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