-/* $OpenBSD: shutdown.c,v 1.39 2015/01/21 19:29:52 naddy Exp $ */
+/* $OpenBSD: shutdown.c,v 1.40 2015/01/21 19:38:53 naddy Exp $ */
/* $NetBSD: shutdown.c,v 1.9 1995/03/18 15:01:09 cgd Exp $ */
/*
(void)printf(" with dump");
(void)printf("\nkill -HUP 1\n");
#else
- if (doreboot) {
- execle(_PATH_REBOOT, "reboot", "-l",
- (nosync ? "-n" : (dodump ? "-d" : NULL)),
- (dodump ? "-d" : NULL), (char *)NULL, (char *)NULL);
- syslog(LOG_ERR, "shutdown: can't exec %s: %m.", _PATH_REBOOT);
- warn(_PATH_REBOOT);
- }
- else if (dohalt || dopower) {
- execle(_PATH_HALT, "halt", "-l",
- (dopower ? "-p" : (nosync ? "-n" : (dodump ? "-d" : NULL))),
- (nosync ? "-n" : (dodump ? "-d" : NULL)),
- (dodump ? "-d" : NULL), (char *)NULL, (char *)NULL);
- syslog(LOG_ERR, "shutdown: can't exec %s: %m.", _PATH_HALT);
- warn(_PATH_HALT);
+ if (dohalt || dopower || doreboot) {
+ char *args[10];
+ char **arg, *path;
+
+ arg = &args[0];
+ if (doreboot) {
+ path = _PATH_REBOOT;
+ *arg++ = "reboot";
+ } else {
+ path = _PATH_HALT;
+ *arg++ = "halt";
+ }
+ *arg++ = "-l";
+ if (dopower)
+ *arg++ = "-p";
+ if (nosync)
+ *arg++ = "-n";
+ if (dodump)
+ *arg++ = "-d";
+ *arg++ = NULL;
+ execve(path, args, NULL);
+ syslog(LOG_ERR, "shutdown: can't exec %s: %m.", path);
+ warn(path);
}
if (access(_PATH_RC, R_OK) != -1) {
pid_t pid;