aboutsummaryrefslogtreecommitdiff
path: root/hurd
diff options
context:
space:
mode:
Diffstat (limited to 'hurd')
-rw-r--r--hurd/hurdexec.c43
-rw-r--r--hurd/hurdstartup.c46
2 files changed, 17 insertions, 72 deletions
diff --git a/hurd/hurdexec.c b/hurd/hurdexec.c
index 149e95c..7893c91 100644
--- a/hurd/hurdexec.c
+++ b/hurd/hurdexec.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -25,6 +25,7 @@ Cambridge, MA 02139, USA. */
#include <hurd.h>
#include <hurd/fd.h>
#include <hurd/signal.h>
+#include <argz.h>
/* Overlay TASK, executing FILE with arguments ARGV and environment ENVP.
If TASK == mach_task_self (), some ports are dealloc'd by the exec server.
@@ -47,36 +48,10 @@ _hurd_exec (task_t task, file_t file,
struct hurd_sigstate *ss;
mach_port_t *please_dealloc, *pdp;
-
- /* Pack the arguments into an array with nulls separating the elements. */
- argslen = 0;
- if (argv != NULL)
- {
- p = argv;
- while (*p != NULL)
- argslen += strlen (*p++) + 1;
- args = __alloca (argslen);
- ap = args;
- for (p = argv; *p != NULL; ++p)
- ap = __memccpy (ap, *p, '\0', ULONG_MAX);
- }
- else
- args = NULL;
-
- /* Pack the environment into an array with nulls separating elements. */
- envlen = 0;
- if (envp != NULL)
- {
- p = envp;
- while (*p != NULL)
- envlen += strlen (*p++) + 1;
- env = __alloca (envlen);
- ap = env;
- for (p = envp; *p != NULL; ++p)
- ap = __memccpy (ap, *p, '\0', ULONG_MAX);
- }
- else
- env = NULL;
+ if (err = __argz_create (argv, &args, &argslen))
+ return err;
+ if (err = __argz_create (envp, &env, &envlen))
+ goto outargs;
/* Load up the ports to give to the new program. */
for (i = 0; i < _hurd_nports; ++i)
@@ -88,7 +63,7 @@ _hurd_exec (task_t task, file_t file,
{
while (--i > 0)
_hurd_port_free (&_hurd_ports[i], &ulink_ports[i], ports[i]);
- return err;
+ goto outenv;
}
}
else
@@ -254,5 +229,9 @@ _hurd_exec (task_t task, file_t file,
__msg_sig_post (_hurd_msgport, 0, __mach_task_self ());
}
+ outargs:
+ free (args);
+ outenv:
+ free (env);
return err;
}
diff --git a/hurd/hurdstartup.c b/hurd/hurdstartup.c
index ca44737..17a7705 100644
--- a/hurd/hurdstartup.c
+++ b/hurd/hurdstartup.c
@@ -1,5 +1,5 @@
/* Initial program startup for running under the GNU Hurd.
-Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+Copyright (C) 1991, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -30,6 +30,7 @@ Cambridge, MA 02139, USA. */
#include "set-hooks.h"
#include "hurdmalloc.h" /* XXX */
#include "hurdstartup.h"
+#include <argz.h>
mach_port_t *_hurd_init_dtable;
mach_msg_type_number_t _hurd_init_dtablesize;
@@ -45,9 +46,6 @@ unsigned long int *__hurd_sigthread_variables;
extern void __mach_init (void);
-int _hurd_split_args (char *, size_t, char **);
-
-
/* Entry point. This is the first thing in the text segment.
The exec server started the initial thread in our task with this spot the
@@ -125,9 +123,9 @@ _hurd_startup (void **argptr, void (*main) (int *data))
arguments and environment into vectors of pointers to strings. */
/* Count up the arguments so we can allocate ARGV. */
- argc = _hurd_split_args (args, argslen, NULL);
+ argc = __argz_count (args, argslen);
/* Count up the environment variables so we can allocate ENVP. */
- envc = _hurd_split_args (env, envlen, NULL);
+ envc = __argz_count (env, envlen);
/* There were some arguments. Allocate space for the vectors of
pointers and fill them in. We allocate the space for the
@@ -138,11 +136,11 @@ _hurd_startup (void **argptr, void (*main) (int *data))
sizeof (struct hurd_startup_data));
*argcptr = argc;
argv = (void *) (argcptr + 1);
- _hurd_split_args (args, argslen, argv);
+ __argz_extract (args, argslen, argv);
/* There was some environment. */
envp = &argv[argc + 1];
- _hurd_split_args (env, envlen, envp);
+ __argz_extract (env, envlen, envp);
}
if (err || in_bootstrap == MACH_PORT_NULL)
@@ -197,35 +195,3 @@ _hurd_startup (void **argptr, void (*main) (int *data))
LOSE;
abort ();
}
-
-/* Split ARGSLEN bytes at ARGS into words, breaking at NUL characters. If
- ARGV is not a null pointer, store a pointer to the start of each word in
- ARGV[n], and null-terminate ARGV. Return the number of words split. */
-
-int
-_hurd_split_args (char *args, size_t argslen, char **argv)
-{
- char *p = args;
- size_t n = argslen;
- int argc = 0;
-
- while (n > 0)
- {
- char *end = memchr (p, '\0', n);
-
- if (argv)
- argv[argc] = p;
- ++argc;
-
- if (end == NULL)
- /* The last argument is unterminated. */
- break;
-
- n -= end + 1 - p;
- p = end + 1;
- }
-
- if (argv)
- argv[argc] = NULL;
- return argc;
-}