From 4e1f1c1352644fe459bece0070e2642bb295a768 Mon Sep 17 00:00:00 2001 From: Konstantin Ananyev Date: Wed, 24 Sep 2008 01:32:30 -0700 Subject: 6751653 reboot -f -e introduces new system() calls --- usr/src/cmd/halt/halt.c | 70 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 13 deletions(-) (limited to 'usr/src/cmd/halt') diff --git a/usr/src/cmd/halt/halt.c b/usr/src/cmd/halt/halt.c index ee42e86356..7c3aa679b1 100644 --- a/usr/src/cmd/halt/halt.c +++ b/usr/src/cmd/halt/halt.c @@ -69,6 +69,8 @@ #include #include #include +#include +#include #include #include #include @@ -110,6 +112,9 @@ static ctid_t startdct = -1; #define ZONEADM_PROG "/usr/sbin/zoneadm" +#define LUUMOUNT_PROG "/usr/sbin/luumount" +#define LUMOUNT_PROG "/usr/sbin/lumount" + /* * The length of FASTBOOT_MOUNTPOINT must be less than MAXPATHLEN. */ @@ -850,20 +855,63 @@ is_fastboot_default(uid_t uid) #endif /* __i386 */ } +static int +halt_exec(const char *path, ...) +{ + pid_t pid; + int i; + int st; + const char *arg; + va_list vp; + const char *argv[256]; + + if ((pid = fork()) == -1) { + return (errno); + } else if (pid == 0) { + (void) fclose(stdout); + (void) fclose(stderr); + + argv[0] = path; + i = 1; + + va_start(vp, path); + + do { + arg = va_arg(vp, const char *); + argv[i] = arg; + } while (arg != NULL && + ++i != sizeof (argv) / sizeof (argv[0])); + + va_end(vp); + + (void) execve(path, (char * const *)argv, NULL); + (void) fprintf(stderr, gettext("cannot execute %s: %s\n"), + path, strerror(errno)); + exit(-1); + } else { + if (waitpid(pid, &st, 0) == pid && + !WIFSIGNALED(st) && WIFEXITED(st)) + st = WEXITSTATUS(st); + else + st = -1; + } + return (st); +} + +/* + * Invokes lumount for bename. + * At successfull completion returns zero and copies contents of bename + * into mountpoint[] + */ static int fastboot_bename(const char *bename, char *mountpoint, size_t mpsz) { int rc; - char cmdbuf[MAXPATHLEN]; - (void) snprintf(cmdbuf, sizeof (cmdbuf), - "/usr/sbin/luumount %s > /dev/null 2>&1", bename); - (void) system(cmdbuf); + (void) halt_exec(LUUMOUNT_PROG, "-n", bename, NULL); - (void) snprintf(cmdbuf, sizeof (cmdbuf), - "/usr/sbin/lumount %s %s > /dev/null 2>&1", - bename, FASTBOOT_MOUNTPOINT); - if ((rc = system(cmdbuf)) != 0) + if ((rc = halt_exec(LUMOUNT_PROG, "-n", bename, FASTBOOT_MOUNTPOINT, + NULL)) != 0) (void) fprintf(stderr, gettext("%s: cannot mount BE %s\n"), cmdname, bename); else @@ -1429,11 +1477,7 @@ fail: if (fast_reboot) { if (bename) { - char cmdbuf[MAXPATHLEN]; - - (void) snprintf(cmdbuf, sizeof (cmdbuf), - "/usr/sbin/luumount %s > /dev/null 2>&1", bename); - (void) system(cmdbuf); + (void) halt_exec(LUUMOUNT_PROG, "-n", bename, NULL); } else if (strlen(fastboot_mounted) != 0) { (void) umount(fastboot_mounted); -- cgit v1.2.3