DragonFly BSD
DragonFly submit List (threaded) for 2005-02
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Patch to execve


From: "Kevin M. Kilbride" <kmk@xxxxxxx>
Date: Thu, 24 Feb 2005 20:58:27 -0800

Patches evecve and friends in preparation for my WARNS6 patch of init, which follows. I didn't trace the implications of this patch very far back, but from what I can tell execve simply takes the argument strings passed to it, stuffs them into a struct, and immediately copies the data into a new address space. Given what ordinarily happens to the supplied data after calling execve, I didn't expect any real difficulties. Someone more familiar with the facility involved could say for sure.

The formal interface is changed from:

execve(const char *path, char *const argv[], char *const envp[])

to the much more useful guarantee of:

execve(const char *path, const char *const argv[], const char *const envp[])

I'm not at all certain why it was originally chosen to make only the pointers constant, when it is the string data itself that provides the more important guarantee, but I couldn't find any reason for the decision. If there is a problem, I will have to rethink my init patch, but if this works the rest is relatively easy....

----------------------
diff -u lib/libc_r/uthread/uthread_execve.c.orig lib/libc_r/uthread/uthread_execve.c
--- lib/libc_r/uthread/uthread_execve.c.orig 2005-02-24 05:39:33.000000000 -0800
+++ lib/libc_r/uthread/uthread_execve.c 2005-02-24 05:40:03.000000000 -0800
@@ -39,7 +39,7 @@
#include "pthread_private.h"


int
-_execve(const char *name, char *const * argv, char *const * envp)
+_execve(const char *name, const char *const * argv, const char *const * envp)
{
struct pthread *curthread = _get_curthread();
int flags;
diff -u lib/libc_r/uthread/pthread_private.h.orig lib/libc_r/uthread/pthread_private.h
--- lib/libc_r/uthread/pthread_private.h.orig 2005-02-24 05:38:51.000000000 -0800
+++ lib/libc_r/uthread/pthread_private.h 2005-02-24 05:39:14.000000000 -0800
@@ -1335,7 +1335,7 @@
int __sys_close(int);
int __sys_dup(int);
int __sys_dup2(int, int);
-int __sys_execve(const char *, char * const *, char * const *);
+int __sys_execve(const char *, const char * const *, const char * const *);
int __sys_fchown(int, uid_t, gid_t);
pid_t __sys_fork(void);
long __sys_fpathconf(int, int);
diff -u lib/libc/sys/execve.2.orig lib/libc/sys/execve.2
--- lib/libc/sys/execve.2.orig 2005-02-24 05:52:08.000000000 -0800
+++ lib/libc/sys/execve.2 2005-02-24 05:52:21.000000000 -0800
@@ -44,7 +44,7 @@
.Sh SYNOPSIS
.In unistd.h
.Ft int
-.Fn execve "const char *path" "char *const argv[]" "char *const envp[]"
+.Fn execve "const char *path" "const char *const argv[]" "const char *const envp[]"
.Sh DESCRIPTION
.Fn Execve
transforms the calling process into a new process.
diff -u lib/libc/gen/exec.3.orig lib/libc/gen/exec.3
--- lib/libc/gen/exec.3.orig 2005-02-24 05:55:03.000000000 -0800
+++ lib/libc/gen/exec.3 2005-02-24 05:55:24.000000000 -0800
@@ -56,11 +56,11 @@
.Ft int
.Fn execle "const char *path" "const char *arg" ...
.Ft int
-.Fn exect "const char *path" "char *const argv[]" "char *const envp[]"
+.Fn exect "const char *path" "const char *const argv[]" "const char *const envp[]"
.Ft int
-.Fn execv "const char *path" "char *const argv[]"
+.Fn execv "const char *path" "const char *const argv[]"
.Ft int
-.Fn execvp "const char *file" "char *const argv[]"
+.Fn execvp "const char *file" "const char *const argv[]"
.Sh DESCRIPTION
The
.Nm exec
diff -u lib/libc/gen/exec.c.orig lib/libc/gen/exec.c
--- lib/libc/gen/exec.c.orig 2005-02-24 01:17:16.000000000 -0800
+++ lib/libc/gen/exec.c 2005-02-24 05:54:30.000000000 -0800
@@ -136,7 +136,7 @@
int
execv(name, argv)
const char *name;
- char * const *argv;
+ const char * const *argv;
{
(void)_execve(name, argv, environ);
return (-1);
@@ -145,7 +145,7 @@
int
execvp(name, argv)
const char *name;
- char * const *argv;
+ const char * const *argv;
{
char **memp;
int cnt, lp, ln;
diff -u lib/libthread_xu/thread/thr_private.h.orig lib/libthread_xu/thread/thr_private.h
--- lib/libthread_xu/thread/thr_private.h.orig 2005-02-24 05:50:04.000000000 -0800
+++ lib/libthread_xu/thread/thr_private.h 2005-02-24 05:50:19.000000000 -0800
@@ -804,7 +804,7 @@
/* #include <unistd.h> */
#ifdef _UNISTD_H_
int __sys_close(int);
-int __sys_execve(const char *, char * const *, char * const *);
+int __sys_execve(const char *, const char * const *, const char * const *);
int __sys_fork(void);
int __sys_fsync(int);
pid_t __sys_getpid(void);





[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]