Per some comments from Lars Kellogg-Stedman <lars@larsshack.org>,
authorEric Andersen <andersen@codepoet.org>
Mon, 7 May 2001 17:48:28 +0000 (17:48 -0000)
committerEric Andersen <andersen@codepoet.org>
Mon, 7 May 2001 17:48:28 +0000 (17:48 -0000)
make xreadlink() return NULL on failure, and make sure everyone
uses the interface correctly.
 -Erik

applets/busybox.c
archival/tar.c
busybox.c
libbb/xreadlink.c
miscutils/readlink.c
readlink.c
tar.c

index badd53d79de9a7c28dc34fbf1c46903d1f96e8b1..41b6069edb79bc0b4d4251296fc90044dd5eb5dc 100644 (file)
@@ -37,10 +37,7 @@ typedef int (*__link_f)(const char *, const char *);
  */
 static char *busybox_fullpath()
 {
-       char proc[256];
-
-       sprintf(proc, "/proc/%d/exe", getpid());
-       return xreadlink(proc);
+       return xreadlink("/proc/self/exe");
 }
 
 /* create (sym)links for each applet */
index eb085c770ded64efa645219ff971b72bdfa49285..135bfd186a9d670b866aa27368e09dd76f0a0c95 100644 (file)
@@ -922,6 +922,8 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name,
                strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname));
        } else if (S_ISLNK(statbuf->st_mode)) {
                char *lpath = xreadlink(real_name);
+               if (!lpath) /* Already printed err msg inside xreadlink() */
+                       return ( FALSE);
                header.typeflag  = SYMTYPE;
                strncpy(header.linkname, lpath, sizeof(header.linkname)); 
                free(lpath);
index badd53d79de9a7c28dc34fbf1c46903d1f96e8b1..41b6069edb79bc0b4d4251296fc90044dd5eb5dc 100644 (file)
--- a/busybox.c
+++ b/busybox.c
@@ -37,10 +37,7 @@ typedef int (*__link_f)(const char *, const char *);
  */
 static char *busybox_fullpath()
 {
-       char proc[256];
-
-       sprintf(proc, "/proc/%d/exe", getpid());
-       return xreadlink(proc);
+       return xreadlink("/proc/self/exe");
 }
 
 /* create (sym)links for each applet */
index 66f63b8838cfa4d47bb443f4f1d2d3687d1a3cff..932e487a59d718093cb29f9d4967d8dc504772e8 100644 (file)
@@ -1,5 +1,6 @@
 /*
- *  xreadlink.c - safe implementation of readlink
+ *  xreadlink.c - safe implementation of readlink.
+ *  Returns a NULL on failure...
  */
 
 #include <stdio.h>
@@ -22,8 +23,10 @@ extern char *xreadlink(const char *path)
        do {
                buf = xrealloc(buf, bufsize += GROWBY);
                readsize = readlink(path, buf, bufsize); /* 1st try */
-               if (readsize == -1)
-                       perror_msg("%s:%s", applet_name, path);
+               if (readsize == -1) {
+                   perror_msg("%s:%s", applet_name, path);
+                   return NULL;
+               }
        }           
        while (bufsize < readsize + 1);
 
index 226649544c1e6b0fe28a0c7e46b5fe3d56043567..c46ebd108198be9514dee6ee32da5756630dd0dd 100644 (file)
@@ -37,6 +37,8 @@ int readlink_main(int argc, char **argv)
                show_usage();
 
        buf = xreadlink(argv[1]);
+       if (!buf)
+               return EXIT_FAILURE;
        puts(buf);
 #ifdef BB_FEATURE_CLEAN_UP
        free(buf);
index 226649544c1e6b0fe28a0c7e46b5fe3d56043567..c46ebd108198be9514dee6ee32da5756630dd0dd 100644 (file)
@@ -37,6 +37,8 @@ int readlink_main(int argc, char **argv)
                show_usage();
 
        buf = xreadlink(argv[1]);
+       if (!buf)
+               return EXIT_FAILURE;
        puts(buf);
 #ifdef BB_FEATURE_CLEAN_UP
        free(buf);
diff --git a/tar.c b/tar.c
index eb085c770ded64efa645219ff971b72bdfa49285..135bfd186a9d670b866aa27368e09dd76f0a0c95 100644 (file)
--- a/tar.c
+++ b/tar.c
@@ -922,6 +922,8 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name,
                strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname));
        } else if (S_ISLNK(statbuf->st_mode)) {
                char *lpath = xreadlink(real_name);
+               if (!lpath) /* Already printed err msg inside xreadlink() */
+                       return ( FALSE);
                header.typeflag  = SYMTYPE;
                strncpy(header.linkname, lpath, sizeof(header.linkname)); 
                free(lpath);