22 #include <sys/types.h> 23 #include <sys/socket.h> 24 #include <sys/resource.h> 32 #define RLIM_INFINITY (1024*1024*1024) 36 openvas_popen4 (
const char *cmd,
char *
const args[], pid_t * ppid,
int inice)
45 for (i = 0; args[i] != NULL; i++)
51 if (socketpair (AF_UNIX, SOCK_STREAM, 0, pipes) < 0)
53 perror (
"socketpair");
57 if ((son = fork ()) < 0)
75 if (nice (inice) < 0 && errno)
80 if (setrlimit (RLIMIT_DATA, &rl) < 0)
81 perror (
"RLIMIT_DATA");
82 if (setrlimit (RLIMIT_RSS, &rl) < 0)
83 perror (
"RLIMIT_RSS");
84 if (setrlimit (RLIMIT_STACK, &rl) < 0)
85 perror (
"RLIMIT_STACK");
88 if ((fd = open (
"/dev/null", O_RDONLY)) < 0)
94 if (dup2 (fd, STDIN_FILENO) < 0)
101 close (STDOUT_FILENO);
102 close (STDERR_FILENO);
103 if (dup2 (pipes[1], STDOUT_FILENO) < 0 || dup2 (pipes[1], STDERR_FILENO) < 0)
112 for (i = 3; i < 256; i++)
116 signal (SIGTERM, _exit);
117 signal (SIGPIPE, _exit);
123 if ((fp = fdopen (pipes[0],
"r")) == NULL)
139 if (waitpid (pid, NULL, WNOHANG) == 0)
140 if (kill (pid, SIGTERM) >= 0)
141 if (waitpid (pid, NULL, WNOHANG) == 0)
144 (void) kill (pid, SIGKILL);
145 (void) waitpid (pid, NULL, WNOHANG);
FILE * openvas_popen4(const char *cmd, char *const args[], pid_t *ppid, int inice)
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
int openvas_pclose(FILE *fp, pid_t pid)