diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-10-09 07:16:49 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:59:40 -0500 |
commit | f9bac1dec23d2312d23d9605a39ce2819a10c1f3 (patch) | |
tree | 8b35f8d314a9056513522f1d1b55234819a23ca2 /source4/lib/system.c | |
parent | 7b7619e0ba489329ced5f5159f97ba7da5aa3fa5 (diff) | |
download | samba-f9bac1dec23d2312d23d9605a39ce2819a10c1f3.tar.gz samba-f9bac1dec23d2312d23d9605a39ce2819a10c1f3.tar.xz samba-f9bac1dec23d2312d23d9605a39ce2819a10c1f3.zip |
r2872: got rid of a couple of unused (and horrible) functions
(This used to be commit 4bb410756df13c8c23d21b43c1186f3f9cb9f758)
Diffstat (limited to 'source4/lib/system.c')
-rw-r--r-- | source4/lib/system.c | 191 |
1 files changed, 0 insertions, 191 deletions
diff --git a/source4/lib/system.c b/source4/lib/system.c index 8d307caea3b..e8a944d8f8d 100644 --- a/source4/lib/system.c +++ b/source4/lib/system.c @@ -671,197 +671,6 @@ struct group *sys_getgrgid(gid_t gid) /************************************************************************** - Extract a command into an arg list. Uses a static pstring for storage. - Caller frees returned arg list (which contains pointers into the static pstring). -****************************************************************************/ - -static char **extract_args(const char *command) -{ - static pstring trunc_cmd; - char *ptr; - int argcl; - char **argl = NULL; - int i; - - pstrcpy(trunc_cmd, command); - - if(!(ptr = strtok(trunc_cmd, " \t"))) { - errno = EINVAL; - return NULL; - } - - /* - * Count the args. - */ - - for( argcl = 1; ptr; ptr = strtok(NULL, " \t")) - argcl++; - - if((argl = (char **)malloc((argcl + 1) * sizeof(char *))) == NULL) - return NULL; - - /* - * Now do the extraction. - */ - - pstrcpy(trunc_cmd, command); - - ptr = strtok(trunc_cmd, " \t"); - i = 0; - argl[i++] = ptr; - - while((ptr = strtok(NULL, " \t")) != NULL) - argl[i++] = ptr; - - argl[i++] = NULL; - return argl; -} - -/************************************************************************** - Wrapper for popen. Safer as it doesn't search a path. - Modified from the glibc sources. - modified by tridge to return a file descriptor. We must kick our FILE* habit -****************************************************************************/ - -typedef struct _popen_list -{ - int fd; - pid_t child_pid; - struct _popen_list *next; -} popen_list; - -static popen_list *popen_chain; - -int sys_popen(const char *command) -{ - int parent_end, child_end; - int pipe_fds[2]; - popen_list *entry = NULL; - char **argl = NULL; - - if (pipe(pipe_fds) < 0) - return -1; - - parent_end = pipe_fds[0]; - child_end = pipe_fds[1]; - - if (!*command) { - errno = EINVAL; - goto err_exit; - } - - if((entry = (popen_list *)malloc(sizeof(popen_list))) == NULL) - goto err_exit; - - ZERO_STRUCTP(entry); - - /* - * Extract the command and args into a NULL terminated array. - */ - - if(!(argl = extract_args(command))) - goto err_exit; - - entry->child_pid = fork(); - - if (entry->child_pid == -1) { - goto err_exit; - } - - if (entry->child_pid == 0) { - - /* - * Child ! - */ - - int child_std_end = STDOUT_FILENO; - popen_list *p; - - close(parent_end); - if (child_end != child_std_end) { - dup2 (child_end, child_std_end); - close (child_end); - } - - /* - * POSIX.2: "popen() shall ensure that any streams from previous - * popen() calls that remain open in the parent process are closed - * in the new child process." - */ - - for (p = popen_chain; p; p = p->next) - close(p->fd); - - execv(argl[0], argl); - _exit (127); - } - - /* - * Parent. - */ - - close (child_end); - SAFE_FREE(argl); - - /* Link into popen_chain. */ - entry->next = popen_chain; - popen_chain = entry; - entry->fd = parent_end; - - return entry->fd; - -err_exit: - - SAFE_FREE(entry); - SAFE_FREE(argl); - close(pipe_fds[0]); - close(pipe_fds[1]); - return -1; -} - -/************************************************************************** - Wrapper for pclose. Modified from the glibc sources. -****************************************************************************/ - -int sys_pclose(int fd) -{ - int wstatus; - popen_list **ptr = &popen_chain; - popen_list *entry = NULL; - pid_t wait_pid; - int status = -1; - - /* Unlink from popen_chain. */ - for ( ; *ptr != NULL; ptr = &(*ptr)->next) { - if ((*ptr)->fd == fd) { - entry = *ptr; - *ptr = (*ptr)->next; - status = 0; - break; - } - } - - if (status < 0 || close(entry->fd) < 0) - return -1; - - /* - * As Samba is catching and eating child process - * exits we don't really care about the child exit - * code, a -1 with errno = ECHILD will do fine for us. - */ - - do { - wait_pid = sys_waitpid (entry->child_pid, &wstatus, 0); - } while (wait_pid == -1 && errno == EINTR); - - SAFE_FREE(entry); - - if (wait_pid == -1) - return -1; - return wstatus; -} - -/************************************************************************** Wrappers for dlopen, dlsym, dlclose. ****************************************************************************/ |