Mercurial > dropbear
comparison svr-main.c @ 893:860e3522f8fc
- Save errno in signal handlers
- Use _exit() in segv handler
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 15 Feb 2014 21:13:57 +0800 |
parents | aa689d140928 |
children | 0bb16232e7c4 |
comparison
equal
deleted
inserted
replaced
892:ae766a2c8fa7 | 893:860e3522f8fc |
---|---|
335 | 335 |
336 /* catch + reap zombie children */ | 336 /* catch + reap zombie children */ |
337 static void sigchld_handler(int UNUSED(unused)) { | 337 static void sigchld_handler(int UNUSED(unused)) { |
338 struct sigaction sa_chld; | 338 struct sigaction sa_chld; |
339 | 339 |
340 const int saved_errno = errno; | |
341 | |
340 while(waitpid(-1, NULL, WNOHANG) > 0); | 342 while(waitpid(-1, NULL, WNOHANG) > 0); |
341 | 343 |
342 sa_chld.sa_handler = sigchld_handler; | 344 sa_chld.sa_handler = sigchld_handler; |
343 sa_chld.sa_flags = SA_NOCLDSTOP; | 345 sa_chld.sa_flags = SA_NOCLDSTOP; |
344 if (sigaction(SIGCHLD, &sa_chld, NULL) < 0) { | 346 if (sigaction(SIGCHLD, &sa_chld, NULL) < 0) { |
345 dropbear_exit("signal() error"); | 347 dropbear_exit("signal() error"); |
346 } | 348 } |
349 errno = saved_errno; | |
347 } | 350 } |
348 | 351 |
349 /* catch any segvs */ | 352 /* catch any segvs */ |
350 static void sigsegv_handler(int UNUSED(unused)) { | 353 static void sigsegv_handler(int UNUSED(unused)) { |
351 fprintf(stderr, "Aiee, segfault! You should probably report " | 354 fprintf(stderr, "Aiee, segfault! You should probably report " |
352 "this as a bug to the developer\n"); | 355 "this as a bug to the developer\n"); |
353 exit(EXIT_FAILURE); | 356 _exit(EXIT_FAILURE); |
354 } | 357 } |
355 | 358 |
356 /* catch ctrl-c or sigterm */ | 359 /* catch ctrl-c or sigterm */ |
357 static void sigintterm_handler(int UNUSED(unused)) { | 360 static void sigintterm_handler(int UNUSED(unused)) { |
358 | 361 |