bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

stat(1) on Solaris 9


From: Eric Blake
Subject: stat(1) on Solaris 9
Date: Thu, 08 Oct 2009 06:18:38 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gnulib fixed stat(2) to work around Solaris 9 bugs.  But stat(1) still
exposes the bug.  Why?  Because our replacement <sys/stat.h> declares stat
as an object-like macro, but stat(1) had a usage pattern that hid rpl_stat
from view and directly called the buggy stat.  OK to commit?

Also, I'm reattaching the stdbuf readlink() cleanup patch from a few days
ago; I've now tested it on Linux.  What file contains maintainer syntax
checks to ensure we don't reintroduce raw '\breadlink(at)?' or 'stat :'?

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrN2J4ACgkQ84KuGfSFAYB0iQCffwGNVYJR2LC4t6onagB3ziQJ
DvIAoI0NBt8WjNCpNVe/xC6iWQ1q4kxf
=3qvN
-----END PGP SIGNATURE-----
>From 0f399115ddbd80c82f7a2f78684f6a2578b2ac46 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 8 Oct 2009 06:04:09 -0600
Subject: [PATCH 1/2] stat: work with recent gnulib changes

* src/stat.c (do_stat): Don't mask function-like stat macro.
---
 src/stat.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/src/stat.c b/src/stat.c
index 14654b1..d18673c 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -872,7 +872,12 @@ do_stat (char const *filename, bool terse, char const 
*format)
           return false;
         }
     }
-  else if ((follow_links ? stat : lstat) (filename, &statbuf) != 0)
+  /* We can't use the shorter
+     (follow_links ? stat : lstat) (filename, &statbug)
+     since stat might be a function-like macro.  */
+  else if ((follow_links
+            ? stat (filename, &statbuf)
+            : lstat (filename, &statbuf)) != 0)
     {
       error (0, errno, _("cannot stat %s"), quote (filename));
       return false;
-- 
1.6.5.rc1


>From 598f98938c6b2533548e238e1c2eddbd9f322ef3 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 24 Sep 2009 17:18:47 -0600
Subject: [PATCH 2/2] stdbuf: improve path search

* src/stdbuf.c (set_program_path): Use gnulib methods for better
file name handling.
* bootstrap.conf (gnulib_modules): Add xreadlink.
---
 bootstrap.conf |    1 +
 src/stdbuf.c   |   28 +++++++++++-----------------
 2 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index e523273..9cf3746 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -238,6 +238,7 @@ gnulib_modules="
   xnanosleep
   xprintf
   xprintf-posix
+  xreadlink
   xstrtod
   xstrtoimax
   xstrtol
diff --git a/src/stdbuf.c b/src/stdbuf.c
index afb7821..05a6b9f 100644
--- a/src/stdbuf.c
+++ b/src/stdbuf.c
@@ -24,8 +24,10 @@

 #include "system.h"
 #include "error.h"
+#include "filenamecat.h"
 #include "posixver.h"
 #include "quote.h"
+#include "xreadlink.h"
 #include "xstrtol.h"
 #include "c-ctype.h"

@@ -145,34 +147,26 @@ set_program_path (const char *arg)
     }
   else
     {
-      char *path;
-      char tmppath[PATH_MAX + 1];
-      ssize_t len = readlink ("/proc/self/exe", tmppath, sizeof (tmppath) - 1);
-      if (len > 0)
-        {
-          tmppath[len] = '\0';
-          program_path = dir_name (tmppath);
-        }
+      char *path = xreadlink ("/proc/self/exe");
+      if (path)
+        program_path = dir_name (path);
       else if ((path = getenv ("PATH")))
         {
           char *dir;
           path = xstrdup (path);
           for (dir = strtok (path, ":"); dir != NULL; dir = strtok (NULL, ":"))
             {
-              int req = snprintf (tmppath, sizeof (tmppath), "%s/%s", dir, 
arg);
-              if (req >= sizeof (tmppath))
-                {
-                  error (0, 0, _("path truncated when looking for %s"),
-                         quote (arg));
-                }
-              else if (access (tmppath, X_OK) == 0)
+              char *candidate = file_name_concat (dir, arg, NULL);
+              if (access (candidate, X_OK) == 0)
                 {
-                  program_path = dir_name (tmppath);
+                  program_path = dir_name (candidate);
+                  free (candidate);
                   break;
                 }
+              free (candidate);
             }
-          free (path);
         }
+      free (path);
     }
 }

-- 
1.6.5.rc1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]