summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-10-09 07:16:49 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:59:40 -0500
commitf9bac1dec23d2312d23d9605a39ce2819a10c1f3 (patch)
tree8b35f8d314a9056513522f1d1b55234819a23ca2 /source4
parent7b7619e0ba489329ced5f5159f97ba7da5aa3fa5 (diff)
downloadsamba-f9bac1dec23d2312d23d9605a39ce2819a10c1f3.tar.gz
samba-f9bac1dec23d2312d23d9605a39ce2819a10c1f3.tar.bz2
samba-f9bac1dec23d2312d23d9605a39ce2819a10c1f3.zip
r2872: got rid of a couple of unused (and horrible) functions
(This used to be commit 4bb410756df13c8c23d21b43c1186f3f9cb9f758)
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/system.c191
-rw-r--r--source4/lib/util_file.c53
2 files changed, 0 insertions, 244 deletions
diff --git a/source4/lib/system.c b/source4/lib/system.c
index 8d307caea3..e8a944d8f8 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.
****************************************************************************/
diff --git a/source4/lib/util_file.c b/source4/lib/util_file.c
index 51e6c7187e..c4f794db0e 100644
--- a/source4/lib/util_file.c
+++ b/source4/lib/util_file.c
@@ -273,44 +273,6 @@ char *fgets_slash(char *s2,int maxlen,XFILE *f)
}
-/****************************************************************************
-load from a pipe into memory
-****************************************************************************/
-char *file_pload(char *syscmd, size_t *size)
-{
- int fd, n;
- char *p, *tp;
- pstring buf;
- size_t total;
-
- fd = sys_popen(syscmd);
- if (fd == -1) return NULL;
-
- p = NULL;
- total = 0;
-
- while ((n = read(fd, buf, sizeof(buf))) > 0) {
- tp = Realloc(p, total + n + 1);
- if (!tp) {
- DEBUG(0,("file_pload: failed to expand buffer!\n"));
- close(fd);
- SAFE_FREE(p);
- return NULL;
- } else p = tp;
- memcpy(p+total, buf, n);
- total += n;
- }
- if (p) p[total] = 0;
-
- /* FIXME: Perhaps ought to check that the command completed
- * successfully (returned 0); if not the data may be
- * truncated. */
- sys_pclose(fd);
-
- if (size) *size = total;
-
- return p;
-}
/****************************************************************************
load a file into memory from a fd.
@@ -463,21 +425,6 @@ char **fd_lines_load(int fd, int *numlines)
/****************************************************************************
-load a pipe into memory and return an array of pointers to lines in the data
-must be freed with file_lines_free().
-****************************************************************************/
-char **file_lines_pload(char *syscmd, int *numlines)
-{
- char *p;
- size_t size;
-
- p = file_pload(syscmd, &size);
- if (!p) return NULL;
-
- return file_lines_parse(p, size, numlines);
-}
-
-/****************************************************************************
free lines loaded with file_lines_load
****************************************************************************/
void file_lines_free(char **lines)