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

This commit is contained in:
Jacob Windle 2019-12-12 19:10:29 -05:00
parent 323fd19544
commit 7f5d4502a9

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. * Entrypoint.
*/ */
@ -142,6 +162,9 @@ int main(int argc, char **argv)
{ {
showHosts(); showHosts();
} }
else {
daemonize();
}
} }
if (hostsFile != NULL) if (hostsFile != NULL)