Page MenuHomeFreeBSD

calendar: correct the search order for files
ClosedPublic

Authored by kevans on Oct 18 2023, 3:29 PM.
Tags
None
Referenced Files
Unknown Object (File)
Apr 30 2024, 5:50 AM
Unknown Object (File)
Apr 30 2024, 5:12 AM
Unknown Object (File)
Apr 30 2024, 5:06 AM
Unknown Object (File)
Apr 30 2024, 5:06 AM
Unknown Object (File)
Apr 29 2024, 9:54 PM
Unknown Object (File)
Feb 16 2024, 7:58 PM
Unknown Object (File)
Jan 21 2024, 5:20 PM
Unknown Object (File)
Dec 23 2023, 3:07 AM
Subscribers

Details

Summary

Include files that don't begin with a '/' are documented to search the
current directory, then /usr/share/calendar. This hasn't been accurate
for years, since e061f95e7b9b ("Rework calendar(1) parser") rewrote a
lot of this.

Stash off the cwd before we do any chdir()ing around and use that to
honor the same order we'll follow for the -f flag. This may result in
an extra lookup that will fail for the initial calendar file, but I
don't think it's worth the complexity to avoid it.

While we're here, fix the documentation to just reference the order
described in FILES so that we only need to keep it up to date in one
place.

Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

It could also make sense to:

@@ -654,17 +654,15 @@ opencalin(void)
 
        /* open up calendar file */
        cal_file = calendarFile;
-       if ((fpin = fopen(calendarFile, "r")) == NULL) {
-               if (doall) {
-                       if (chdir(calendarHomes[0]) != 0)
-                               return (NULL);
-                       if (stat(calendarNoMail, &sbuf) == 0)
-                               return (NULL);
-                       if ((fpin = fopen(calendarFile, "r")) == NULL)
-                               return (NULL);
-               } else {
-                       fpin = cal_fopen(calendarFile);
-               }
+       if (doall && (fpin = fopen(calendarFile, "r")) == NULL) {
+               if (chdir(calendarHomes[0]) != 0)
+                       return (NULL);
+               if (stat(calendarNoMail, &sbuf) == 0)
+                       return (NULL);
+               if ((fpin = fopen(calendarFile, "r")) == NULL)
+                       return (NULL);
+       } else if (!doall) {
+               fpin = cal_fopen(calendarFile);
        }
        return (fpin);
 }

Just so that all of the !doall logic is consolidated here.

des added inline comments.
usr.bin/calendar/io.c
134

You're silently ignoring all errors from openat() here, is that really what we want or should we only ignore ENOENT?

kevans marked an inline comment as done.

Don't ignore errors from openat()

usr.bin/calendar/io.c
134

I was torn because we ignore all errors from fopen below and just fall through to the rest of the search paths, but that also can lead to false positive messages about the calendar-data port...

I think we also want to ignore ENAMETOOLONG because then the file just can't exist and that's probably not what the user wanted.

This revision is now accepted and ready to land.Dec 4 2023, 9:32 PM
This revision was automatically updated to reflect the committed changes.