Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libast/preroot/setpreroot.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1985-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* David Korn <[email protected]> *
19
* Phong Vo <[email protected]> *
20
* *
21
***********************************************************************/
22
#pragma prototyped
23
/*
24
* AT&T Bell Laboratories
25
* force current command to run under dir preroot
26
*/
27
28
#include <ast.h>
29
#include <preroot.h>
30
31
#if FS_PREROOT
32
33
#include <option.h>
34
35
void
36
setpreroot(register char** argv, const char* dir)
37
{
38
register char* s;
39
register char** ap;
40
int argc;
41
char* cmd;
42
char** av;
43
char buf[PATH_MAX];
44
45
if ((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)))))
46
{
47
argc = 3;
48
for (ap = argv; *ap++; argc++);
49
if (av = newof(0, char*, argc, 0))
50
{
51
ap = av;
52
*ap++ = PR_COMMAND;
53
*ap++ = (char*)dir;
54
*ap++ = cmd;
55
while (*ap++ = *argv++);
56
if (!(s = getenv(PR_SILENT)) || !*s)
57
{
58
sfprintf(sfstderr, "+");
59
ap = av;
60
while (s = *ap++)
61
sfprintf(sfstderr, " %s", s);
62
sfprintf(sfstderr, "\n");
63
sfsync(sfstderr);
64
}
65
execv(*av, av);
66
free(av);
67
}
68
}
69
}
70
71
#else
72
73
NoN(setpreroot)
74
75
#endif
76
77