udhcpc: code shrink
[oweals/busybox.git] / procps / smemcap.c
index 06cf93c85575f4b4bf6884016a89342dcb73acc9..2f8ab192e2101c8445cee79c9299534d3b482ed1 100644 (file)
@@ -7,20 +7,19 @@
  the GNU General Public License version 2 or later, incorporated
  herein by reference.
 */
-
-//applet:IF_SMEMCAP(APPLET(smemcap, _BB_DIR_USR_BIN, _BB_SUID_DROP))
-
-//kbuild:lib-$(CONFIG_SMEMCAP) += smemcap.o
-
 //config:config SMEMCAP
-//config:      bool "smemcap"
+//config:      bool "smemcap (2.5 kb)"
 //config:      default y
 //config:      help
-//config:        smemcap is a tool for capturing process data for smem,
-//config:        a memory usage statistic tool.
+//config:      smemcap is a tool for capturing process data for smem,
+//config:      a memory usage statistic tool.
+
+//applet:IF_SMEMCAP(APPLET(smemcap, BB_DIR_USR_BIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_SMEMCAP) += smemcap.o
 
 #include "libbb.h"
-#include "unarchive.h"
+#include "bb_archive.h"
 
 struct fileblock {
        struct fileblock *next;
@@ -41,7 +40,7 @@ static void writeheader(const char *path, struct stat *sb, int type)
        sprintf(header.size, "%o", (unsigned)sb->st_size);
        sprintf(header.mtime, "%llo", sb->st_mtime & 077777777777LL);
        header.typeflag = type;
-       //strcpy(header.magic, "ustar  "); - do we want to be standard-compliant?
+       strcpy(header.magic, "ustar  "); /* like GNU tar */
 
        /* Calculate and store the checksum (the sum of all of the bytes of
         * the header). The checksum field must be filled with blanks for the
@@ -66,7 +65,11 @@ static void archivefile(const char *path)
        struct stat s;
 
        /* buffer the file */
-       fd = xopen(path, O_RDONLY);
+       fd = open(path, O_RDONLY);
+       if (fd == -1) {
+               /* skip vanished processes between dir listing and traversal */
+               return;
+       }
        do {
                cur = xzalloc(sizeof(*cur));
                *prev = cur;
@@ -125,5 +128,8 @@ int smemcap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
                }
        }
 
+       if (ENABLE_FEATURE_CLEAN_UP)
+               closedir(d);
+
        return EXIT_SUCCESS;
 }