TIme to fork off and die if we are the parent.

pull/4/head
Jacob Windle 2019-12-12 19:10:29 -05:00
parent 323fd19544
commit 7f5d4502a9
1 changed files with 23 additions and 0 deletions

23
main.c
View File

@ -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)