Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Jun 2008 06:54:10 GMT
From:      John Birrell <jb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 144347 for review
Message-ID:  <200806300654.m5U6sAvp000664@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=144347

Change 144347 by jb@freebsd3 on 2008/06/30 06:53:39

	Use vfork() rather than fork() because we intend to execvp() anyway.
	
	Add provision for the caller to specify a callback to be called 
	after vfork, but before execvp() so that the child process can do a
	few things.

Affected files ...

.. //depot/projects/dtrace/src/lib/libproc/libproc.h#6 edit
.. //depot/projects/dtrace/src/lib/libproc/proc_create.c#6 edit

Differences ...

==== //depot/projects/dtrace/src/lib/libproc/libproc.h#6 (text+ko) ====

@@ -33,6 +33,8 @@
 
 struct proc_handle;
 
+typedef void (*proc_child_func)(void *);
+
 /* Values returned by proc_state(). */
 #define PS_IDLE		1
 #define PS_STOP		2
@@ -55,7 +57,8 @@
 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 *, struct proc_handle **);
+int	proc_create(const char *, char * const *, proc_child_func *, void *,
+	    struct proc_handle **);
 int	proc_detach(struct proc_handle *);
 int	proc_getflags(struct proc_handle *);
 int	proc_name2sym(struct proc_handle *, const char *, const char *, GElf_Sym *);

==== //depot/projects/dtrace/src/lib/libproc/proc_create.c#6 (text+ko) ====

@@ -90,7 +90,8 @@
 }
 
 int
-proc_create(const char *file, char * const *argv, struct proc_handle **pphdl)
+proc_create(const char *file, char * const *argv, proc_child_func *pcf,
+    void *child_arg, struct proc_handle **pphdl)
 {
 	struct proc_handle *phdl;
 	struct kevent kev;
@@ -106,13 +107,16 @@
 		return (ENOMEM);
 
 	/* Fork a new process. */
-	if ((pid = fork()) == -1)
+	if ((pid = vfork()) == -1)
 		error = errno;
 	else if (pid == 0) {
 		/* The child expects to be traced. */
 		if (ptrace(PT_TRACE_ME, 0, 0, 0) != 0)
 			_exit(1);
 
+		if (pcf != NULL)
+			(*pcf)(child_arg);
+
 		/* Execute the specified file: */
 		execvp(file, argv);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200806300654.m5U6sAvp000664>