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

According to Pádraig Brady on 9/25/2009 4:11 AM:
> 
> You need to chmod a+x ln/hard-to-sym

Oops.  Yeah.  Serves me right for testing on cygwin 1.5 (cygwin 1.7 fixed
that bug, so that a script now has to be executable to run it).

> Also " path " in your -P description in coreutils.texi
> is causing doc/Makefile.am::check-texinfo to fail

s/path/file name/ fixed that.

> 
> Also your stdbuf cleanup needs the following.
> (I was wary about passing NULL into access())

I should have used xreadlink, not areadlink, for ENOMEM.  But
file_name_concat guarantees non-NULL results (it calls xalloc-die on
ENOMEM, and there are no other failure paths), so there was no risk of
calling access(NULL).  Hmm, should we be using euidaccess instead of access?

Also, Jim, should we add a maintainer check that ensures we always use
[ax]readlink rather than raw readlink?

I've folded in your suggestions.  I pushed ln and copy.c changes to
master, but left stdbuf changes only on my own repo.

git pull git://repo.or.cz/coreutils/ericb.git master

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

Eric Blake             e...@byu.net
-----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/

iEYEARECAAYFAkq8wz0ACgkQ84KuGfSFAYC8mQCgvvTDvYEyo9a+wS3Y9zE9Z+ZE
R7cAniLaXbQl92mCCw8K6Z2o3D36QUm+
=a82d
-----END PGP SIGNATURE-----
>From 7a31f56455d10a9467bbb688093302875c9dff09 Mon Sep 17 00:00:00 2001
From: Eric Blake <e...@byu.net>
Date: Thu, 24 Sep 2009 17:18:47 -0600
Subject: [PATCH] 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 f648e22..c9ce36f 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -236,6 +236,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