Selaa lähdekoodia

I spent a few hours adding a kill argument to ntkd, You can now kill an instance of ntkd by just running another with -k

MissValeska 10 vuotta sitten
vanhempi
commit
54195c8b76
1 muutettua tiedostoa jossa 23 lisäystä ja 2 poistoa
  1. 23
    2
      src/netsukuku.c

+ 23
- 2
src/netsukuku.c Näytä tiedosto

@@ -171,7 +171,8 @@ void usage(void)
171 171
 		"\n"
172 172
 		" -d	Debug (Add more ds to get more info)\n"
173 173
 		" -h	Shows this help\n"
174
-		" -v	Shows the version you are using\n");
174
+		" -v	Shows the version you are using\n"
175
+                " -k     Kills the running instance of ntkd\n");
175 176
 }
176 177
 
177 178
 /*
@@ -347,10 +348,11 @@ void parse_options(int argc, char **argv)
347 348
 
348 349
 			{"debug", 	0, 0, 'd'},
349 350
 			{"version",	0, 0, 'v'},
351
+			{"kill", 0, 0, 'k'},
350 352
 			{0, 0, 0, 0}
351 353
 		};
352 354
 
353
-		c = getopt_long (argc, argv,"i:c:l:hvd64DRrIa", long_options,
355
+		c = getopt_long (argc, argv,"i:c:l:hvd64DRrIak", long_options,
354 356
 				&option_index);
355 357
 		if (c == -1)
356 358
 			break;
@@ -361,6 +363,25 @@ void parse_options(int argc, char **argv)
361 363
 				printf("%s\n",VERSION_STR);
362 364
 				exit(0);
363 365
 				break;
366
+                        case 'k':
367
+                            if(is_ntkd_already_running() == 1){
368
+                            char process_name[256] = {0};
369
+                            pid_t pid;
370
+                            printf("...Shutting down ntkd...\n");
371
+                            FILE *fd=fopen(server_opt.pid_file, "r");
372
+                            while(fscanf(fd, "%s %d", process_name, &pid)!=EOF) {
373
+                                    if(strcmp(process_name, "ntkd") == 0) {
374
+                                    kill(pid, SIGKILL);
375
+                                        }
376
+                                    }
377
+                                    fclose(fd);
378
+                                    exit(0);
379
+                            }
380
+                            else if(is_ntkd_already_running() == 0) {
381
+                                printf("ntkd is not running\n ...Exiting...\n");
382
+                                exit(0);
383
+                            }
384
+                            break;
364 385
 			case 'h':
365 386
 				usage();
366 387
 				exit(0);

Loading…
Peruuta
Tallenna