Add some code to be able to detect programs even as user with
authorDr. Werner Fink <werner@suse.de>
Mon, 17 Oct 2011 12:53:27 +0000 (12:53 +0000)
committerDr. Werner Fink <werner@suse.de>
Mon, 17 Oct 2011 12:53:27 +0000 (12:53 +0000)
kernel 3.0 and above

git-svn-id: svn://svn.sv.gnu.org/sysvinit/sysvinit/trunk@112 456724a4-4300-0410-8514-c89748c515a2

doc/Changelog
src/killall5.c

index feb79c56565e49c2c30f2758d96914137fd7b8fe..0cb2ca09819b5e8b838d42d0f4a4d5d13ffcf42c 100644 (file)
@@ -39,6 +39,8 @@ sysvinit (2.89dsf) UNRELEASED; urgency=low
     variable on non-linux platforms.
   * Only set the VSWTC field for termios in init if it is available,
     to get the source building on FreeBSD.
+  * Add some code to be able to detect programs even as user with
+    kernel 3.0 and above
 
  -- Petter Reinholdtsen <pere@hungry.com>  Sun Apr 11 11:28:55 CEST 2010
 
index 3d35364c1d01cec1c286bc24ba440e4d4e0cae1f..7d42eccbc379a00b9706218f993b5da6fbd8583d 100644 (file)
@@ -469,6 +469,7 @@ int readproc(int do_stat)
        char            *s, *q;
        unsigned long   startcode, endcode;
        int             pid, f;
+       ssize_t         len;
 
        /* Open the /proc directory. */
        if (chdir("/proc") == -1) {
@@ -635,23 +636,22 @@ int readproc(int do_stat)
                switch (do_stat) {
                case DO_NETFS:
                        if ((p->nfs = check4nfs(path, buf)))
-                               break;
+                               goto link;
                case DO_STAT:
                        if (stat(path, &st) != 0)
                                break;
-                       else {
-                               char buf[PATH_MAX];
-
-                               f = readlink(path, buf, sizeof buf);
-                               if (f > 0) {
-                                       p->pathname = (char *)xmalloc(f + 1);
-                                       memcpy(p->pathname, buf, f);
-                                       p->pathname[f] = '\0';
-                               }
-                       }
                        p->dev = st.st_dev;
                        p->ino = st.st_ino;
+
+                       /* Fall through */
                default:
+               link:
+                       len = readlink(path, buf, PATH_MAX);
+                       if (len > 0) {
+                               p->pathname = (char *)xmalloc(len + 1);
+                               memcpy(p->pathname, buf, len);
+                               p->pathname[len] = '\0';
+                       }
                        break;
                }
 
@@ -722,6 +722,7 @@ PIDQ_HEAD *pidof(char *prog)
        int             dostat = 0;
        int             foundone = 0;
        int             ok = 0;
+       const int       root = (getuid() == 0);
        char            real[PATH_MAX+1];
 
        if (! prog)
@@ -769,16 +770,11 @@ PIDQ_HEAD *pidof(char *prog)
         * network FS located binaries */
        if (!foundone && nfs) {
                for (p = plist; p; p = p->next) {
-                       char exe [PATH_MAX+1];
-                       char path[PATH_MAX+1];
-                       int len;
+                       if (!p->pathname)
+                               continue;
                        if (!p->nfs)
                                continue;
-                       snprintf(exe, sizeof(exe), "/proc/%d/exe", p->pid);
-                       if ((len = readlink(exe, path, PATH_MAX)) < 0)
-                                   continue;
-                       path[len] = '\0';
-                       if (strcmp(prog, path) != 0)
+                       if (strcmp(prog, p->pathname) != 0)
                                continue;
                        add_pid_to_q(q, p);
                        foundone++;
@@ -788,19 +784,31 @@ PIDQ_HEAD *pidof(char *prog)
        /* If we didn't find a match based on dev/ino, try the name. */
        if (!foundone) for (p = plist; p; p = p->next) {
                if (prog[0] == '/') {
-                       if (!p->pathname)
-                               continue;
+                       if (!p->pathname) {
+                               if (root)
+                                       continue;
+                               goto fallback; 
+                       }
                        if (strcmp(prog, p->pathname)) {
                                int len = strlen(prog);
                                if (strncmp(prog, p->pathname, len))
+                               {
+                                       if (scripts_too)
+                                               goto fallback;
                                        continue;
+                               }
                                if (strcmp(" (deleted)", p->pathname + len))
+                               {
+                                       if (scripts_too)
+                                               goto fallback;
                                        continue;
+                               }
                        }
                        add_pid_to_q(q, p);
                        continue;
                }
 
+       fallback:
                ok = 0;
 
                /*             matching        nonmatching