2008-09-24 17:38:00 +02:00
|
|
|
--- src/killall5.c
|
2009-04-01 18:20:36 +02:00
|
|
|
+++ src/killall5.c 2009-01-27 16:32:40.000000000 +0100
|
2009-01-29 01:08:29 +01:00
|
|
|
@@ -59,6 +59,8 @@ typedef struct proc {
|
|
|
|
pid_t pid; /* Process ID. */
|
|
|
|
int sid; /* Session ID. */
|
|
|
|
char kernel; /* Kernel thread or zombie. */
|
|
|
|
+ char isfuse; /* Provides FUSE filesystems */
|
|
|
|
+ char isudev; /* Is the uevent handler */
|
|
|
|
char nfs; /* Binary is loacted on NFS part. */
|
|
|
|
struct proc *next; /* Pointer to next struct. */
|
|
|
|
} PROC;
|
2009-04-01 18:20:36 +02:00
|
|
|
@@ -410,6 +412,38 @@ int readarg(FILE *fp, char *buf, int sz)
|
2008-09-24 17:38:00 +02:00
|
|
|
}
|
|
|
|
|
2009-01-29 01:08:29 +01:00
|
|
|
/*
|
2008-09-24 17:38:00 +02:00
|
|
|
+ * Scan the filedescriptors of pid for /dev/fuse
|
|
|
|
+ */
|
2009-01-29 01:08:29 +01:00
|
|
|
+int is_fuse(const char *pid) {
|
2008-09-24 17:38:00 +02:00
|
|
|
+ DIR *dir;
|
|
|
|
+ char path[256];
|
|
|
|
+ char buf[256];
|
|
|
|
+ struct dirent *d;
|
|
|
|
+ ssize_t len;
|
|
|
|
+
|
|
|
|
+ /* Open /proc/pid/fd/ */
|
2009-01-29 01:08:29 +01:00
|
|
|
+ snprintf(path, sizeof(path), "/proc/%s/fd", pid);
|
2008-09-24 17:38:00 +02:00
|
|
|
+ if ((dir = opendir(path)) != NULL) {
|
2009-01-29 01:08:29 +01:00
|
|
|
+ int dfd = dirfd(dir);
|
2008-09-24 17:38:00 +02:00
|
|
|
+ /* Walk through the directory. */
|
|
|
|
+ while ((d = readdir(dir)) != NULL) {
|
2008-10-06 17:17:04 +02:00
|
|
|
+ if (*d->d_name == '.')
|
|
|
|
+ continue;
|
2008-09-24 17:38:00 +02:00
|
|
|
+ /* check for /dev/fuse */
|
2009-01-29 01:08:29 +01:00
|
|
|
+ if ((len = readlinkat(dfd, d->d_name, buf, sizeof(buf))) > 0) {
|
|
|
|
+ buf[len] = '\0';
|
|
|
|
+ if (strcmp("/dev/fuse", buf) == 0)
|
|
|
|
+ return 1; /* Fuse filesystem */
|
2008-09-24 17:38:00 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ closedir(dir);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* Not a fuse filesystem */
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
2009-01-29 01:08:29 +01:00
|
|
|
+/*
|
|
|
|
* Read the proc filesystem.
|
|
|
|
*/
|
|
|
|
int readproc()
|
2009-04-01 18:20:36 +02:00
|
|
|
@@ -565,13 +599,19 @@ int readproc()
|
2009-01-29 01:08:29 +01:00
|
|
|
|
|
|
|
/* Try to stat the executable. */
|
|
|
|
snprintf(path, sizeof(path), "/proc/%s/exe", d->d_name);
|
|
|
|
- if (check4nfs(path, NULL))
|
|
|
|
+ if (check4nfs(path, buf))
|
|
|
|
p->nfs = 1;
|
|
|
|
if ((p->nfs == 0) && (stat(path, &st) == 0)) {
|
|
|
|
p->dev = st.st_dev;
|
|
|
|
p->ino = st.st_ino;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ /* Check for uevent handler */
|
|
|
|
+ p->isudev = (strncmp(buf, "/sbin/udevd", 11) == 0);
|
|
|
|
+
|
|
|
|
+ /* Check for provider of FUSE filesystems */
|
|
|
|
+ p->isfuse = is_fuse(d->d_name);
|
|
|
|
+
|
|
|
|
/* Link it into the list. */
|
|
|
|
p->next = plist;
|
|
|
|
plist = p;
|
2009-04-01 18:20:36 +02:00
|
|
|
@@ -907,14 +947,16 @@ int main(int argc, char **argv)
|
2008-09-24 17:38:00 +02:00
|
|
|
}
|
2009-04-01 18:20:36 +02:00
|
|
|
clear_mnt();
|
2008-09-24 17:38:00 +02:00
|
|
|
|
|
|
|
- /* Now kill all processes except our session. */
|
2008-10-06 17:17:04 +02:00
|
|
|
+ /* Now kill all processes except init (pid 1), our session, and FUSE filesystems. */
|
2008-09-24 17:38:00 +02:00
|
|
|
sid = (int)getsid(0);
|
|
|
|
pid = (int)getpid();
|
|
|
|
for (p = plist; p; p = p->next) {
|
|
|
|
- if (p->pid == 1 || p->pid == pid || p->sid == sid || p->kernel) {
|
2009-01-29 01:08:29 +01:00
|
|
|
+ if (p->pid == 1 || p->pid == pid || p->sid == sid || p->kernel || p->isfuse) {
|
2008-09-24 17:38:00 +02:00
|
|
|
kill(p->pid, SIGCONT);
|
|
|
|
continue;
|
|
|
|
}
|
2009-01-29 01:08:29 +01:00
|
|
|
+ if (((sig == SIGTERM) || (sig == SIGKILL)) && p->isudev)
|
|
|
|
+ continue;
|
|
|
|
kill(p->pid, sig);
|
|
|
|
}
|
|
|
|
|