The branch main has been updated by dteske:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=14df6e1e686ef1908c107932d9224d3f3fbc6b51

commit 14df6e1e686ef1908c107932d9224d3f3fbc6b51
Author:     Devin Teske <[email protected]>
AuthorDate: 2026-08-28 00:57:53 +0000
Commit:     Devin Teske <[email protected]>
CommitDate: 2026-08-28 00:57:53 +0000

    fortune: fall back to all databases if fortunes is missing
    
    With no file argument, fortune looks for a database named fortunes
    in FORTDIR. The base system has not shipped that file since
    0538d7bbe620 (FreeBSD 12), only freebsd-tips, so the default
    invocation failed even though a valid database remained. Callers
    such as xlockmore's marquee and nose modes (fortune -s) then
    displayed the error as the epigram.
    
    If the named fortunes file is absent, scan every database in the
    existing search path. /usr/local/share/games/fortune stays on that
    path so fortune-mod-* packages keep working; when
    fortune-mod-freebsd-classic restores the fortunes file, it is still
    preferred. fortune -f with no arguments lists the same files that
    would be searched.
    
    MFC after:      1 week
    
    Reviewed by:    ziaee, fuz
    Differential Revision:  https://reviews.freebsd.org/D59057
---
 usr.bin/fortune/fortune/fortune.6 | 16 +++++++++++---
 usr.bin/fortune/fortune/fortune.c | 46 +++++++++++++++++----------------------
 2 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/usr.bin/fortune/fortune/fortune.6 
b/usr.bin/fortune/fortune/fortune.6
index 6c2a677d24b6..0b6957870040 100644
--- a/usr.bin/fortune/fortune/fortune.6
+++ b/usr.bin/fortune/fortune/fortune.6
@@ -28,7 +28,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd July 1, 2021
+.Dd August 20, 2026
 .Dt FORTUNE 6
 .Os
 .Sh NAME
@@ -46,6 +46,12 @@
 When
 .Nm
 is run with no arguments it prints out a random epigram.
+It prefers a database named
+.Pa fortunes
+if one exists in the search path; otherwise it uses every database
+in that path, including the base system's
+.Pa freebsd-tips
+file and any files installed by ports.
 Epigrams are divided into several categories, where each category
 is subdivided into those which are potentially offensive and those
 which are not.
@@ -172,9 +178,13 @@ If set, fortune will save some state about what fortune
 it was up to on disk.
 .El
 .Sh FILES
-.Bl -tag -width ".Pa /usr/share/games/fortune/*"
+.Bl -tag -width ".Pa /usr/local/share/games/fortune/*"
 .It Pa /usr/share/games/fortune/*
-the fortunes databases (those files ending
+the base system fortune databases, currently
+.Pa freebsd-tips
+.It Pa /usr/local/share/games/fortune/*
+additional databases installed by ports
+(those files ending in
 .Dq Pa -o
 contain the
 .Sy offensive
diff --git a/usr.bin/fortune/fortune/fortune.c 
b/usr.bin/fortune/fortune/fortune.c
index 4989f11f1085..0f6490fd4583 100644
--- a/usr.bin/fortune/fortune/fortune.c
+++ b/usr.bin/fortune/fortune/fortune.c
@@ -85,7 +85,6 @@ typedef struct fd {
 
 static bool    Found_one;              /* did we find a match? */
 static bool    Find_files = FALSE;     /* just find a list of proper fortune 
files */
-static bool    Fortunes_only = FALSE;  /* check only "fortunes" files */
 static bool    Wait = FALSE;           /* wait desired after fortune */
 static bool    Short_only = FALSE;     /* short fortune desired */
 static bool    Long_only = FALSE;      /* long fortune desired */
@@ -352,33 +351,32 @@ form_file_list(char **files, int file_cnt)
        char    **pstr;
 
        if (file_cnt == 0) {
-               if (Find_files) {
-                       Fortunes_only = TRUE;
+               /*
+                * Prefer a database named "fortunes" so a port that
+                * restores that file keeps the historic default.  If
+                * it is absent (the base system has shipped only
+                * freebsd-tips since the other datfiles left src),
+                * use every database in the search path.  LOCALBASE
+                * stays on that path; port cookies are not moved.
+                */
+               pstr = Fortune_path_arr;
+               i = 0;
+               while (*pstr) {
+                       i += add_file(NO_PROB, "fortunes", *pstr++,
+                                     &File_list, &File_tail, NULL);
+               }
+               if (!i) {
                        pstr = Fortune_path_arr;
-                       i = 0;
                        while (*pstr) {
                                i += add_file(NO_PROB, *pstr++, NULL,
                                              &File_list, &File_tail, NULL);
                        }
-                       Fortunes_only = FALSE;
-                       if (!i) {
-                               fprintf(stderr, "No fortunes found in %s.\n",
-                                   Fortune_path);
-                       }
-                       return (i != 0);
-               } else {
-                       pstr = Fortune_path_arr;
-                       i = 0;
-                       while (*pstr) {
-                               i += add_file(NO_PROB, "fortunes", *pstr++,
-                                             &File_list, &File_tail, NULL);
-                       }
-                       if (!i) {
-                               fprintf(stderr, "No fortunes found in %s.\n",
-                                   Fortune_path);
-                       }
-                       return (i != 0);
                }
+               if (!i) {
+                       fprintf(stderr, "No fortunes found in %s.\n",
+                           Fortune_path);
+               }
+               return (i != 0);
        }
        for (i = 0; i < file_cnt; i++) {
                percent = NO_PROB;
@@ -776,10 +774,6 @@ is_fortfile(const char *file, char **datp, char **posp, 
int check_for_offend)
                DPRINTF(2, (stderr, "FALSE (file starts with '.')\n"));
                return (FALSE);
        }
-       if (Fortunes_only && strncmp(sp, "fortunes", 8) != 0) {
-               DPRINTF(2, (stderr, "FALSE (check fortunes only)\n"));
-               return (FALSE);
-       }
        if ((sp = strrchr(sp, '.')) != NULL) {
                sp++;
                for (i = 0; suflist[i] != NULL; i++)

Reply via email to