173 lines
4.0 KiB
Plaintext
173 lines
4.0 KiB
Plaintext
|
--- Makefile
|
||
|
+++ Makefile 2008-12-04 18:59:57.812644400 +0100
|
||
|
@@ -54,9 +54,10 @@ UBINPRG =
|
||
|
ifeq ($(DISTRO),SuSE)
|
||
|
UBINPRG += usleep
|
||
|
UBINPRG += fsync
|
||
|
+ VBINPRG += vhangup
|
||
|
endif
|
||
|
|
||
|
-all: $(SBINPRG) $(UBINPRG)
|
||
|
+all: $(SBINPRG) $(UBINPRG) $(VBINPRG)
|
||
|
|
||
|
libinit.o: libinit.c libinit.h
|
||
|
$(CC) $(CFLAGS) $(CLOOP) -DINITDIR=\"$(INITDIR)\" -c $<
|
||
|
@@ -104,6 +105,10 @@ install: $(TODO)
|
||
|
$(INSTBIN) $$p $(UBINDIR)/; \
|
||
|
$(INSTDOC) $$p.1 $(UDOCDIR)/; \
|
||
|
done
|
||
|
+ for p in $(VBINPRG); do \
|
||
|
+ $(INSTBIN) $$p $(SBINDIR)/; \
|
||
|
+ $(INSTDOC) $$p.8 $(SDOCDIR)/; \
|
||
|
+ done
|
||
|
#
|
||
|
# Make distribution
|
||
|
#
|
||
|
@@ -120,8 +125,10 @@ FILES = README \
|
||
|
libinit.h \
|
||
|
usleep.c \
|
||
|
usleep.1 \
|
||
|
- fsync.c \
|
||
|
- fsync.1 \
|
||
|
+ fsync.c \
|
||
|
+ fsync.1 \
|
||
|
+ vhangup.c \
|
||
|
+ vhangup.8 \
|
||
|
killproc-$(VERSION).lsm
|
||
|
|
||
|
dest:
|
||
|
--- vhangup.8
|
||
|
+++ vhangup.8 2008-12-05 11:29:05.893545808 +0100
|
||
|
@@ -0,0 +1,51 @@
|
||
|
+.\"
|
||
|
+.\" Copyright 2008 Werner Fink, 2008 SUSE LINUX Products GmbH, Germany.
|
||
|
+.\"
|
||
|
+.\" This program is free software; you can redistribute it and/or modify
|
||
|
+.\" it under the terms of the GNU General Public License as published by
|
||
|
+.\" the Free Software Foundation; either version 2 of the License, or
|
||
|
+.\" (at your option) any later version.
|
||
|
+.\"
|
||
|
+.TH VHANGUP 1 "Jan 31, 2008" "Version 1.16" "The SuSE boot concept"
|
||
|
+.UC 1
|
||
|
+.SH NAME
|
||
|
+Vhangup \- Cause a virtually hangup on the specified terminals
|
||
|
+.\"
|
||
|
+.SH SYNOPSIS
|
||
|
+.\"
|
||
|
+.B vhangup [
|
||
|
+.I /dev/<terminal>
|
||
|
+.B [
|
||
|
+.I /dev/<terminal>
|
||
|
+.B ]
|
||
|
+.B ]
|
||
|
+.\"
|
||
|
+.SH DESCRIPTION
|
||
|
+.B vhangup
|
||
|
+simulates a hangup on the specified terminals. Not existing
|
||
|
+device files or devices will be ignored.
|
||
|
+\."
|
||
|
+.SH EXAMPLES
|
||
|
+.nf
|
||
|
+.B vhangup /dev/tty1 /dev/tty2 /dev/tty3 /dev/tty4 /dev/tty5 /dev/tty6 /dev/ttyS1
|
||
|
+
|
||
|
+.fi
|
||
|
+This will replace all open file descriptors in the kernel that points
|
||
|
+to the listed ttys by a dummy that will deny further reading/writing
|
||
|
+to the device. It also send the signals SIGHUP/SIGCONT to the processes
|
||
|
+which have file descriptors open on the listed ttys.
|
||
|
+\."
|
||
|
+.SH RETURN VALUE
|
||
|
+On success, zero is returned. On error, 1 is returned.
|
||
|
+\."
|
||
|
+.SH SEE ALSO
|
||
|
+.BR vhangup (2),
|
||
|
+.BR tty (4),
|
||
|
+.BR ttyS (4),
|
||
|
+.BR pts (4).
|
||
|
+\."
|
||
|
+.SH COPYRIGHT
|
||
|
+2008 Werner Fink,
|
||
|
+2008 SUSE LINUX Products GmbH, Germany.
|
||
|
+.SH AUTHOR
|
||
|
+Werner Fink <werner@suse.de>
|
||
|
--- vhangup.c
|
||
|
+++ vhangup.c 2008-12-05 11:47:35.881479139 +0100
|
||
|
@@ -0,0 +1,77 @@
|
||
|
+/*
|
||
|
+ * vhangup.c Cause a hangup on the specified terminals
|
||
|
+ *
|
||
|
+ * Usage: vhangup /dev/tty1 ...
|
||
|
+ *
|
||
|
+ * Copyright 2008 Werner Fink, 2008 SUSE LINUX Products GmbH, Germany.
|
||
|
+ *
|
||
|
+ * This program is free software; you can redistribute it and/or modify
|
||
|
+ * it under the terms of the GNU General Public License as published by
|
||
|
+ * the Free Software Foundation; either version 2 of the License, or
|
||
|
+ * (at your option) any later version.
|
||
|
+ *
|
||
|
+ * Author: Werner Fink <werner@suse.de>
|
||
|
+ */
|
||
|
+
|
||
|
+#ifndef _GNU_SOURCE
|
||
|
+# define _GNU_SOURCE
|
||
|
+#endif
|
||
|
+#include <errno.h>
|
||
|
+#include <fcntl.h>
|
||
|
+#include <stdio.h>
|
||
|
+#include <stdlib.h>
|
||
|
+#include <string.h>
|
||
|
+#include <sys/ioctl.h>
|
||
|
+#include <sys/types.h>
|
||
|
+#include <sys/stat.h>
|
||
|
+#include <sys/wait.h>
|
||
|
+#include <termios.h>
|
||
|
+#include <unistd.h>
|
||
|
+
|
||
|
+int main(int argc, char* argv[])
|
||
|
+{
|
||
|
+ int ret;
|
||
|
+
|
||
|
+ switch (fork()) {
|
||
|
+ case -1:
|
||
|
+ fprintf(stderr, "vhangup: %s\n", strerror(errno));
|
||
|
+ return 1;
|
||
|
+ case 0: {
|
||
|
+ struct sigaction sa, sa_old;
|
||
|
+ int num;
|
||
|
+
|
||
|
+ setsid();
|
||
|
+
|
||
|
+ sa.sa_flags = 0;
|
||
|
+ sa.sa_handler = SIG_IGN;
|
||
|
+ sigemptyset (&sa.sa_mask);
|
||
|
+ sigaction (SIGHUP, &sa, &sa_old);
|
||
|
+
|
||
|
+ for (ret = num = 1; num < argc; num++) {
|
||
|
+ int fd = open(argv[num], O_RDWR|O_NONBLOCK|O_NOCTTY, 0);
|
||
|
+ if (fd < 0) {
|
||
|
+ switch (errno) {
|
||
|
+ case ENOENT:
|
||
|
+ case ENODEV:
|
||
|
+ case ENXIO:
|
||
|
+ ret++;
|
||
|
+ default:
|
||
|
+ break;
|
||
|
+ }
|
||
|
+ continue;
|
||
|
+ }
|
||
|
+ if ((ioctl (fd, TIOCSCTTY, 1) == 0) && (vhangup() == 0))
|
||
|
+ ret++;
|
||
|
+ close(fd);
|
||
|
+ }
|
||
|
+
|
||
|
+ sigaction (SIGHUP, &sa_old, NULL);
|
||
|
+ exit(ret != num);
|
||
|
+ }
|
||
|
+ default:
|
||
|
+ waitpid(-1, &ret, 0);
|
||
|
+ break;
|
||
|
+ }
|
||
|
+
|
||
|
+ return (WIFEXITED(ret)) ? WEXITSTATUS(ret) : 1;
|
||
|
+}
|