TIme to fork off and die if we are the parent.
This commit is contained in:
parent
323fd19544
commit
7f5d4502a9
23
main.c
23
main.c
@ -101,6 +101,26 @@ void readToHost(char *host, FILE *hostsFile)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Daemonize the process, to be run like this ONLY if there were no arguments
|
||||
* provided.
|
||||
*
|
||||
* TODO:
|
||||
* read the config file.
|
||||
*/
|
||||
void daemonize() {
|
||||
pid_t mypid = fork();
|
||||
if (mypid != 0) {
|
||||
// I am the parent, kill myself
|
||||
fprintf(stderr, "Parent exiting");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
else {
|
||||
// DO THE THING.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entrypoint.
|
||||
*/
|
||||
@ -142,6 +162,9 @@ int main(int argc, char **argv)
|
||||
{
|
||||
showHosts();
|
||||
}
|
||||
else {
|
||||
daemonize();
|
||||
}
|
||||
}
|
||||
|
||||
if (hostsFile != NULL)
|
||||
|
Loading…
Reference in New Issue
Block a user