]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
stdbuf: make it mandatory to specify a buffering option
authorPádraig Brady <P@draigBrady.com>
Sat, 22 Jun 2013 02:37:51 +0000 (03:37 +0100)
committerPádraig Brady <P@draigBrady.com>
Sat, 22 Jun 2013 03:02:19 +0000 (04:02 +0100)
This is consistent with the documented interface and
avoids any ambiguity in a user thinking that stdbuf without options
might reset to a "standard" buffering setup.

* src/stdbuf.c (set_libstdbuf_options): Indicate with the return value
whether any env variables were actually set.
(main): Fail unless some env variables were set.
* tests/misc/stdbuf.sh: Ensure this constraint is enforced.
* NEWS: Mention the small change in behavior.

NEWS
src/stdbuf.c
tests/misc/stdbuf.sh

diff --git a/NEWS b/NEWS
index aff6a425045fbb16c4b5c98800715d3321f59843..b728ec0074815352d9fc22ae5decd352f21267f7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -41,6 +41,11 @@ GNU coreutils NEWS                                    -*- outline -*-
   csplit accepts a new option: --suppressed-matched, to elide the lines
   used to identify the split points.
 
+** Changes in behavior
+
+  stdbuf now requires at least one buffering mode option to be specified,
+  as per the documented interface.
+
 ** Improvements
 
   stat and tail work better with EFIVARFS, EXOFS, F2FS, SNFS and UBIFS.
index 38e9bee7ce69d45ee2202414510817edcdf72126..2500c300147f30aa5d2d99fd29b5865637a11290 100644 (file)
@@ -248,12 +248,14 @@ set_LD_PRELOAD (void)
     }
 }
 
-/* Populate environ with _STDBUF_I=$MODE _STDBUF_O=$MODE _STDBUF_E=$MODE  */
+/* Populate environ with _STDBUF_I=$MODE _STDBUF_O=$MODE _STDBUF_E=$MODE.
+   Return TRUE if any environment variables set.   */
 
-static void
+static bool
 set_libstdbuf_options (void)
 {
-  unsigned int i;
+  bool env_set = false;
+  size_t i;
 
   for (i = 0; i < ARRAY_CARDINALITY (stdbuf); i++)
     {
@@ -278,8 +280,12 @@ set_libstdbuf_options (void)
                      _("failed to update the environment with %s"),
                      quote (var));
             }
+
+          env_set = true;
         }
     }
+
+  return env_set;
 }
 
 int
@@ -346,9 +352,11 @@ main (int argc, char **argv)
       usage (EXIT_CANCELED);
     }
 
-  /* FIXME: Should we mandate at least one option?  */
-
-  set_libstdbuf_options ();
+  if (! set_libstdbuf_options ())
+    {
+      error (0, 0, _("you must specify a buffering mode option"));
+      usage (EXIT_CANCELED);
+    }
 
   /* Try to preload libstdbuf first from the same path as
      stdbuf is running from.  */
index 12347ecc7a09b3e872ac17f90c63fc5428542502..650e8e737dc2be1ea2afcff7184213dad921d19b 100755 (executable)
@@ -50,6 +50,8 @@ stdbuf -o$SIZE_OFLOW true # size too large
 test $? = 125 || fail=1
 stdbuf -iL true # line buffering stdin disallowed
 test $? = 125 || fail=1
+stdbuf true # a buffering mode must be specified
+test $? = 125 || fail=1
 stdbuf -i0 -o0 -e0 true || fail=1 #check all files
 stdbuf -o1 . # invalid command
 test $? = 126 || fail=1