pid_t child, rchild;
char portarg[5], addrarg[33];
const char *afarg;
- int i, r, status;
+ int i, r, status, restore_sigchild;
const int *evilsignal;
sigset_t block, saved;
+ struct sigaction old_sigchild;
unsigned int portval;
switch (addr->sa_family) {
break;
case AF_INET6:
afarg = "6";
- bytes2hex(((struct sockaddr_in6*)addr)->sin6_addr.s6_addr, addrarg, 16);
+ for (i=0; i<16; i++)
+ sprintf(addrarg+i*2,"%02x",
+ ((struct sockaddr_in6*)addr)->sin6_addr.s6_addr[i]);
break;
default:
abort();
sprintf(portarg,"%04x",
portval&0x0ffff);
+ restore_sigchild= 0;
+ if (sigaction(SIGCHLD,NULL,&old_sigchild)) return -1;
+ if (old_sigchild.sa_handler == SIG_IGN) {
+ struct sigaction new_sigchild;
+
+ new_sigchild.sa_handler= SIG_DFL;
+ sigemptyset(&new_sigchild.sa_mask);
+ new_sigchild.sa_flags= 0;
+ if (sigaction(SIGCHLD,&new_sigchild,&old_sigchild)) return -1;
+ restore_sigchild= 1;
+ }
+
child= fork(); if (child==-1) goto x_err;
if (!child) {
r= -1;
x:
if (sigprocmask(SIG_SETMASK,&saved,0)) abort();
+ if (restore_sigchild) {
+ if (sigaction(SIGCHLD,&old_sigchild,NULL)) return -1;
+ if (old_sigchild.sa_handler == SIG_IGN) {
+ int discard;
+ while (waitpid(-1, &discard, WNOHANG) > 0)
+ ;
+ }
+ }
return r;
}