OBS User unknown 2008-12-15 14:10:15 +00:00 committed by Git OBS Bridge
parent e4cfece68d
commit 5c042ce76b
3 changed files with 89 additions and 13 deletions

View File

@ -1,5 +1,5 @@
--- Makefile
+++ Makefile 2008-12-05 16:27:17.683465096 +0100
+++ Makefile 2008-12-05 16:27:17.683465000 +0100
@@ -54,6 +54,8 @@ UBINPRG =
ifeq ($(DISTRO),SuSE)
UBINPRG += usleep
@ -34,7 +34,7 @@
dest:
--- mkill.8
+++ mkill.8 2008-12-05 17:16:14.313863273 +0100
+++ mkill.8 2008-12-05 17:16:14.313863000 +0100
@@ -0,0 +1,77 @@
+.\"
+.\" Copyright 2008 Werner Fink, 2008 SUSE LINUX Products GmbH, Germany.
@ -114,8 +114,8 @@
+.SH AUTHOR
+Werner Fink <werner@suse.de>
--- mkill.c
+++ mkill.c 2008-12-05 17:09:02.275026090 +0100
@@ -0,0 +1,617 @@
+++ mkill.c 2008-12-12 14:30:48.817075022 +0100
@@ -0,0 +1,684 @@
+/*
+ * mkill.c Send a signal to all processes accessing a mount point
+ *
@ -176,6 +176,7 @@
+static void init_signames(void);
+static int signame_to_signum(const char *sig);
+static void init_mnt(int argc, char* argv[]);
+static void clear_mnt(void);
+static void add_proc(pid_t pid);
+static boolean check(const char *restrict name);
+
@ -185,6 +186,7 @@
+ proc_t * this, *ptr, * last;
+ struct dirent * dent;
+ int num, nsig = SIGTERM;
+ boolean found;
+ DIR * proc;
+
+ num = argc;
@ -193,12 +195,16 @@
+ char *sig = argv[num];
+ int tmp, len = strlen(sig);
+ sig++;
+ if ((tmp = atoi(sig)) > 0 && tmp < NSIG) {
+ memset(sig, '\0', len);
+ if (*sig == '0') {
+ memset(argv[num], '\0', len);
+ nsig = 0;
+ break;
+ } else if ((tmp = atoi(sig)) > 0 && tmp < NSIG) {
+ memset(argv[num], '\0', len);
+ nsig = tmp;
+ break;
+ } else if ((tmp = signame_to_signum(sig)) > 0) {
+ memset(sig, '\0', len);
+ memset(argv[num], '\0', len);
+ nsig = tmp;
+ break;
+ }
@ -229,7 +235,6 @@
+ char name[PATH_MAX+1];
+ char line[BUFSIZ+1];
+ char * slash = &path[6];
+ boolean found = false;
+ struct dirent * dfd;
+ ssize_t len;
+ size_t flen;
@ -244,6 +249,8 @@
+ if (pid == curr)
+ continue;
+
+ found = false;
+
+ *slash = '\0';
+ strncpy(slash, dent->d_name, 246);
+ strcat(slash, "/root");
@ -341,23 +348,59 @@
+ add_proc((pid_t)atol(dent->d_name));
+ }
+ (void)closedir(proc);
+ clear_mnt();
+
+ num = 0;
+ this = procs;
+ last = (proc_t*)0;
+ found = false;
+ for(ptr = procs; this; ptr = this) {
+ last = ptr->prev;
+ this = ptr->next;
+ if (nsig)
+ if (nsig) {
+ kill(ptr->pid, nsig);
+ else {
+ found = true;
+ } else {
+ if (num++ > 0)
+ putc(' ', stdout);
+ printf("%d", ptr->pid);
+ }
+ }
+
+ if (num > 0)
+ putc('\n', stdout);
+
+ num = 3000000;
+ if (nsig == SIGTERM) while (found) {
+
+ if ((num <= 0) || !found)
+ break;
+ usleep(10000);
+ num -= 10000;
+
+ this = procs;
+ last = (proc_t*)0;
+ found = false;
+ for(ptr = procs; this; ptr = this) {
+ last = ptr->prev;
+ this = ptr->next;
+
+ if (kill (ptr->pid, 0) < 0) {
+ if (ptr == procs) {
+ if (this) this->prev = (proc_t*)0;
+ procs = this;
+ } else if (last) {
+ if (this) this->prev = last;
+ last->next = this;
+ }
+ free(ptr);
+ continue;
+ }
+
+ found = true;
+ }
+ }
+
+ return 0;
+}
+
@ -412,9 +455,33 @@
+ endmntent(mnt);
+}
+
+static void clear_mnt(void)
+{
+ mntent_t *p, *n, *l;
+
+ n = mntent;
+ l = (mntent_t*)0;
+ for (p = mntent; n; p = n) {
+ l = p->prev;
+ n = p->next;
+ if (p == mntent) {
+ if (n) n->prev = (mntent_t*)0;
+ mntent = n;
+ } else if (l) {
+ if (n) n->prev = l;
+ l->next = n;
+ }
+ free(p);
+ }
+}
+
+static void add_proc(pid_t pid)
+{
+ proc_t * ptr = (proc_t*)malloc(sizeof(proc_t));
+ if (ptr == (proc_t*)0) {
+ fprintf(stderr, "mkill: %s\n", strerror(errno));
+ exit(1);
+ }
+ ptr->pid = pid;
+ if (procs)
+ procs->prev = ptr;
@ -734,7 +801,7 @@
+#endif
+}
--- vhangup.8
+++ vhangup.8 2008-12-05 16:32:40.062425538 +0100
+++ vhangup.8 2008-12-05 16:32:40.062425000 +0100
@@ -0,0 +1,47 @@
+.\"
+.\" Copyright 2008 Werner Fink, 2008 SUSE LINUX Products GmbH, Germany.
@ -784,7 +851,7 @@
+.SH AUTHOR
+Werner Fink <werner@suse.de>
--- vhangup.c
+++ vhangup.c 2008-12-05 11:47:35.881479139 +0100
+++ vhangup.c 2008-12-05 11:47:35.881479000 +0100
@@ -0,0 +1,77 @@
+/*
+ * vhangup.c Cause a hangup on the specified terminals

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Dec 10 14:27:34 CET 2008 - werner@suse.de
- Mkill(8): add the option -0 for debugging and wait upto 3 seconds
if a signal was send.
-------------------------------------------------------------------
Fri Dec 5 16:46:55 CET 2008 - werner@suse.de

View File

@ -30,7 +30,7 @@ Group: System/Base
PreReq: coreutils
AutoReqProv: on
Version: 2.86
Release: 188
Release: 189
Summary: SysV-Style init
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: libselinux-devel libsepol-devel
@ -321,6 +321,9 @@ rm -rf ${RPM_BUILD_ROOT}
%doc %{_mandir}/man8/mkill.8.gz
%changelog
* Wed Dec 10 2008 werner@suse.de
- Mkill(8): add the option -0 for debugging and wait upto 3 seconds
if a signal was send.
* Fri Dec 05 2008 werner@suse.de
- New tool in killproc source tree: mkill(8) for sending all
processes making a active mount busy a signal, this avoid fuser.