-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapper.c
50 lines (42 loc) · 1.2 KB
/
wrapper.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
const char script[] = "/usr/local/lib/project_manager.py";
int main(int argc, char** argv)
{
uid_t uid = getuid();
uid_t euid = geteuid();
if (euid != 0) {
fprintf(stderr, "WARNING: not running with superuser privileges\n");
}
/* copy argument array and NULL terminate the argument array */
char **args = malloc((argc + 1) * sizeof(*args));
if (args == NULL) {
fprintf(stderr, "Error: Failed to allocate memory\n");
return EXIT_FAILURE;
}
args[0] = (char *)script;
int i;
for (i = 1; i < argc; i++) {
/* copy all arguments */
args[i] = argv[i];
}
args[argc] = NULL; /* NULL terminate the array of args */
int ret = execvp(args[0], args);
if (ret == -1) {
const char * msg;
switch (errno) {
case ENOENT:
msg = "Could not find project_manager.py.";
break;
default:
msg = strerror(errno);
}
fprintf(stderr, "ERROR: %s\n", msg);
return EXIT_FAILURE;
}
/* you'll never get here */
return EXIT_SUCCESS;
}