sysvinit/killproc-2.15.dif

129 lines
3.0 KiB
Plaintext
Raw Normal View History

--- Makefile
+++ Makefile 2009-05-27 12:05:43.117901008 +0200
@@ -27,6 +27,7 @@ endif
#
# egcs used with -O2 includes -fno-force-mem which is/was buggy (1998/10/08)
#
+ LDFLAGS = -Wl,--as-needed,--hash-size=8599,-O2
CFLAGS = $(RPM_OPT_FLAGS) $(COPTS) $(DEBUG) $(INC) -D_GNU_SOURCE -Wall -pipe
CLOOP = -funroll-loops
CC = gcc
@@ -80,13 +81,13 @@ sig.def:
done
killproc: killproc.c libinit.o
- $(CC) $(CFLAGS) $(CLOOP) -o $@ $^ $(LIBS)
+ $(CC) $(CFLAGS) $(CLOOP) $(LDFLAGS) -o $@ $^ $(LIBS)
startproc: startproc.c libinit.o
- $(CC) $(CFLAGS) $(CLOOP) -o $@ $^ $(LIBS)
+ $(CC) $(CFLAGS) $(CLOOP) $(LDFLAGS) -o $@ $^ $(LIBS)
checkproc: checkproc.c libinit.o
- $(CC) $(CFLAGS) $(CLOOP) -o $@ $^ $(LIBS)
+ $(CC) $(CFLAGS) $(CLOOP) $(LDFLAGS) -o $@ $^ $(LIBS)
usleep: usleep.c
$(CC) $(CFLAGS) -o $@ $^
--- 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 */