sysvinit/killproc-2.15.dif

102 lines
2.2 KiB
Plaintext

--- mkill.c
+++ mkill.c 2009-04-29 12:55:49.480409712 +0200
@@ -100,6 +100,7 @@ int main(int argc, char* argv[])
{
const pid_t pid = getpid();
const pid_t sid = getsid(0);
+ const pid_t ppid = getppid();
proc_t * this, *ptr, * last;
struct dirent * dent;
int dfd, num, nsig = SIGTERM;
@@ -210,6 +211,9 @@ int main(int argc, char* argv[])
if (sid == curr)
continue;
+ if (ppid == curr)
+ continue;
+
found = false;
strcpy(path, dent->d_name);
@@ -308,6 +312,8 @@ int main(int argc, char* argv[])
for (ptr = procs; this; ptr = this) {
last = ptr->prev;
this = ptr->next;
+ if (ptr->pid != curr)
+ continue;
if (ptr == procs) {
if (this) this->prev = (proc_t*)0;
procs = this;
--- usleep.c
+++ usleep.c 2009-04-30 11:40:00.065901445 +0200
@@ -20,20 +20,25 @@
#ifdef __NO_STRING_INLINES
# undef __NO_STRING_INLINES
#endif
+#include <errno.h>
+#include <fcntl.h>
#include <libgen.h>
-#include <string.h>
+#include <sched.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <time.h>
#include <unistd.h>
-#ifdef _POSIX_PRIORITY_SCHEDULING
-# include <sched.h>
-#endif
#define USAGE "Usage:\t%s [ microseconds ]\n", we_are
static char *we_are;
int main(int argc, char **argv)
{
unsigned long int usec = 1;
+ int fd;
if (argc > 2)
goto err;
@@ -45,12 +50,35 @@ int main(int argc, char **argv)
goto err;
}
- if (usec)
+ if ((fd = open("/dev/null", O_RDWR|O_NOCTTY|O_CLOEXEC)) >= 0) {
+ dup2(fd, 0);
+ dup2(fd, 1);
+ dup2(fd, 2);
+ if (fd > 2) close(fd);
+ }
+
+ if (usec) {
+#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 199309L)
+ struct timespec req = {0, 0}, rem = {0, 0};
+ int ret;
+
+ while (usec >= 1000000UL) {
+ req.tv_sec++;
+ usec -= 1000000UL;
+ }
+ req.tv_nsec = usec * 1000;
+
+ do {
+ ret = nanosleep(&req, &rem);
+ if (ret == 0 || errno != EINTR)
+ break;
+ req = rem;
+ } while (req.tv_nsec > 0 || req.tv_sec > 0);
+#else
usleep(usec);
-#ifdef _POSIX_PRIORITY_SCHEDULING
- else
- (void)sched_yield();
#endif
+ } else
+ (void)sched_yield();
_exit(0);
/* Do this at the end for speed */