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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/types.h>
#include <poll.h>
#include <dirent.h>
//Needs NULL as last arg!!
int run_start(char* _prog, char* _args[])
{
pid_t pid = fork();
if( pid < 0 )
return 1;
else if (pid > 0)
return 0;
setsid();
if(fork())
exit(0);
close(STDOUT_FILENO);
close(STDIN_FILENO);
close(STDERR_FILENO);
execv(_prog, _args);
exit(1);
}
//Need NULL as last arg!!
int run_stdio(char* _prog, const char* _args[])
{
pid_t pid;
if((pid = fork()) == -1)
return 2;
if (pid == 0)
{
execv(_prog, _args);
//Error handling
int err = errno;
printf("Fuckup %i: %s\n", err, strerror(err));
exit(1);
}
else
{
int status;
waitpid(pid, &status, 0);
return 0;
}
}
int exists(const char *fname)
{
FILE *file;
if ((file = fopen(fname, "r")))
{
fclose(file);
return 1;
}
return 0;
}
int main(int argc, char* argv[])
{
printf("MegumInit\n");
printf("(∩ಠ益[+])⊃━☆゚Explosion!\n\n");
char* arg2[] = {"/bin/toybox", "cat", "meg.txt", NULL};
run_stdio(arg2[0], arg2);
return 0;
}
|