dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libast / common / preroot / setpreroot.c
blob1656e0703e6b60b11151ee0faddf19459aeeccfc
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #pragma prototyped
24 * AT&T Bell Laboratories
25 * force current command to run under dir preroot
28 #include <ast.h>
29 #include <preroot.h>
31 #if FS_PREROOT
33 #include <option.h>
35 void
36 setpreroot(register char** argv, const char* dir)
38 register char* s;
39 register char** ap;
40 int argc;
41 char* cmd;
42 char** av;
43 char buf[PATH_MAX];
45 if ((argv || (argv = opt_info.argv)) && (dir || (dir = getenv(PR_BASE)) && *dir) && !ispreroot(dir) && (*(cmd = *argv++) == '/' || (cmd = pathpath(buf, cmd, NiL, PATH_ABSOLUTE|PATH_REGULAR|PATH_EXECUTE))))
47 argc = 3;
48 for (ap = argv; *ap++; argc++);
49 if (av = newof(0, char*, argc, 0))
51 ap = av;
52 *ap++ = PR_COMMAND;
53 *ap++ = dir;
54 *ap++ = cmd;
55 while (*ap++ = *argv++);
56 if (!(s = getenv(PR_SILENT)) || !*s)
58 sfprintf(sfstderr, "+");
59 ap = av;
60 while (s = *ap++)
61 sfprintf(sfstderr, " %s", s);
62 sfprintf(sfstderr, "\n");
63 sfsync(sfstderr);
65 execv(*av, av);
66 free(av);
71 #else
73 NoN(setpreroot)
75 #endif