mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-22 11:22:38 -04:00
+ Add -deamon mode to kiwix-serve (ID: 2961214)
This commit is contained in:
parent
a5646c3c44
commit
2d5f4350eb
@ -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) {
|
||||
switch (c) {
|
||||
|
||||
case 'd':
|
||||
daemonFlag = 1;
|
||||
break;
|
||||
case 'd':
|
||||
daemonFlag = true;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verboseFlag = true;
|
||||
break;
|
||||
case 'v':
|
||||
verboseFlag = true;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
indexPath = optarg;
|
||||
break;
|
||||
case 'i':
|
||||
indexPath = optarg;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
serverPort = atoi(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
serverPort = atoi(optarg);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (optind < argc) {
|
||||
zimPath = argv[optind++];
|
||||
}
|
||||
} 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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user