implemented numeric sort (sort -g)
[oweals/busybox.git] / utility.c
index de7a0fbfc639bce0c62f791609bd4aed1cee6dde..d01be9c98c87b74f1cd81a2a937f27100e694146 100644 (file)
--- a/utility.c
+++ b/utility.c
@@ -217,10 +217,12 @@ copyFile( const char *srcName, const char *destName,
     if (setModes == TRUE) {
        //fprintf(stderr, "Setting permissions for %s\n", destName);
        chmod(destName, srcStatBuf.st_mode);
-       if (followLinks == TRUE)
-           chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
-       else
+#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
+       if (followLinks == FALSE)
            lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
+       else
+#endif
+           chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
 
        times.actime = srcStatBuf.st_atime;
        times.modtime = srcStatBuf.st_mtime;
@@ -376,7 +378,7 @@ int fullRead(int fd, char *buf, int len)
 #endif
 
 
-#if defined (BB_CHOWN) || defined (BB_CP) || defined (BB_FIND) || defined (BB_LS)
+#if defined (BB_CHOWN) || defined (BB_CP) || defined (BB_FIND) || defined (BB_LS) || defined (BB_INSMOD)
 /*
  * Walk down all the directories under the specified 
  * location, and do something (something specified
@@ -1069,13 +1071,43 @@ extern long getNum (const char *cp)
 #endif
 
 
-/* END CODE */
-
-
-
-
-
-
-
+#if defined BB_INIT || defined BB_HALT || defined BB_REBOOT 
 
+#if ! defined BB_FEATURE_USE_PROCFS
+#error Sorry, I depend on the /proc filesystem right now.
+#endif
+/* findInitPid()
+ *  
+ *  This finds the pid of init (which is not always 1).
+ *  Currently, it's implemented by rummaging through the proc filesystem.
+ *
+ *  [return]
+ *  0      failure
+ *  pid            when init's pid is found.
+ */
+extern pid_t
+findInitPid()
+{
+    pid_t   init_pid;
+    char    filename[256];
+    char    buffer[256];
+
+    /* no need to opendir ;) */
+    for (init_pid = 1; init_pid < 65536; init_pid++) {
+       FILE    *status;
+
+       sprintf(filename, "/proc/%d/status", init_pid);
+       status = fopen(filename, "r");
+       if (!status) { continue; }
+       fgets(buffer, 256, status);
+       fclose(status);
+
+       if ( (strstr(buffer, "init\n") != NULL )) {
+           return init_pid;
+       }
+    }
+    return 0;
+}
+#endif
 
+/* END CODE */