Subject: bin/4810: add -D (no-detach) flag to shutdown
To: None <gnats-bugs@gnats.netbsd.org>
From: None <tsarna@endicor.com>
List: netbsd-bugs
Date: 01/12/1998 15:56:43
>Number:         4810
>Category:       bin
>Synopsis:       add -D (no-detach) flag to shutdown
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Jan 12 14:05:00 1998
>Last-Modified:
>Originator:     Ty Sarna
>Organization:
	Endicor Technologies, Inc., San Antonio, Texas
>Release:        1.3
>Environment:

System: NetBSD lotharon.endicor.com 1.3 NetBSD 1.3 (LOTHARON) #5: Mon Jan 5 21:41:37 CST 1998 tsarna@lotharon.endicor.com:/endicor/netbsd/src/sys/arch/sun3/compile/LOTHARON sun3

>Description:
	For some purposes (UPS monitoring daemons, etc.), it's nice for
	program to be able to call shutdown, but be able to abort it if
	conditions change. In other cases, one may wish to run something
	like shutdown -k, followed by other programs. Either case is
	harder than really should be necessary if shutdown detaches (forks).
>How-To-Repeat:
	N/A
>Fix:
	This patch adds a flag -D that prevents shutdown from forking;
	instead, shutdown will run under it's original PID.

--- shutdown.c.orig	Mon Jan 12 15:32:10 1998
+++ shutdown.c	Mon Jan 12 15:38:53 1998
@@ -89,7 +89,7 @@
 #undef S
 
 static time_t offset, shuttime;
-static int dofast, dohalt, doreboot, killflg, mbuflen, nosync, dodump;
+static int dofast, dohalt, doreboot, killflg, mbuflen, nosync, nofork, dodump;
 static char *whom, mbuf[BUFSIZ];
 
 void badtime __P((void));
@@ -120,7 +120,7 @@
 	}
 #endif
 	readstdin = 0;
-	while ((ch = getopt(argc, argv, "-fhknrd")) != -1)
+	while ((ch = getopt(argc, argv, "-fhknrdD")) != -1)
 		switch (ch) {
 		case '-':
 			readstdin = 1;
@@ -143,6 +143,9 @@
 		case 'd':
 			dodump = 1;
 			break;
+		case 'D':
+			nofork = 1;
+			break;
 		case '?':
 		default:
 			usage();
@@ -212,7 +215,7 @@
 	(void)putc('\n', stdout);
 #else
 	(void)setpriority(PRIO_PROCESS, 0, PRIO_MIN);
-	{
+	if (nofork == 0) {
 		int forkpid;
 
 		forkpid = fork();
--- shutdown.8.orig	Mon Jan 12 15:45:01 1998
+++ shutdown.8	Mon Jan 12 15:46:54 1998
@@ -42,7 +42,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl 
-.Op Fl fhkrnd
+.Op Fl fhkrndD
 .Ar time
 .Op Ar warning-message ...
 .Sh DESCRIPTION
@@ -94,6 +94,10 @@
 flags to
 .Xr reboot 8
 to request a forced crash dump and reboot.
+.It Fl D
+Prevents
+.Nm
+from detaching (forking).
 .It Ar time
 .Ar Time
 is the time at which

>Audit-Trail:
>Unformatted: