Functions | |
int | di_exec_env_full (const char *path, const char *const argv[], const char *const envp[], di_io_handler *stdout_handler, di_io_handler *stderr_handler, void *io_user_data, di_process_handler *parent_prepare_handler, void *parent_prepare_user_data, di_process_handler *child_prepare_handler, void *child_prepare_user_data) |
int | di_exec_env (const char *path, const char *const argv[], const char *const envp[]) |
int | di_exec_full (const char *path, const char *const argv[], di_io_handler *stdout_handler, di_io_handler *stderr_handler, void *io_user_data, di_process_handler *parent_prepare_handler, void *parent_prepare_user_data, di_process_handler *child_prepare_handler, void *child_prepare_user_data) |
int | di_exec (const char *path, const char *const argv[]) |
int | di_exec_shell_full (const char *const cmd, di_io_handler *stdout_handler, di_io_handler *stderr_handler, void *io_user_data, di_process_handler *parent_prepare_handler, void *parent_prepare_user_data, di_process_handler *child_prepare_handler, void *child_prepare_user_data) |
int | di_exec_shell (const char *const cmd) |
int | di_exec_shell_log (const char *const cmd) |
int | di_exec_mangle_status (int status) |
int | di_execlog (const char *const cmd) __attribute__((deprecated)) |
Variables | |
di_io_handler | di_exec_io_log |
di_process_handler | di_exec_prepare_chdir |
di_process_handler | di_exec_prepare_chroot |
|
execv like call
00114 { 00115 return di_exec_full (path, argv, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 00116 }
|
|
execve like call
00084 { 00085 return di_exec_env_full (path, argv, envp, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 00086 }
|
|
execve like call
00042 { 00043 char line[MAXLINE]; 00044 pid_t pid; 00045 int fds[4] = { -1, }, mode = 0, pipes = 0, i; 00046 00047 if (stdout_handler) 00048 { 00049 mode += 1; 00050 pipes++; 00051 } 00052 if (stderr_handler) 00053 { 00054 mode += 2; 00055 pipes++; 00056 } 00057 00058 for (i = 0; i < pipes; i++) 00059 pipe (&fds[i * 2]); 00060 00061 pid = fork (); 00062 00063 if (pid <= 0) 00064 { 00065 for (i = 0; i < pipes; i++) 00066 close (fds[i * 2]); 00067 } 00068 00069 if (pid == 0) 00070 { 00071 int temp, realfds[3] = 00072 { 00073 0, 00074 fds[1], 00075 fds[3] 00076 }; 00077 00078 temp = open ("/dev/null", O_RDWR); 00079 00080 switch (mode) 00081 { 00082 case 0: 00083 realfds[1] = temp; 00084 realfds[2] = temp; 00085 break; 00086 case 2: 00087 realfds[1] = temp; 00088 realfds[2] = fds[1]; 00089 break; 00090 case 1: 00091 realfds[2] = fds[1]; 00092 break; 00093 } 00094 00095 for (i = 1; i <= 2; i++) 00096 dup2 (realfds[i], i); 00097 00098 close (temp); 00099 } 00100 00101 for (i = 0; i < pipes; i++) 00102 close (fds[i * 2 + 1]); 00103 00104 if (pid == 0) 00105 { 00106 if (child_prepare_handler) 00107 if (child_prepare_handler (pid, child_prepare_user_data)) 00108 exit (255); 00109 00110 if (envp) 00111 execve (path, (char *const *) argv, (char *const *) envp); 00112 else 00113 execv (path, (char *const *) argv); 00114 exit (127); 00115 } 00116 else if (pid < 0) 00117 { 00118 di_log (DI_LOG_LEVEL_WARNING, "fork failed"); 00119 return -1; 00120 } 00121 else 00122 { 00123 int status = -1; 00124 struct pollfd pollfds[pipes]; 00125 struct files 00126 { 00127 FILE *file; 00128 di_io_handler *handler; 00129 } 00130 files[pipes]; 00131 00132 for (i = 0; i < pipes; i++) 00133 { 00134 fcntl (fds[i * 2], F_SETFL, O_NONBLOCK); 00135 files[i].file = fdopen (fds[i * 2], "r"); 00136 pollfds[i].fd = fds[i * 2]; 00137 pollfds[i].events = POLLIN; 00138 } 00139 00140 switch (mode) 00141 { 00142 case 2: 00143 files[0].handler = stderr_handler; 00144 break; 00145 case 3: 00146 files[1].handler = stderr_handler; 00147 case 1: 00148 files[0].handler = stdout_handler; 00149 break; 00150 } 00151 00152 if (parent_prepare_handler && parent_prepare_handler (pid, parent_prepare_user_data)) 00153 kill (pid, 9); 00154 else if (pipes) 00155 while (poll (pollfds, pipes, -1) >= 0) 00156 { 00157 bool exit = false; 00158 00159 for (i = 0; i < pipes; i++) 00160 { 00161 if (pollfds[i].revents & POLLIN) 00162 { 00163 while (fgets (line, sizeof (line), files[i].file) != NULL) 00164 { 00165 size_t len = strlen (line); 00166 if (line[len - 1] == '\n') 00167 { 00168 line[len - 1] = '\0'; 00169 len--; 00170 } 00171 files[i].handler (line, len, io_user_data); 00172 } 00173 exit = true; 00174 } 00175 } 00176 00177 if (exit) 00178 continue; 00179 00180 for (i = 0; i < pipes; i++) 00181 if (pollfds[i].revents & POLLHUP) 00182 exit = true; 00183 00184 if (exit) 00185 break; 00186 } 00187 00188 if (!waitpid (pid, &status, 0)) 00189 return -1; 00190 00191 for (i = 0; i < pipes; i++) 00192 fclose (files[i].file); /* closes fds[i * 2] */ 00193 00194 return status; 00195 } 00196 00197 return -1; 00198 }
|
|
execv like call
00201 { 00202 return di_exec_env_full (path, argv, NULL, stdout_handler, stderr_handler, io_user_data, parent_prepare_handler, parent_prepare_user_data, child_prepare_handler, child_prepare_user_data); 00203 }
|
|
mangle status like sh does it: * if signaled: 128 + signal * else return code 00236 { 00237 if (WIFEXITED (status)) 00238 return WEXITSTATUS (status); 00239 if (WIFSIGNALED (status)) 00240 return 128 + WTERMSIG (status); 00241 if (WIFSTOPPED (status)) 00242 return 128 + WSTOPSIG (status); 00243 return status; 00244 }
|
|
system like call
00142 { 00143 return di_exec_shell_full (cmd, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 00144 }
|
|
system like call
00206 { 00207 const char *const argv[] = { "sh", "-c", cmd, NULL }; 00208 return di_exec_full ("/bin/sh", argv, stdout_handler, stderr_handler, io_user_data, parent_prepare_handler, parent_prepare_user_data, child_prepare_handler, child_prepare_user_data); 00209 }
|
|
system like call with output via log
00154 { 00155 return di_exec_shell_full (cmd, di_exec_io_log, NULL, NULL, NULL, NULL, NULL, NULL); 00156 }
|
|
00171 { 00172 return di_exec_shell_log (cmd); 00173 }
|
|
logs the output |
|
chdir to user_data
|
|
chroot to user_data
|