Browse Source

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 years ago
parent
commit
54195c8b76
1 changed files with 23 additions and 2 deletions
  1. 23
    2
      src/netsukuku.c

+ 23
- 2
src/netsukuku.c View File

171
 		"\n"
171
 		"\n"
172
 		" -d	Debug (Add more ds to get more info)\n"
172
 		" -d	Debug (Add more ds to get more info)\n"
173
 		" -h	Shows this help\n"
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
 
348
 
348
 			{"debug", 	0, 0, 'd'},
349
 			{"debug", 	0, 0, 'd'},
349
 			{"version",	0, 0, 'v'},
350
 			{"version",	0, 0, 'v'},
351
+			{"kill", 0, 0, 'k'},
350
 			{0, 0, 0, 0}
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
 				&option_index);
356
 				&option_index);
355
 		if (c == -1)
357
 		if (c == -1)
356
 			break;
358
 			break;
361
 				printf("%s\n",VERSION_STR);
363
 				printf("%s\n",VERSION_STR);
362
 				exit(0);
364
 				exit(0);
363
 				break;
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
 			case 'h':
385
 			case 'h':
365
 				usage();
386
 				usage();
366
 				exit(0);
387
 				exit(0);

Loading…
Cancel
Save