From mi@misha.cisco.com Thu Feb 18 14:18:07 1999
Return-Path: <mi@misha.cisco.com>
Received: from misha.cisco.com (misha.cisco.com [171.69.206.50])
	by hub.freebsd.org (Postfix) with ESMTP id F228711A04
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 18 Feb 1999 14:18:03 -0800 (PST)
	(envelope-from mi@misha.cisco.com)
Received: (from root@localhost)
	by misha.cisco.com (8.9.1/8.9.1) id RAA06950;
	Thu, 18 Feb 1999 17:18:00 -0500 (EST)
	(envelope-from mi)
Message-Id: <199902182218.RAA06950@misha.cisco.com>
Date: Thu, 18 Feb 1999 17:18:00 -0500 (EST)
From: Mikhail Teterin <mi@misha.cisco.com>
Reply-To: mi@aldan.algebra.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: fortune(6) gives bogus diagnostic sometimes
X-Send-Pr-Version: 3.2

>Number:         10152
>Category:       bin
>Synopsis:       fortune(6) gives bogus diagnostic sometimes
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Feb 18 14:20:00 PST 1999
>Closed-Date:    Tue Mar 9 03:47:21 PST 1999
>Last-Modified:  Tue Mar  9 03:47:33 PST 1999
>Originator:     Mikhail Teterin
>Release:        FreeBSD 3.0-RELEASE i386
>Organization:
Virtual Estates, Inc.
>Environment:

	For whatever reason, some files in my /usr/share/games/fortune/
	were readable to root only...

>Description:

	  6816 fortune  CALL  stat(0x8052000,0xefbfd6f8)
	  6816 fortune  NAMI  "/usr/share/games/fortune/fortunes"
	  6816 fortune  RET   stat 0
	  6816 fortune  CALL  open(0x8052000,0,0)
	  6816 fortune  NAMI  "/usr/share/games/fortune/fortunes"
	  6816 fortune  RET   open 3
	  6816 fortune  CALL  access(0x8052040,0x4)
	  6816 fortune  NAMI  "/usr/share/games/fortune/fortunes.dat"
	  6816 fortune  RET   access -1 errno 13 Permission denied
	  6816 fortune  CALL  write(0x2,0xefbfd020,0x4a)
	  6816 fortune  GIO   fd 2 wrote 74 bytes
	       "fortune:/usr/share/games/fortune/fortunes not a fortune file or direct\
		ory"

see, it failed to open /usr/share/games/fortune/fortunes.dat, but reported a problem
with /usr/share/games/fortune/fortunes.

>How-To-Repeat:

	Make /usr/share/games/fortune/fortunes.dat 400. Try fortune -s

>Fix:

>Release-Note:
>Audit-Trail:

