sysvinit/sysvinit-2.86-fuse-no-kill.patch

118 lines
2.8 KiB
Diff
Raw Normal View History

--- src/killall5.c
+++ src/killall5.c
@@ -274,6 +274,7 @@
/*
* Read the proc filesystem.
+ * CWD must be /proc.
*/
int readproc()
{
@@ -289,7 +290,7 @@
int pid, f;
/* Open the /proc directory. */
- if ((dir = opendir("/proc")) == NULL) {
+ if ((dir = opendir(".")) == NULL) {
nsyslog(LOG_ERR, "cannot opendir(/proc)");
return -1;
}
@@ -316,10 +317,10 @@
memset(p, 0, sizeof(PROC));
/* Open the status file. */
- snprintf(path, sizeof(path), "/proc/%s/stat", d->d_name);
+ snprintf(path, sizeof(path), "%s/stat", d->d_name);
/* Read SID & statname from it. */
- if ((fp = fopen(path, "r")) != NULL) {
+ if ((fp = fopen(path, "r")) != NULL) {
buf[0] = 0;
fgets(buf, sizeof(buf), fp);
@@ -333,7 +334,7 @@
if (q == NULL) {
p->sid = 0;
nsyslog(LOG_ERR,
- "can't get program name from %s\n",
+ "can't get program name from /proc/%s\n",
path);
if (p->argv0) free(p->argv0);
if (p->argv1) free(p->argv1);
@@ -379,7 +380,7 @@
continue;
}
- snprintf(path, sizeof(path), "/proc/%s/cmdline", d->d_name);
+ snprintf(path, sizeof(path), "%s/cmdline", d->d_name);
if ((fp = fopen(path, "r")) != NULL) {
/* Now read argv[0] */
@@ -446,6 +447,39 @@
return 0;
}
+/*
+ * Scan the filedescriptors of pid for /dev/fuse
+ * CWD must be /proc.
+ */
+int is_fuse(int pid) {
+ DIR *dir;
+ char path[256];
+ char buf[256];
+ struct dirent *d;
+ ssize_t len;
+
+ /* Open /proc/pid/fd/ */
+ snprintf(path, sizeof(path), "%d/fd", pid);
+ if ((dir = opendir(path)) != NULL) {
+ /* Walk through the directory. */
+ while ((d = readdir(dir)) != NULL) {
+ /* check for /dev/fuse */
+ snprintf(path, sizeof(path), "%d/fd/%s",
+ pid, d->d_name);
+ if ((len = readlink(path, buf, sizeof(buf))) > 0) {
+ if (strncmp("/dev/fuse", buf, len) == 0) {
+ /* Fuse filesystem */
+ return 1;
+ }
+ }
+ }
+ closedir(dir);
+ }
+
+ /* Not a fuse filesystem */
+ return 0;
+}
+
PIDQ_HEAD *init_pid_q(PIDQ_HEAD *q)
{
q->head = q->next = q->tail = NULL;
@@ -749,6 +783,11 @@
/* Which NFS partitions are online? */
init_nfs();
+ if (chdir("/proc") == -1) {
+ nsyslog(LOG_ERR, "chdir /proc failed");
+ return(1);
+ }
+
/*
* Ignoring SIGKILL and SIGSTOP do not make sense, but
* someday kill(-1, sig) might kill ourself if we don't
@@ -769,11 +808,12 @@
exit(1);
}
- /* Now kill all processes except our session. */
+ /* Now kill all processes except init (pid 1), our session,
+ and FUSE filesystems. */
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) {
+ if (p->pid == 1 || p->pid == pid || p->sid == sid || p->kernel || is_fuse(p->pid)) {
kill(p->pid, SIGCONT);
continue;
}