mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-22 19:38:53 -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 = "";
|
string indexPath = "";
|
||||||
int serverPort = 80;
|
int serverPort = 80;
|
||||||
int daemonFlag = 0;
|
int daemonFlag = false;
|
||||||
|
|
||||||
/* Argument parsing */
|
/* Argument parsing */
|
||||||
while (42) {
|
while (42) {
|
||||||
@ -272,31 +272,32 @@ int main(int argc, char **argv) {
|
|||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
int c = getopt_long(argc, argv, "dvi:p:", long_options, &option_index);
|
int c = getopt_long(argc, argv, "dvi:p:", long_options, &option_index);
|
||||||
|
|
||||||
if (c == -1)
|
if (c != -1) {
|
||||||
break;
|
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
daemonFlag = 1;
|
daemonFlag = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
verboseFlag = true;
|
verboseFlag = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
indexPath = optarg;
|
indexPath = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
serverPort = atoi(optarg);
|
serverPort = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (optind < argc) {
|
if (optind < argc) {
|
||||||
zimPath = argv[optind++];
|
zimPath = argv[optind++];
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -330,6 +331,22 @@ int main(int argc, char **argv) {
|
|||||||
hasSearchIndex = false;
|
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 */
|
/* Mutex init */
|
||||||
pthread_mutex_init(&readerLock, NULL);
|
pthread_mutex_init(&readerLock, NULL);
|
||||||
pthread_mutex_init(&searcherLock, NULL);
|
pthread_mutex_init(&searcherLock, NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user