+ Add -deamon mode to kiwix-serve (ID: 2961214)

This commit is contained in:
kelson42 2010-03-18 13:07:40 +00:00
parent a5646c3c44
commit 2d5f4350eb

View File

@ -256,7 +256,7 @@ int main(int argc, char **argv) {
string indexPath = "";
int serverPort = 80;
int daemonFlag = 0;
int daemonFlag = false;
/* Argument parsing */
while (42) {
@ -272,31 +272,32 @@ int main(int argc, char **argv) {
int option_index = 0;
int c = getopt_long(argc, argv, "dvi:p:", long_options, &option_index);
if (c == -1)
break;
if (c != -1) {
switch (c) {
case 'd':
daemonFlag = 1;
break;
case 'v':
verboseFlag = true;
break;
case 'i':
indexPath = optarg;
break;
case 'p':
serverPort = atoi(optarg);
break;
}
if (optind < argc) {
zimPath = argv[optind++];
switch (c) {
case 'd':
daemonFlag = true;
break;
case 'v':
verboseFlag = true;
break;
case 'i':
indexPath = optarg;
break;
case 'p':
serverPort = atoi(optarg);
break;
}
} else {
if (optind < argc) {
zimPath = argv[optind++];
break;
}
}
}
@ -330,6 +331,22 @@ int main(int argc, char **argv) {
hasSearchIndex = false;
}
/* Fork if necessary */
if (daemonFlag) {
pid_t pid;
/* Fork off the parent process */
pid = fork();
if (pid < 0) {
exit(1);
}
/* If we got a good PID, then
we can exit the parent process. */
if (pid > 0) {
exit(0);
}
}
/* Mutex init */
pthread_mutex_init(&readerLock, NULL);
pthread_mutex_init(&searcherLock, NULL);