diff options
| author | David M. Syzdek <syzdek@bindlebinaries.com> | 2010-09-28 17:27:27 -0800 |
|---|---|---|
| committer | David M. Syzdek <syzdek@bindlebinaries.com> | 2010-09-28 17:27:27 -0800 |
| commit | 334b47a80dc047a29554c61dff3066e5fb989112 (patch) | |
| tree | 1590a18944685b0a3559cbdfbb7b8b1ab7c23170 /src/suicide.c | |
| parent | f2425de76a6cbd9cc9f5b674f875fb12f4f9350c (diff) | |
| download | dmstools-334b47a80dc047a29554c61dff3066e5fb989112.tar.gz dmstools-334b47a80dc047a29554c61dff3066e5fb989112.tar.bz2 dmstools-334b47a80dc047a29554c61dff3066e5fb989112.tar.xz dmstools-334b47a80dc047a29554c61dff3066e5fb989112.zip | |
Adding ability to attempt to catch signal to suicide.
Diffstat (limited to 'src/suicide.c')
| -rw-r--r-- | src/suicide.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/suicide.c b/src/suicide.c index bb037db..d6da7bd 100644 --- a/src/suicide.c +++ b/src/suicide.c | |||
| @@ -320,6 +320,7 @@ int main(int argc, char * argv[]) | |||
| 320 | int c; | 320 | int c; |
| 321 | int val; | 321 | int val; |
| 322 | int verbose; | 322 | int verbose; |
| 323 | int attempt_catch; | ||
| 323 | int opt_index; | 324 | int opt_index; |
| 324 | char buff[16]; | 325 | char buff[16]; |
| 325 | pid_t p; // process ID | 326 | pid_t p; // process ID |
| @@ -328,7 +329,7 @@ int main(int argc, char * argv[]) | |||
| 328 | size_t action_size; | 329 | size_t action_size; |
| 329 | SuicideAction ** actions; | 330 | SuicideAction ** actions; |
| 330 | 331 | ||
| 331 | static char short_opt[] = "hn:s:SvV"; | 332 | static char short_opt[] = "chn:s:SvV"; |
| 332 | static struct option long_opt[] = | 333 | static struct option long_opt[] = |
| 333 | { | 334 | { |
| 334 | {"help", no_argument, 0, 'h'}, | 335 | {"help", no_argument, 0, 'h'}, |
| @@ -350,6 +351,7 @@ int main(int argc, char * argv[]) | |||
| 350 | verbose = 0; | 351 | verbose = 0; |
| 351 | opt_index = 0; | 352 | opt_index = 0; |
| 352 | action_size = 0; | 353 | action_size = 0; |
| 354 | attempt_catch = 0; | ||
| 353 | 355 | ||
| 354 | while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1) | 356 | while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1) |
| 355 | { | 357 | { |
| @@ -358,6 +360,9 @@ int main(int argc, char * argv[]) | |||
| 358 | case -1: /* no more arguments */ | 360 | case -1: /* no more arguments */ |
| 359 | case 0: /* long options toggles */ | 361 | case 0: /* long options toggles */ |
| 360 | break; | 362 | break; |
| 363 | case 'c': | ||
| 364 | attempt_catch = 1; | ||
| 365 | break; | ||
| 361 | case 'h': | 366 | case 'h': |
| 362 | suicide_usage(); | 367 | suicide_usage(); |
| 363 | return(0); | 368 | return(0); |
| @@ -397,8 +402,9 @@ int main(int argc, char * argv[]) | |||
| 397 | printf(">> getpid(): %i\n", p); | 402 | printf(">> getpid(): %i\n", p); |
| 398 | }; | 403 | }; |
| 399 | 404 | ||
| 400 | for(c = 0; c < 32; c++) | 405 | if (attempt_catch) |
| 401 | signal(c, suicide_signal_handler); | 406 | for(c = 0; c < 32; c++) |
| 407 | signal(c, suicide_signal_handler); | ||
| 402 | 408 | ||
| 403 | for(count = 0; count < action_size; count++) | 409 | for(count = 0; count < action_size; count++) |
| 404 | { | 410 | { |
| @@ -406,9 +412,12 @@ int main(int argc, char * argv[]) | |||
| 406 | snprintf(buff, 16L, "%s", actions[count]->data->name); | 412 | snprintf(buff, 16L, "%s", actions[count]->data->name); |
| 407 | else | 413 | else |
| 408 | snprintf(buff, 16L, "%i", actions[count]->number); | 414 | snprintf(buff, 16L, "%i", actions[count]->number); |
| 409 | if (verbose) | 415 | if (attempt_catch) |
| 410 | printf(">> signal(%s)\n", buff); | 416 | { |
| 411 | signal(actions[count]->number, suicide_signal_handler); | 417 | if (verbose) |
| 418 | printf(">> signal(%s)\n", buff); | ||
| 419 | signal(actions[count]->number, suicide_signal_handler); | ||
| 420 | }; | ||
| 412 | printf(">> kill(%i, %s)\n", p, buff); | 421 | printf(">> kill(%i, %s)\n", p, buff); |
| 413 | kill(p, actions[count]->number); | 422 | kill(p, actions[count]->number); |
| 414 | if (verbose) | 423 | if (verbose) |
| @@ -528,6 +537,7 @@ void suicide_usage(void) | |||
| 528 | // line. The two strings referenced are: PROGRAM_NAME, and | 537 | // line. The two strings referenced are: PROGRAM_NAME, and |
| 529 | // PACKAGE_BUGREPORT | 538 | // PACKAGE_BUGREPORT |
| 530 | printf(_("Usage: %s [OPTIONS]\n" | 539 | printf(_("Usage: %s [OPTIONS]\n" |
| 540 | " -c attempt to catch signals\n" | ||
| 531 | " -h, --help print this help and exit\n" | 541 | " -h, --help print this help and exit\n" |
| 532 | " -n signum signal number to send\n" | 542 | " -n signum signal number to send\n" |
| 533 | " -s sigspec signal name to send\n" | 543 | " -s sigspec signal name to send\n" |
