/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped22/*23* AT&T Bell Laboratories24* force current command to run under dir preroot25*/2627#include <ast.h>28#include <preroot.h>2930#if FS_PREROOT3132#include <option.h>3334void35setpreroot(register char** argv, const char* dir)36{37register char* s;38register char** ap;39int argc;40char* cmd;41char** av;42char buf[PATH_MAX];4344if ((argv || (argv = opt_info.argv)) && (dir || (dir = getenv(PR_BASE)) && *dir) && !ispreroot(dir) && (*(cmd = *argv++) == '/' || (cmd = pathpath(cmd, NiL, PATH_ABSOLUTE|PATH_REGULAR|PATH_EXECUTE, buf, sizeof(buf)))))45{46argc = 3;47for (ap = argv; *ap++; argc++);48if (av = newof(0, char*, argc, 0))49{50ap = av;51*ap++ = PR_COMMAND;52*ap++ = (char*)dir;53*ap++ = cmd;54while (*ap++ = *argv++);55if (!(s = getenv(PR_SILENT)) || !*s)56{57sfprintf(sfstderr, "+");58ap = av;59while (s = *ap++)60sfprintf(sfstderr, " %s", s);61sfprintf(sfstderr, "\n");62sfsync(sfstderr);63}64execv(*av, av);65free(av);66}67}68}6970#else7172NoN(setpreroot)7374#endif757677