There might be file descriptors open by things like pam_systemd that
we do not want to keep open for the child process.
Original idea by: Jakub Jelen <jjelen@redhat.com>
*/
{
char *shell = env_get("SHELL", jobenv);
+ int fd, fdmax = getdtablesize();
+
+ /* close all unwanted open file descriptors */
+ for(fd = STDERR + 1; fd < fdmax; fd++) {
+ close(fd);
+ }
#if DEBUGGING
if (DebugFlags & DTEST) {
ssize_t out;
char buf[PIPE_BUF];
struct sigaction sa;
+ int fd;
#ifdef __GNUC__
(void) &iop; /* Avoid fork clobbering */
sa.sa_handler = SIG_DFL;
sigaction(SIGPIPE, &sa, NULL);
+ /* close all unwanted open file descriptors */
+ for (fd = STDERR + 1; fd < fds; fd++) {
+ close(fd);
+ }
+
if (cron_change_user_permanently(pw, pw->pw_dir) != 0)
_exit(2);