NetBSD Problem Report #31531

From taca@back-street.net  Sun Oct  9 14:58:37 2005
Return-Path: <taca@back-street.net>
Received: from ns.back-street.net (221x250x131x194.ap221.ftth.ucom.ne.jp [221.250.131.194])
	by narn.netbsd.org (Postfix) with ESMTP id A6C4063B878
	for <gnats-bugs@gnats.NetBSD.org>; Sun,  9 Oct 2005 14:58:35 +0000 (UTC)
Message-Id: <20051009145825.8D3DA375CB@reef.back-street.net>
Date: Sun,  9 Oct 2005 23:58:25 +0900 (JST)
From: taca@back-street.net
Reply-To: taca@back-street.net
To: gnats-bugs@netbsd.org
Subject: shutdown(8) quietly exit if execed from login shell
X-Send-Pr-Version: 3.95

>Number:         31531
>Category:       bin
>Synopsis:       shutdown(8) quietly exit if execed from login shell
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Oct 09 14:59:00 +0000 2005
>Closed-Date:    Tue Mar 07 22:22:26 +0000 2006
>Last-Modified:  Sat May 30 06:50:02 +0000 2009
>Originator:     Takahiro Kambe
>Release:        NetBSD 3.99.9
>Organization:
Takahiro Kambe
>Environment:


System: NetBSD reef.back-street.net 3.99.9 NetBSD 3.99.9 (CF-R3E) #8: Sun Oct 2 12:09:11 JST 2005 taca@reef.back-street.net:/data/i386/obj/sys/arch/i386/compile/CF-R3E i386
Architecture: i386
Machine: i386
>Description:
	shutdown(8) quietly exit if it is execed from login shell.
	I don't know wheather it is a bug or specification, but my old
	memory tells me that there was no such behavior with older *BSD.
>How-To-Repeat:
	1. login root or normal user and execute su(1) with exec shell
	   builtin coommand.

		% exec su
		Password:
		#

	2. exec shutdown(8).

		# exec /sbin/shutdown now

	3. Wait, but nothing happens.

>Fix:
	Background shutdown(8) process is killed with SIGHUP by init(8)
	as a member of login session process.  So, make shutdown(8) have
	its own session.

--- shutdown.c.orig	2005-10-09 23:50:29.000000000 +0900
+++ shutdown.c	2005-10-09 23:50:30.000000000 +0900
@@ -214,17 +214,11 @@
 #else
 	(void)setpriority(PRIO_PROCESS, 0, PRIO_MIN);
 	if (nofork == 0) {
-		int forkpid;
-
-		forkpid = fork();
-		if (forkpid == -1) {
+		if (daemon(0, 1)) {
 			perror("shutdown: fork");
 			exit(1);
 		}
-		if (forkpid) {
-			(void)printf("shutdown: [pid %d]\n", forkpid);
-			exit(0);
-		}
+		(void)printf("shutdown: [pid %d]\n", getpid());
 	}
 #endif
 	openlog("shutdown", LOG_CONS, LOG_AUTH);

>Release-Note:

>Audit-Trail:
From: Takahiro Kambe <taca@back-street.net>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/31531: shutdown(8) quietly exit if execed from login shell
Date: Mon, 05 Dec 2005 19:33:54 +0900 (JST)

 Using daemon(3) was wrong.  Here is updated patch:

 --- sbin/shutdown/shutdown.c.orig	2005-12-05 19:19:54.000000000 +0900
 +++ sbin/shutdown/shutdown.c	2005-12-05 19:20:04.000000000 +0900
 @@ -225,6 +225,7 @@
  			(void)printf("shutdown: [pid %d]\n", forkpid);
  			exit(0);
  		}
 +		(void)setsid();
  	}
  #endif
  	openlog("shutdown", LOG_CONS, LOG_AUTH);

 -- 
 Takahiro Kambe <taca@back-street.net>

From: John Nemeth <jnemeth@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: PR/31531 CVS commit: src/sbin/shutdown
Date: Tue,  7 Mar 2006 22:19:55 +0000 (UTC)

 Module Name:	src
 Committed By:	jnemeth
 Date:		Tue Mar  7 22:19:55 UTC 2006

 Modified Files:
 	src/sbin/shutdown: shutdown.c

 Log Message:
 PR/31531: Takahiro Kambe: shutdown(8) quietly exit if execed from login shell


 To generate a diff of this commit:
 cvs rdiff -r1.45 -r1.46 src/sbin/shutdown/shutdown.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: jnemeth@netbsd.org
State-Changed-When: Tue, 07 Mar 2006 22:22:26 +0000
State-Changed-Why:
patch applied, thanks


From: Soren Jacobsen <snj@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/31531 CVS commit: [netbsd-3] src/sbin/shutdown
Date: Sat, 30 May 2009 06:45:39 +0000

 Module Name:	src
 Committed By:	snj
 Date:		Sat May 30 06:45:39 UTC 2009

 Modified Files:
 	src/sbin/shutdown [netbsd-3]: Makefile shutdown.c

 Log Message:
 Pull up following revision(s) (requested by jnemeth in ticket #2019):
 	sbin/shutdown/Makefile: revision 1.9
 	sbin/shutdown/shutdown.c: revision 1.45-1.48
 Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
 programs that did not compile before.
 PR/31531: Takahiro Kambe: shutdown(8) quietly exit if execed from login shell
 - sprinkle static
 - pass WARNS=4 and lint
 - use size_t/time_t where appropriate
 - get/setprogname()
 - before executing rc.shutdown, set the real user id to 0, because shutdown
   scripts may depend on it (for example su depends on being root).
 - use warn instead of perror, and make sure we use the right errno.
 PR/36626 - Jukka Salmi -- fails to compile if DEBUG is defined


 To generate a diff of this commit:
 cvs rdiff -u -r1.8 -r1.8.20.1 src/sbin/shutdown/Makefile
 cvs rdiff -u -r1.44 -r1.44.2.1 src/sbin/shutdown/shutdown.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.