--- libinit.c +++ libinit.c 2011-01-21 18:25:49.019926024 +0000 @@ -307,15 +307,16 @@ static void init_mounts(void) } } -static MNTINFO *find_mount(const char * path) +static int find_mount(const char * path, MNTINFO *s) { - MNTINFO *m; + MNTINFO *m, *p = s->parent; for (m = mounts; m; m = m->next) { - if (strncmp(path, m->point, m->nlen)) - continue; - break; + if (s == m && strncmp(path, m->point, m->nlen) == 0) + return 1; + if (p == m && strncmp(path, p->point, p->nlen) == 0) + return 1; } - return m; + return 0; } extern inline char * handl_buf(char *restrict buf) @@ -728,19 +729,21 @@ int pidof (const char * inname, const ch if (!(flags & (KTHREAD|KSHORT)) && !isscrpt) { char entry[PATH_MAX+1]; char *realname = NULL; - const char *name; + const char *name = NULL; boolean found; - if ((rll = readlinkat(dfd, here(d->d_name, "exe"), entry, PATH_MAX)) < 0) { - if (errno != EPERM && errno != EACCES) - goto risky; - continue; - } - entry[rll] = '\0'; - name = handl_buf(entry); + if (prefix) { + if ((rll = readlinkat(dfd, here(d->d_name, "exe"), entry, PATH_MAX)) < 0) { + if (errno != EPERM && errno != EACCES) + goto risky; + continue; + } + entry[rll] = '\0'; + name = handl_buf(entry); - if (prefix && find_mount(name) != prefix) - continue; + if (!find_mount(name, prefix)) + continue; + } if (fstatat(dfd, here(d->d_name, "exe"), &pid_st, 0) < 0) { if (errno != EPERM && errno != EACCES) @@ -765,12 +768,22 @@ int pidof (const char * inname, const ch if (strlen(fullname) > PATH_MAX) continue; + if (!name) { + if ((rll = readlinkat(dfd, here(d->d_name, "exe"), entry, PATH_MAX)) < 0) { + if (errno != EPERM && errno != EACCES) + goto risky; + continue; + } + entry[rll] = '\0'; + name = handl_buf(entry); + } + if (strncmp(fullname, name, PATH_MAX) == 0) { found = true; break; } - if ((realname = realpath(name, NULL)) == (char*)0) + if ((realname = realpath(fullname, NULL)) == (char*)0) continue; if (strncmp(realname, name, PATH_MAX) == 0)