linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stepan Kasal <kasal@math.cas.cz>
To: linux-hotplug@vger.kernel.org
Subject: Re: [Cooker] strange problem with "hotplug" package
Date: Thu, 08 May 2003 12:24:45 +0000	[thread overview]
Message-ID: <marc-linux-hotplug-105239690809278@msgid-missing> (raw)
In-Reply-To: <marc-linux-hotplug-105222892315303@msgid-missing>

[-- Attachment #1: Type: text/plain, Size: 745 bytes --]

Hello,

On Tue, May 06, 2003 at 10:12:20PM +0200, Jim Meyering wrote:
>   $ grep -q --help > /dev/full && echo ok
>   grep: write error: No space left on device
>   ok

thank you very much for pointing this out; I haven't thought about this.

> While without -q, it works as I'd expect:
>   $ grep --help > /dev/full && echo ok
>   grep: write error: No space left on device
>   [Exit 1]

No, I'd expect exit code 2 in both cases, not 1.

I have revised my previous patch; see the patch attached to this mail.
(It's relative to plain 2.5.1.)  Feedback welcome, of course.

> P.S. Thanks for taking up the reins of GNU grep.

Well I have to admit that I haven't done much yet.
But I hope I'll get to it soon.  ;-)

Have a nice day,
	Stepan Kasal

[-- Attachment #2: grep-2.5.1-close_stdout2.patch --]
[-- Type: text/plain, Size: 3203 bytes --]

Thu May  8 14:08:57 CEST 2003  Stepan Kasal  <kasal@math.cas.cz>

	* lib/closeout.c (default_exit_status): set to 2.
	* src/grep.c (main): Don't register atexit(close_stdout) if -q
	  was given---no output will be written; there is also no need
	  to use close_stdout_set_status().  Move the atexit() call after
	  all calls to usage(); usage() and --version call close_stdout()
	  explicitely before exit.
	  (grepbuf): move exit(0) ...
	  (grepfile): ... here, when the bufdesc is closed; this doesn't
	  present any performance loss, done_on_match is 1 and ensures
	  that we get out of grepbuf() quickly.

diff -urpN grep-2.5.1.orig/lib/closeout.c grep-2.5.1/lib/closeout.c
--- grep-2.5.1.orig/lib/closeout.c	Sun Mar  4 06:33:12 2001
+++ grep-2.5.1/lib/closeout.c	Thu May  8 13:50:14 2003
@@ -47,7 +47,8 @@ extern int errno;
 #include "__fpending.h"
 #endif
 
-static int default_exit_status = EXIT_FAILURE;
+static int default_exit_status = /* EXIT_FAILURE */
+	2 /* error exit code for grep */;
 static const char *file_name;
 
 /* Set the value to be used for the exit status when close_stdout is called.
diff -urpN grep-2.5.1.orig/src/grep.c grep-2.5.1/src/grep.c
--- grep-2.5.1.orig/src/grep.c	Tue Mar 26 16:54:12 2002
+++ grep-2.5.1/src/grep.c	Thu May  8 14:05:27 2003
@@ -722,8 +722,6 @@ grepbuf (char const *beg, char const *li
           outleft--;
 	  if (!outleft || done_on_match)
 	    {
-	      if (exit_on_match)
-		exit (0);
 	      after_last_match = bufoffset - (buflim - endp);
 	      return nlines;
 	    }
@@ -978,6 +976,9 @@ grepfile (char const *file, struct stats
 	    }
     }
 
+  if (!status && exit_on_match)
+	exit (0);
+
   return status;
 }
 
@@ -1125,6 +1126,7 @@ two FILEs given, assume -h.  Exit status
 and 2 if trouble.\n"));
       printf (_("\nReport bugs to <bug-gnu-utils@gnu.org>.\n"));
     }
+  close_stdout ();
   exit (status);
 }
 
@@ -1348,8 +1350,6 @@ main (int argc, char **argv)
   textdomain (PACKAGE);
 #endif
 
-  atexit (close_stdout);
-
   prepend_default_options (getenv ("GREP_OPTIONS"), &argc, &argv);
 
   while ((opt = get_nondigit_option (argc, argv, &default_context)) != -1)
@@ -1524,7 +1524,6 @@ main (int argc, char **argv)
 
       case 'q':
 	exit_on_match = 1;
-	close_stdout_set_status(0);
 	break;
 
       case 'R':
@@ -1579,7 +1578,7 @@ main (int argc, char **argv)
                   !strcasecmp(optarg, "if-tty"))
             color_option = 2;
           else
-            show_help = 1;
+	    error (2, 0, _("unrecognized colour option"));
         } else
           color_option = 2;
         if(color_option == 2) {
@@ -1667,6 +1666,7 @@ Copyright 1988, 1992-1999, 2000, 2001 Fr
 This is free software; see the source for copying conditions. There is NO\n\
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"));
       printf ("\n");
+      close_stdout ();
       exit (0);
     }
 
@@ -1693,6 +1693,10 @@ warranty; not even for MERCHANTABILITY o
       }
     else
       usage (2);
+
+  /* don't close stdout for -q, consider ``grep -q pat <&- >&-'' */
+  if (!exit_on_match)
+    atexit (close_stdout);
 
   if (!install_matcher (matcher) && !install_matcher ("default"))
     abort ();

  parent reply	other threads:[~2003-05-08 12:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-06 13:45 [Cooker] strange problem with "hotplug" package Andrey Borzenkov
2003-05-06 15:54 ` Stepan Kasal
2003-05-06 20:12 ` Jim Meyering
2003-05-08 12:24 ` Stepan Kasal [this message]
2003-05-08 16:17 ` Jim Meyering

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=marc-linux-hotplug-105239690809278@msgid-missing \
    --to=kasal@math.cas.cz \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).