aboutsummaryrefslogtreecommitdiff
path: root/lib/libproc
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2017-12-03 16:50:16 +0000
committerMark Johnston <markj@FreeBSD.org>2017-12-03 16:50:16 +0000
commit5577b8a709c072fedc73dde9b3ad730699438bf7 (patch)
treed870e402f90efa1d1a9c5da33361bd7543eabdf5 /lib/libproc
parent4fbebc74723d70a180ea0bba901ca6d5eead6146 (diff)
downloadsrc-5577b8a709c072fedc73dde9b3ad730699438bf7.tar.gz
src-5577b8a709c072fedc73dde9b3ad730699438bf7.zip
Add an envp argument to proc_create().
This is needed to support dtrace's -x setenv option. MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=326498
Diffstat (limited to 'lib/libproc')
-rw-r--r--lib/libproc/Makefile2
-rw-r--r--lib/libproc/libproc.h4
-rw-r--r--lib/libproc/proc_create.c26
-rw-r--r--lib/libproc/tests/proc_test.c2
4 files changed, 17 insertions, 17 deletions
diff --git a/lib/libproc/Makefile b/lib/libproc/Makefile
index ed37b8acb3c0..cd78eb335ecc 100644
--- a/lib/libproc/Makefile
+++ b/lib/libproc/Makefile
@@ -37,7 +37,7 @@ CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libctf/common \
CFLAGS+= -DNO_CTF
.endif
-SHLIB_MAJOR= 4
+SHLIB_MAJOR= 5
MAN=
diff --git a/lib/libproc/libproc.h b/lib/libproc/libproc.h
index 7c17943b10f2..ef88f94c4752 100644
--- a/lib/libproc/libproc.h
+++ b/lib/libproc/libproc.h
@@ -142,8 +142,8 @@ int proc_addr2sym(struct proc_handle *, uintptr_t, char *, size_t, GElf_Sym *);
int proc_attach(pid_t pid, int flags, struct proc_handle **pphdl);
int proc_continue(struct proc_handle *);
int proc_clearflags(struct proc_handle *, int);
-int proc_create(const char *, char * const *, proc_child_func *, void *,
- struct proc_handle **);
+int proc_create(const char *, char * const *, char * const *,
+ proc_child_func *, void *, struct proc_handle **);
int proc_detach(struct proc_handle *, int);
int proc_getflags(struct proc_handle *);
int proc_name2sym(struct proc_handle *, const char *, const char *,
diff --git a/lib/libproc/proc_create.c b/lib/libproc/proc_create.c
index 21accb619c47..72e3a087b774 100644
--- a/lib/libproc/proc_create.c
+++ b/lib/libproc/proc_create.c
@@ -176,9 +176,10 @@ out:
}
int
-proc_create(const char *file, char * const *argv, proc_child_func *pcf,
- void *child_arg, struct proc_handle **pphdl)
+proc_create(const char *file, char * const *argv, char * const *envp,
+ proc_child_func *pcf, void *child_arg, struct proc_handle **pphdl)
{
+ extern char * const *environ;
struct proc_handle *phdl;
int error, status;
pid_t pid;
@@ -189,8 +190,7 @@ proc_create(const char *file, char * const *argv, proc_child_func *pcf,
error = 0;
phdl = NULL;
- /* Fork a new process. */
- if ((pid = vfork()) == -1)
+ if ((pid = fork()) == -1)
error = errno;
else if (pid == 0) {
/* The child expects to be traced. */
@@ -200,18 +200,14 @@ proc_create(const char *file, char * const *argv, proc_child_func *pcf,
if (pcf != NULL)
(*pcf)(child_arg);
- /* Execute the specified file: */
+ if (envp != NULL)
+ environ = envp;
+
execvp(file, argv);
- /* Couldn't execute the file. */
_exit(2);
/* NOTREACHED */
} else {
- /* The parent owns the process handle. */
- error = proc_init(pid, 0, PS_IDLE, &phdl);
- if (error != 0)
- goto bad;
-
/* Wait for the child process to stop. */
if (waitpid(pid, &status, WUNTRACED) == -1) {
error = errno;
@@ -221,11 +217,15 @@ proc_create(const char *file, char * const *argv, proc_child_func *pcf,
/* Check for an unexpected status. */
if (!WIFSTOPPED(status)) {
- error = EBUSY;
+ error = ENOENT;
DPRINTFX("ERROR: child process %d status 0x%x", pid, status);
goto bad;
}
- phdl->status = PS_STOP;
+
+ /* The parent owns the process handle. */
+ error = proc_init(pid, 0, PS_IDLE, &phdl);
+ if (error == 0)
+ phdl->status = PS_STOP;
bad:
if (error != 0 && phdl != NULL) {
diff --git a/lib/libproc/tests/proc_test.c b/lib/libproc/tests/proc_test.c
index 9ec99cd355c4..ca7afc73b7ae 100644
--- a/lib/libproc/tests/proc_test.c
+++ b/lib/libproc/tests/proc_test.c
@@ -65,7 +65,7 @@ start_prog(const struct atf_tc *tc, bool sig)
argv[1] = NULL;
}
- error = proc_create(argv[0], argv, NULL, NULL, &phdl);
+ error = proc_create(argv[0], argv, NULL, NULL, NULL, &phdl);
ATF_REQUIRE_EQ_MSG(error, 0, "failed to run '%s'", target_prog_file);
ATF_REQUIRE(phdl != NULL);