1*7fd79137SRobert Mustacchi /* 2*7fd79137SRobert Mustacchi * This file and its contents are supplied under the terms of the 3*7fd79137SRobert Mustacchi * Common Development and Distribution License ("CDDL"), version 1.0. 4*7fd79137SRobert Mustacchi * You may only use this file in accordance with the terms of version 5*7fd79137SRobert Mustacchi * 1.0 of the CDDL. 6*7fd79137SRobert Mustacchi * 7*7fd79137SRobert Mustacchi * A full copy of the text of the CDDL should have accompanied this 8*7fd79137SRobert Mustacchi * source. A copy of the CDDL is also available via the Internet at 9*7fd79137SRobert Mustacchi * http://www.illumos.org/license/CDDL. 10*7fd79137SRobert Mustacchi */ 11*7fd79137SRobert Mustacchi 12*7fd79137SRobert Mustacchi /* 13*7fd79137SRobert Mustacchi * Copyright (c) 2015, Joyent, Inc. 14*7fd79137SRobert Mustacchi */ 15*7fd79137SRobert Mustacchi 16*7fd79137SRobert Mustacchi /* 17*7fd79137SRobert Mustacchi * Alternate execution engine for CTF tools 18*7fd79137SRobert Mustacchi */ 19*7fd79137SRobert Mustacchi 20*7fd79137SRobert Mustacchi #include <stdlib.h> 21*7fd79137SRobert Mustacchi #include <string.h> 22*7fd79137SRobert Mustacchi #include <unistd.h> 23*7fd79137SRobert Mustacchi 24*7fd79137SRobert Mustacchi #include "ctftools.h" 25*7fd79137SRobert Mustacchi 26*7fd79137SRobert Mustacchi void 27*7fd79137SRobert Mustacchi ctf_altexec(const char *env, int argc, char **argv) 28*7fd79137SRobert Mustacchi { 29*7fd79137SRobert Mustacchi const char *alt; 30*7fd79137SRobert Mustacchi char *altexec; 31*7fd79137SRobert Mustacchi 32*7fd79137SRobert Mustacchi alt = getenv(env); 33*7fd79137SRobert Mustacchi if (alt == NULL || *alt == '\0') 34*7fd79137SRobert Mustacchi return; 35*7fd79137SRobert Mustacchi 36*7fd79137SRobert Mustacchi altexec = strdup(alt); 37*7fd79137SRobert Mustacchi if (altexec == NULL) 38*7fd79137SRobert Mustacchi terminate("failed to allocate memory for altexec\n"); 39*7fd79137SRobert Mustacchi 40*7fd79137SRobert Mustacchi if (unsetenv(env) != 0) 41*7fd79137SRobert Mustacchi aborterr("failed to remove %s from environment", env); 42*7fd79137SRobert Mustacchi 43*7fd79137SRobert Mustacchi (void) execv(altexec, argv); 44*7fd79137SRobert Mustacchi terminate("failed to altexec %s", altexec); 45*7fd79137SRobert Mustacchi } 46