GNU/Linux -f now works as -f -F instead

Jan Kratochvil jan.kratochvil at redhat.com
Thu Jul 3 15:43:54 UTC 2008


Hi,

option `-f' currently should not follow vfork() (only fork()).  There is an
option `-F' to follow specifically vfork().

But on GNU/Linux `-f' already follows even vfork() due to:
	int
	internal_fork(tcp)
	struct tcb *tcp;
	{
	#ifdef LINUX
		/* We do special magic with clone for any clone or fork.  */
		return internal_clone(tcp);
	#else

(1) Either GNU/Linux should no longer follow vfork() if given just `-f'.
    But this would break the behavior expected by the users and one would have
    to start using `-f -F' instead of the former common `-f'.

(2) or `-F' should get obsoleted and vfork() should get followed just by `-f'.
    [attached]

(3) or the man page should be updated to document it behaves differently on
    GNU/Linux vs. other platforms.  `-F' should print a warning on GNU/Linux.


(Thanks Dmitry L. for the review, going to follow-up.)


Regards,
Jan
-------------- next part --------------
2008-07-03  Jan Kratochvil  <jan.kratochvil at redhat.com>

	Trace even VFORK on -f on all the platforms.
	* strace.1 <-f>: Describe Linux catches new children immediately.
	<-F>: Make the option obsolete.  Move the SunOS VFORK comment to the
	`-f' option description.
	* defs.h (followvfork): Declaration removed.
	* strace.c (followvfork): Variable removed.
	(main) <-F>: Merge with the `-f' option.
	(trace): Make !FOLLOWVFORK unconditional.
	* process.c (internal_fork): Make !FOLLOWVFORK unconditional.

--- defs.h	20 May 2008 01:35:55 -0000	1.80
+++ defs.h	3 Jul 2008 14:48:17 -0000
@@ -434,7 +434,7 @@ struct xlat {
 
 extern struct tcb **tcbtab;
 extern int *qual_flags;
-extern int debug, followfork, followvfork;
+extern int debug, followfork;
 extern int dtime, cflag, xflag, qflag;
 extern int acolumn;
 extern unsigned int nprocs, tcbtabsize;
--- process.c	20 May 2008 01:11:56 -0000	1.110
+++ process.c	3 Jul 2008 14:48:18 -0000
@@ -989,8 +989,7 @@ struct tcb *tcp;
 #ifdef SYS_vfork
 	if (known_scno(tcp) == SYS_vfork) {
 		/* Attempt to make vfork into fork, which we can follow. */
-		if (!followvfork ||
-		    change_syscall(tcp, SYS_fork) < 0)
+		if (change_syscall(tcp, SYS_fork) < 0)
 			dont_follow = 1;
 	}
 #endif
--- strace.1	25 Apr 2006 07:48:03 -0000	1.15
+++ strace.1	3 Jul 2008 14:48:20 -0000
@@ -232,7 +232,9 @@ itself on the standard error.
 Trace child processes as they are created by currently traced
 processes as a result of the
 .BR fork (2)
-system call.  The new process is
+system call.
+.IP
+On non-Linux platforms the new process is
 attached to as soon as its pid is known (through the return value of
 .BR fork (2)
 in the parent process). This means that such children may run
@@ -240,13 +242,17 @@ uncontrolled for a while (especially in 
 .BR vfork (2)),
 until the parent is scheduled again to complete its
 .RB ( v ) fork (2)
-call.
+call.  On Linux the child is traced from its first instruction with no delay.
 If the parent process decides to
 .BR wait (2)
 for a child that is currently
 being traced, it is suspended until an appropriate child process either
 terminates or incurs a signal that would cause it to terminate (as
 determined from the child's current signal disposition).
+.IP
+On SunOS 4.x the tracing of
+.BR vfork s
+is accomplished with some dynamic linking trickery.
 .TP
 .B \-ff
 If the
@@ -258,16 +264,8 @@ where pid is the numeric process id of e
 This is incompatible with -c, since no per-process counts are kept.
 .TP
 .B \-F
-Attempt to follow
-.BR vfork s.
-(On SunOS 4.x, this is accomplished with
-some dynamic linking trickery.)
-Otherwise,
-.BR vfork s
-will
-not be followed even if
-.B \-f
-has been given.
+This option is now obsolete and it has the same functionality as
+.BR -f .
 .TP
 .B \-h
 Print the help summary.
--- strace.c	13 Nov 2007 08:12:12 -0000	1.85
+++ strace.c	3 Jul 2008 14:48:21 -0000
@@ -78,7 +78,7 @@
 #endif
 #endif
 
-int debug = 0, followfork = 0, followvfork = 0;
+int debug = 0, followfork = 0;
 int dtime = 0, cflag = 0, xflag = 0, qflag = 0;
 static int iflag = 0, interactive = 0, pflag_seen = 0, rflag = 0, tflag = 0;
 
@@ -659,12 +659,11 @@ main(int argc, char *argv[])
 		case 'd':
 			debug++;
 			break;
+		case 'F':
+			/* Obsoleted, acts as `-f'.  */
 		case 'f':
 			followfork++;
 			break;
-		case 'F':
-			followvfork++;
-			break;
 		case 'h':
 			usage(stdout, 0);
 			break;
@@ -2261,7 +2260,7 @@ trace()
 		/* Look up `pid' in our table. */
 		if ((tcp = pid2tcb(pid)) == NULL) {
 #ifdef LINUX
-			if (followfork || followvfork) {
+			if (followfork) {
 				/* This is needed to go with the CLONE_PTRACE
 				   changes in process.c/util.c: we might see
 				   the child's initial trap before we see the


More information about the Strace-devel mailing list