From: "Matthew D. Fuller" <fullermd@futuresouth.com>
To: mi@aldan.algebra.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/10152: fortune(6) gives bogus diagnostic sometimes
Date: Thu, 18 Feb 1999 22:10:08 -0600

 On Thu, Feb 18, 1999 at 05:18:00PM -0500, a little birdie told me
 that Mikhail Teterin remarked
 > 
 > >Environment:
 > 
 > 	For whatever reason, some files in my /usr/share/games/fortune/
 > 	were readable to root only...
 > 
 > 	       "fortune:/usr/share/games/fortune/fortunes not a fortune file or direct\
 > 		ory"
 
 Interesting.
 The relevant code it this:
     if ((isdir && !add_dir(fp)) ||
         (!isdir &&
          !is_fortfile(path, &fp->datfile, &fp->posfile, (parent != NULL))))
     {
         if (parent == NULL)
             fprintf(stderr,
                 "fortune:%s not a fortune file or directory\n",
                 path);
 
 around line 540-ish in fortune.c.
 
 I'll look into this a bit more, see if I can't make up something.
 
 
 
 ---
 
 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
 | Matthew Fuller     http://www.over-yonder.net/~fullermd |
 * fullermd@futuresouth.com       fullermd@over-yonder.net *
 | UNIX Systems Administrator      Specializing in FreeBSD |
 *   FutureSouth Communications   ISPHelp ISP Consulting   *
 |  "The only reason I'm burning my candle at both ends,   |
 *    is because I haven't figured out how to light the    *
 |                     middle yet"                         |
 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
 

From: "Matthew D. Fuller" <fullermd@futuresouth.com>
To: mi@aldan.algebra.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/10152: fortune(6) gives bogus diagnostic sometimes
Date: Fri, 19 Feb 1999 01:11:27 -0600

 Hm.
 Looks like it's a bit deeper than that.
 I think we need more specific warnings on 'Can't open XXXXX'.
 I'll see what I can do with it, I seem to have a few hours to play with.
 
 
 
 ---
 
 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
 | Matthew Fuller     http://www.over-yonder.net/~fullermd |
 * fullermd@futuresouth.com       fullermd@over-yonder.net *
 | UNIX Systems Administrator      Specializing in FreeBSD |
 *   FutureSouth Communications   ISPHelp ISP Consulting   *
 |  "The only reason I'm burning my candle at both ends,   |
 *    is because I haven't figured out how to light the    *
 |                     middle yet"                         |
 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
 

From: "Matthew D. Fuller" <fullermd@futuresouth.com>
To: FreeBSD-gnats-submit@FreeBSD.ORG
Cc: Mikhail Teterin <mi@misha.cisco.com>
Subject: Re: bin/10152: fortune(6) gives bogus diagnostic sometimes [RFC]
Date: Fri, 19 Feb 1999 02:42:20 -0600

 OK, call for opinions on this.
 
 I see where the errors are coming from, but I'm not sure what an
 appropriate fix is, if a 'fix' is even appropriate.
 
 The error in this case is occuring here:
     if (access(datfile, R_OK) < 0) {
         free(datfile);
         DPRINTF(2, (stderr, "FALSE (no \".dat\" file)\n"));
         return FALSE;
     }
 
 Note that the warning message is NOT printed unless you use the
 undocumented debug flag, which is only enabled when fortune is compiled
 with -DDEBUG (which we always do by default).  I've attached a patch
 later to document this in the manpage.
 
 When you run it as fortune -DD (see the 2 after DPRINTF there?  That's
 how many times -D must be specified for the message in question to be
 printed), you see this:
 (ttyp1):{1672}% fortune -DD
 adding file "/usr/share/games/fortune/fortunes"
 path = "/usr/share/games/fortune/fortunes"
 is_fortfile(/usr/share/games/fortune/fortunes) returns FALSE (no ".dat" file)
 fortune:/usr/share/games/fortune/fortunes not a fortune file or directory
 
 The final error message is dies on doesn't help you at all unless you see
 the rest of it.  There's a number of other reasons is_fortfile() can bomb
 out, so changing the message directly isn't quite the answer.  Maybe
 is_fortfile() should spout a warning for permission denied?  Most of the
 other warnings are non-fatal, and not even worthy of a warning, but this
 one seems to be; even if you're not in -D[...] mode.
 
 Regardless, I think the changes should be added into the manpage, since it
 seems to always be compiled with -DDEBUG.
 
 How does this look?  It only deals with THIS problem, not with any
 related things, but it's better than nothing:
 
 
 Index: fortune.6
 ===================================================================
 RCS file: /usr/cvs/src/games/fortune/fortune/fortune.6,v
 retrieving revision 1.5
 diff -u -r1.5 fortune.6
 --- fortune.6	1997/02/22 14:46:50	1.5
 +++ fortune.6	1999/02/19 08:28:10
 @@ -43,7 +43,7 @@
  .Nd "print a random, hopefully interesting, adage"
  .Sh SYNOPSIS
  .Nm fortune
 -.Op Fl aefilosw
 +.Op Fl aDefilosw
  .Op Fl m Ar pattern
  .Oo
  .Op Ar \&N%
 @@ -63,6 +63,9 @@
  (See the
  .Fl o
  option for more information on offensive fortunes.)
 +.It Fl D
 +Enable additional debugging output.
 +Specify this option multiple times for more verbose output.
  .It Fl e
  Consider all fortune files to be of equal size (see discussion below
  on multiple files).
 Index: fortune.c
 ===================================================================
 RCS file: /usr/cvs/src/games/fortune/fortune/fortune.c,v
 retrieving revision 1.10
 diff -u -r1.10 fortune.c
 --- fortune.c	1997/06/14 00:37:08	1.10
 +++ fortune.c	1999/02/19 08:37:49
 @@ -799,8 +799,12 @@
  	datfile = copy(file, (unsigned int) (strlen(file) + 4)); /* +4 for ".dat" */
  	strcat(datfile, ".dat");
  	if (access(datfile, R_OK) < 0) {
 +		DPRINTF(2, (stderr, "FALSE (no readable \".dat\" file)\n"));
 +#ifdef DEBUG
 +		if (Debug < 2)
 +			DPRINTF(0, (stderr, "Warning: file \"%s\" unreadable\n", datfile));
 +#endif
  		free(datfile);
 -		DPRINTF(2, (stderr, "FALSE (no \".dat\" file)\n"));
  		return FALSE;
  	}
  	if (datp != NULL)
 
 
 
 
 ---
 
 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
 | Matthew Fuller     http://www.over-yonder.net/~fullermd |
 * fullermd@futuresouth.com       fullermd@over-yonder.net *
 | UNIX Systems Administrator      Specializing in FreeBSD |
 *   FutureSouth Communications   ISPHelp ISP Consulting   *
 |  "The only reason I'm burning my candle at both ends,   |
 *    is because I haven't figured out how to light the    *
 |                     middle yet"                         |
 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
 
State-Changed-From-To: open->closed 
State-Changed-By: dcs 
State-Changed-When: Tue Mar 9 03:47:21 PST 1999 
State-Changed-Why:  
Fixed. Thanks. 
>Unformatted:
