-
Notifications
You must be signed in to change notification settings - Fork 2
/
Human.c
62 lines (53 loc) · 1.78 KB
/
Human.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
51
52
53
54
55
56
57
58
59
60
61
62
/* This program reads settings.txt, and based on line 1 (shell vs. desktop)
* executes either the shell program, or continues by forking and executing
* a desktop program, while also launching the applications program and
* managing everything from the background.
*/
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
void exec(char path[]) {
pid_t pid; //i think pid_t relies on sys/types.h? just a guess, based on the name (types.h)
char *const parmList[] = {NULL};
if ((pid = fork()) == -1) printf("fork error\nKat-OS has been Rendered Inoperable\n\nPlease Cut Power"); //Check if fork failed
else if (pid == 0) {
execv(path, parmList); //runs main() function in program located at $path with arguments $parmList, which should be a NULL terminated string
printf("Return not expected. Must be an execv error\nKat-OS has been Rendered Inoperable\n\nPlease Cut Power"); //This will only run if execv() failed, because execv() should terminate the existing process
}
}
char readSetting(char setting[], int s_len){
FILE* ptr;
char str[20000];
ptr = fopen("config.txt", "a+");
if (NULL == ptr) {
printf("config.txt can't be opened \n Please try rebooting");
}
fgets(str, 20000, ptr);
fclose(ptr);
int i = 0;
while(1){
if(str[i] == setting[0]){
int x = 1; ++i;
while(1){
if(str[i] != setting[x]) break;
if((s_len - 1) == x){
++i;
if(str[i] == '='){
++i;
return str[i];
}
} ++i; ++x;
}
} ++i;
}
}
int main(){
char ShellOrDesktop = readSetting("Shell/Desktop", 13);
switch(ShellOrDesktop){
case 's': exec("Shell");
case 'S': exec("Shell");
case 'd': exec("Desk");
case 'D': exec("Desk");
}
}
// Compile as "Human"