-static int closeSafely(int fd)
-{
- /*If we always initialize file descriptor variables with value -1*/
- /*this method should work like a charm*/
- return (fd == -1) ? 0 : TEMP_FAILURE_RETRY(close(fd));
-}
}
end:
- closeSafely (sockfd);
+ close (sockfd);
return returnValue;
err:
/*When there is an error.*/
if ((fd = TEMP_FAILURE_RETRY(open( "/dev/tty", O_RDWR, 0))) == -1) {
/*We already have no tty control*/
- closeSafely(fd);
+ close(fd);
return 0;
}
return -1;
}
- if (closeSafely(fd) < 0) {
+ if (close(fd) < 0) {
syslog (LOG_ERR, "Closing tty failed: %m");
return -1;
}
if ((fd = TEMP_FAILURE_RETRY(open( "/dev/null", O_RDWR, 0))) == -1) {
- closeSafely(fd);
+ close(fd);
return -1;
}
if (TEMP_FAILURE_RETRY(dup2(fd,0)) < 0 ||
TEMP_FAILURE_RETRY(dup2(fd,1)) < 0 ||
TEMP_FAILURE_RETRY(dup2(fd,2)) < 0) {
- closeSafely(fd);
+ close(fd);
return -1;
}
- closeSafely(fd);
+ close(fd);
return 0;
}
err:
free(command);
- closeSafely(socket);
+ close(socket);
pthread_exit(0);
}
}
/*Close useless file descriptors. The child inherits copies of the parent's set of open file descriptors. See as well: CLOEXEC*/
- closeSafely (out[0]);
- closeSafely (out[1]);
- closeSafely (err[0]);
- closeSafely (err[1]);
- closeSafely (sockfd);
- closeSafely (socket);
+ close (out[0]);
+ close (out[1]);
+ close (err[0]);
+ close (err[1]);
+ close (sockfd);
+ close (socket);
args = create_args(command);
if (args == NULL) {
if (TEMP_FAILURE_RETRY(send(socket, buf, sizeof(struct tcpforkhdr), MSG_NOSIGNAL)) < 0)
syslog (LOG_INFO, "error while sending return status: %m");
- closeSafely (out[0]);
- closeSafely (out[1]);
- closeSafely (err[0]);
- closeSafely (err[1]);
+ close (out[0]);
+ close (out[1]);
+ close (err[0]);
+ close (err[1]);
return returnValue;
err:
childreturnstatus = -1;
}
- closeSafely (sockfd);
+ close (sockfd);
/*TODO: kill child processes, finish threads and release allocate memory*/
/* From http://www.cons.org/cracauer/sigint.html
* Since a shellscript may in turn be called by a shellscript, you need to make sure that you properly