svn commit: r326498 - in head: . cddl/contrib/opensolaris/lib/libdtrace/common lib/libproc lib/libproc/tests
Mark Johnston
markj at FreeBSD.org
Sun Dec 3 16:50:17 UTC 2017
Author: markj
Date: Sun Dec 3 16:50:16 2017
New Revision: 326498
URL: https://svnweb.freebsd.org/changeset/base/326498
Log:
Add an envp argument to proc_create().
This is needed to support dtrace's -x setenv option.
MFC after: 2 weeks
Modified:
head/ObsoleteFiles.inc
head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_proc.c
head/lib/libproc/Makefile
head/lib/libproc/libproc.h
head/lib/libproc/proc_create.c
head/lib/libproc/tests/proc_test.c
Modified: head/ObsoleteFiles.inc
==============================================================================
--- head/ObsoleteFiles.inc Sun Dec 3 13:52:35 2017 (r326497)
+++ head/ObsoleteFiles.inc Sun Dec 3 16:50:16 2017 (r326498)
@@ -38,6 +38,9 @@
# xargs -n1 | sort | uniq -d;
# done
+# 20171203: libproc version bump
+OLD_LIBS+=usr/lib/libproc.so.4
+OLD_LIBS+=usr/lib32/libproc.so.4
# 20171203: new clang import which bumps version from 5.0.0 to 5.0.1.
OLD_FILES+=usr/lib/clang/5.0.0/include/sanitizer/allocator_interface.h
OLD_FILES+=usr/lib/clang/5.0.0/include/sanitizer/asan_interface.h
Modified: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_proc.c
==============================================================================
--- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_proc.c Sun Dec 3 13:52:35 2017 (r326497)
+++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_proc.c Sun Dec 3 16:50:16 2017 (r326498)
@@ -967,7 +967,7 @@ dt_proc_create(dtrace_hdl_t *dtp, const char *file, ch
#ifdef illumos
if ((dpr->dpr_proc = Pcreate(file, argv, &err, NULL, 0)) == NULL) {
#else
- if ((err = proc_create(file, argv, pcf, child_arg,
+ if ((err = proc_create(file, argv, NULL, pcf, child_arg,
&dpr->dpr_proc)) != 0) {
#endif
return (dt_proc_error(dtp, dpr,
Modified: head/lib/libproc/Makefile
==============================================================================
--- head/lib/libproc/Makefile Sun Dec 3 13:52:35 2017 (r326497)
+++ head/lib/libproc/Makefile Sun Dec 3 16:50:16 2017 (r326498)
@@ -37,7 +37,7 @@ CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libc
CFLAGS+= -DNO_CTF
.endif
-SHLIB_MAJOR= 4
+SHLIB_MAJOR= 5
MAN=
Modified: head/lib/libproc/libproc.h
==============================================================================
--- head/lib/libproc/libproc.h Sun Dec 3 13:52:35 2017 (r326497)
+++ head/lib/libproc/libproc.h Sun Dec 3 16:50:16 2017 (r326498)
@@ -142,8 +142,8 @@ int proc_addr2sym(struct proc_handle *, uintptr_t, cha
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 *,
Modified: head/lib/libproc/proc_create.c
==============================================================================
--- head/lib/libproc/proc_create.c Sun Dec 3 13:52:35 2017 (r326497)
+++ head/lib/libproc/proc_create.c Sun Dec 3 16:50:16 2017 (r326498)
@@ -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
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
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
/* 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) {
Modified: head/lib/libproc/tests/proc_test.c
==============================================================================
--- head/lib/libproc/tests/proc_test.c Sun Dec 3 13:52:35 2017 (r326497)
+++ head/lib/libproc/tests/proc_test.c Sun Dec 3 16:50:16 2017 (r326498)
@@ -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);
More information about the svn-src-all
mailing list