DEV: Bump uglifyjs
[discourse_docker.git] / image / base / thpoff.c
1 // PUBLIC DOMAIN CODE
2 //
3 // A tiny program that disable transparent huge pages on arbitrary processes
4 // thpoff echo 1 : will run echo 1 with SET_THP_DISABLE true on the process
5 #include <stdio.h>
6 #include <sys/prctl.h>
7 #include <unistd.h>
8 #include <errno.h>
9
10 int main( int argc, char **argv) {
11 if (argc < 2) {
12 fprintf(stderr, "ERROR: expecting at least 1 argument!\n");
13 return -1;
14 }
15 prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
16
17 char* newargv[argc];
18 int i;
19
20 newargv[argc-1] = NULL;
21 for (i=1; i<argc; i++) {
22 newargv[i-1] = argv[i];
23 }
24
25 execvp(argv[1], newargv);
26
27 if (errno == ENOENT) {
28 fprintf(stderr, "ERROR: file not found\n");
29 return -1;
30 } else if (errno == EACCES) {
31 fprintf(stderr, "ERROR: can not run file\n");
32 return -1;
33 } else if (errno > 0) {
34 fprintf(stderr, "ERROR: %i errno while attempting to run file\n", errno);
35 return -1;
36 }
37
38 return 0;
39 }