aboutsummaryrefslogtreecommitdiff
path: root/sbin/shutdown
diff options
context:
space:
mode:
authorAlexander Langer <alex@FreeBSD.org>1998-01-10 20:11:06 +0000
committerAlexander Langer <alex@FreeBSD.org>1998-01-10 20:11:06 +0000
commitf6faa785f225f9fc1b2f6428eb0a0c7ae8f5f394 (patch)
tree0bd62e4042563ac2a5dd3493fbba1f9c67d81985 /sbin/shutdown
parent1f48070a27cc8a5a4aa6eaaa7ee7476254321b3e (diff)
downloadsrc-f6faa785f225f9fc1b2f6428eb0a0c7ae8f5f394.tar.gz
src-f6faa785f225f9fc1b2f6428eb0a0c7ae8f5f394.zip
Pass an actual empty environment to execle() as per POSIX rather than
rely on undocumented behavior. The following fixes were obtained from OpenBSD: o -Wall fixes to tlist array initialization and assignment used as truth value. o Use a restricted environment. o Improved error message when shutdown fails to exec reboot or halt.
Notes
Notes: svn path=/head/; revision=32399
Diffstat (limited to 'sbin/shutdown')
-rw-r--r--sbin/shutdown/shutdown.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/sbin/shutdown/shutdown.c b/sbin/shutdown/shutdown.c
index 145f0e747f49..11911b07ef54 100644
--- a/sbin/shutdown/shutdown.c
+++ b/sbin/shutdown/shutdown.c
@@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: shutdown.c,v 1.10 1998/01/08 02:23:59 alex Exp $
+ * $Id: shutdown.c,v 1.11 1998/01/08 20:05:45 alex Exp $
*/
#ifndef lint
@@ -73,10 +73,18 @@ static char sccsid[] = "@(#)shutdown.c 8.2 (Berkeley) 2/16/94";
struct interval {
int timeleft, timetowait;
} tlist[] = {
- 10 H, 5 H, 5 H, 3 H, 2 H, 1 H, 1 H, 30 M,
- 30 M, 10 M, 20 M, 10 M, 10 M, 5 M, 5 M, 3 M,
- 2 M, 1 M, 1 M, 30 S, 30 S, 30 S,
- 0, 0,
+ { 10 H, 5 H },
+ { 5 H, 3 H },
+ { 2 H, 1 H },
+ { 1 H, 30 M },
+ { 30 M, 10 M },
+ { 20 M, 10 M },
+ { 10 M, 5 M },
+ { 5 M, 3 M },
+ { 2 M, 1 M },
+ { 1 M, 30 S },
+ { 30 S, 30 S },
+ { 0 , 0 }
};
#undef H
#undef M
@@ -226,7 +234,7 @@ loop()
* Warn now, if going to sleep more than a fifth of
* the next wait time.
*/
- if (sltime = offset - tp->timeleft) {
+ if ((sltime = offset - tp->timeleft)) {
if (sltime > tp->timetowait / 5)
timewarn(offset);
(void)sleep(sltime);
@@ -247,6 +255,11 @@ loop()
static jmp_buf alarmbuf;
+static char *restricted_environ[] = {
+ "PATH=" _PATH_STDPATH,
+ NULL
+};
+
void
timewarn(timeleft)
int timeleft;
@@ -255,12 +268,14 @@ timewarn(timeleft)
static char hostname[MAXHOSTNAMELEN + 1];
FILE *pf;
char wcmd[MAXPATHLEN + 4];
+ extern char **environ;
if (!first++)
(void)gethostname(hostname, sizeof(hostname));
/* undoc -n option to wall suppresses normal wall banner */
(void)snprintf(wcmd, sizeof(wcmd), "%s -n", _PATH_WALL);
+ environ = restricted_environ;
if (!(pf = popen(wcmd, "w"))) {
syslog(LOG_ERR, "shutdown: can't find %s: %m", _PATH_WALL);
return;
@@ -307,6 +322,7 @@ timeout(signo)
void
die_you_gravy_sucking_pig_dog()
{
+ char *empty_environ[] = { NULL };
syslog(LOG_NOTICE, "%s by %s: %s",
doreboot ? "reboot" : dohalt ? "halt" : "shutdown", whom, mbuf);
@@ -327,14 +343,16 @@ die_you_gravy_sucking_pig_dog()
(void)printf("\nkill -HUP 1\n");
#else
if (doreboot) {
- execle(_PATH_REBOOT, "reboot", "-l", nosync, NULL, NULL);
+ execle(_PATH_REBOOT, "reboot", "-l", nosync,
+ (char *)NULL, empty_environ);
syslog(LOG_ERR, "shutdown: can't exec %s: %m.", _PATH_REBOOT);
- perror("shutdown");
+ warn(_PATH_REBOOT);
}
else if (dohalt) {
- execle(_PATH_HALT, "halt", "-l", nosync, NULL, NULL);
+ execle(_PATH_HALT, "halt", "-l", nosync,
+ (char *)NULL, empty_environ);
syslog(LOG_ERR, "shutdown: can't exec %s: %m.", _PATH_HALT);
- perror("shutdown");
+ warn(_PATH_HALT);
}
(void)kill(1, SIGTERM); /* to single user */
#endif