This repository has been archived by the owner on Jul 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrov-util.c
62 lines (56 loc) · 1.53 KB
/
rov-util.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
#include "rov-util.h"
#include "stdlib.h"
#include "unistd.h"
#include "stdio.h"
#include "string.h"
#include "../rovlog/rovlog.h"
void safe_shutdown(void) {
//TODO
}
short start_child(char *path) {
//TODO
int forkval = fork();
if(forkval < 0) {
perror("fork");
exit(-1);
} else if (forkval > 0) {
// I'm the parent.
return forkval;
} else {
// I'm the child, so I'm going to be the new process.
int errval = execvp(path, NULL);
char buff[64];
sprintf(buff, "Process %s closed: %i ", path, errval);
perror("child exit: ");
rovlog(INFO, buff); // If we got here, the process closed.
}
}
short start_child_args(char *path, char *arg) {
int forkval = fork();
if(forkval < 0) {
perror("fork");
exit(-1);
} else if (forkval > 0) {
// I'm the parent.
return forkval;
} else {
// I'm the child, so I'm going to be the new process.
int errval = execvp(path, arg);
char buff[64];
sprintf(buff, "Process %s closed: %i ", path, errval);
perror("child exit: ");
rovlog(INFO, buff); // If we got here, the process closed.
}
}
short stop_child(short pid) {
//TODO
}
short checkup_child(short pid) {
// POSIX standard says kill -0 to check if process exists
int killresult = kill(pid, 0);
if(killresult != 0)
return -1; // The process does not exist and needs to be restarted
else
return 0;
// TODO: Use the heartbeat stuff
}