Functions | |
| 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
00082 {
00083 return di_exec_full (path, argv, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
00084 }
|
|
||||||||||||||||||||||||||||||||||||||||
|
execv like call
00042 {
00043 char line[MAXLINE];
00044 pid_t pid;
00045 int pipeout[2], pipeerr[2];
00046
00047 pipe (pipeout);
00048 pipe (pipeerr);
00049
00050 pid = fork ();
00051
00052 if (pid == 0)
00053 {
00054 dup2 (pipeout[1], 1);
00055 dup2 (pipeerr[1], 2);
00056 }
00057 if (pid <= 0)
00058 {
00059 close (pipeout[0]);
00060 close (pipeerr[0]);
00061 }
00062 close (pipeout[1]);
00063 close (pipeerr[1]);
00064
00065 if (pid == 0)
00066 {
00067 #if 0
00068 int i;
00069
00070 i = open ("/dev/null", O_RDONLY);
00071 dup2 (i, 0);
00072 close (i);
00073 #endif
00074
00075 if (child_prepare_handler)
00076 if (child_prepare_handler (pid, child_prepare_user_data))
00077 exit (255);
00078
00079 execv (path, (char *const *) argv);
00080 exit (127);
00081 }
00082 else if (pid < 0)
00083 {
00084 di_log (DI_LOG_LEVEL_WARNING, "fork failed");
00085 return -1;
00086 }
00087 else
00088 {
00089 int i, status = -1;
00090 struct pollfd fds[2] =
00091 {
00092 { pipeout[0], POLLIN, 0 },
00093 { pipeerr[0], POLLIN, 0 },
00094 };
00095 struct files
00096 {
00097 FILE *file;
00098 di_io_handler *handler;
00099 }
00100 files[] =
00101 {
00102 { fdopen (pipeout[0], "r"), stdout_handler },
00103 { fdopen (pipeerr[0], "r"), stderr_handler },
00104 };
00105
00106 fcntl (pipeout[0], F_SETFL, O_NONBLOCK);
00107 fcntl (pipeerr[0], F_SETFL, O_NONBLOCK);
00108
00109 if (parent_prepare_handler)
00110 if (parent_prepare_handler (pid, parent_prepare_user_data))
00111 {
00112 kill (pid, 9);
00113 goto cleanup;
00114 }
00115
00116 while (poll (fds, 2, -1) >= 0)
00117 {
00118 int exit = 0;
00119
00120 for (i = 0; i < 2; i++)
00121 {
00122 if (fds[i].revents & POLLIN)
00123 {
00124 while (fgets (line, sizeof (line), files[i].file) != NULL)
00125 if (files[i].handler)
00126 {
00127 size_t len = strlen (line);
00128 if (line[len - 1] == '\n')
00129 {
00130 line[len - 1] = '\0';
00131 len--;
00132 }
00133 files[i].handler (line, len, io_user_data);
00134 }
00135 exit = 1;
00136 }
00137 }
00138
00139 if (exit)
00140 continue;
00141
00142 for (i = 0; i < 2; i++)
00143 if (fds[i].revents & POLLHUP)
00144 exit = 1;
00145
00146 if (exit)
00147 break;
00148 }
00149
00150 if (!waitpid (pid, &status, 0))
00151 return -1;
00152
00153 cleanup:
00154 fclose (files[0].file); /* closes pipeout[0] */
00155 fclose (files[1].file); /* closes pipeerr[0] */
00156
00157 return status;
00158 }
00159
00160 return -1;
00161 }
|
|
|
mangle status like sh does it: * if signaled: 128 + signal * else return code
00194 {
00195 if (WIFEXITED (status))
00196 return WEXITSTATUS (status);
00197 if (WIFSIGNALED (status))
00198 return 128 + WTERMSIG (status);
00199 if (WIFSTOPPED (status))
00200 return 128 + WSTOPSIG (status);
00201 return status;
00202 }
|
|
|
system like call
00110 {
00111 return di_exec_shell_full (cmd, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
00112 }
|
|
||||||||||||||||||||||||||||||||||||
|
system like call
00164 {
00165 const char *const argv[] = { "sh", "-c", cmd, NULL };
00166 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);
00167 }
|
|
|
system like call with output via log
00122 {
00123 return di_exec_shell_full (cmd, di_exec_io_log, di_exec_io_log, NULL, NULL, NULL, NULL, NULL);
00124 }
|
|
|
00139 {
00140 return di_exec_shell_log (cmd);
00141 }
|
|
|
logs the output |
|
|
chdir to user_data
|
|
|
chroot to user_data
|
1.3.5