From owner-freebsd-current@FreeBSD.ORG Mon Dec 15 13:34:16 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7A86C16A4CE; Mon, 15 Dec 2003 13:34:16 -0800 (PST) Received: from schlepper.zs64.net (schlepper.zs64.net [212.12.50.230]) by mx1.FreeBSD.org (Postfix) with ESMTP id C17C943D45; Mon, 15 Dec 2003 13:34:02 -0800 (PST) (envelope-from cracauer@schlepper.zs64.net) Received: from schlepper.zs64.net (schlepper [212.12.50.230]) by schlepper.zs64.net (8.12.10/8.11.1) with ESMTP id hBFLY1ZR068458; Mon, 15 Dec 2003 22:34:01 +0100 (CET) (envelope-from cracauer@schlepper.zs64.net) Received: (from cracauer@localhost) by schlepper.zs64.net (8.12.10/8.12.9/Submit) id hBFLY104068457; Mon, 15 Dec 2003 16:34:01 -0500 (EST) Date: Mon, 15 Dec 2003 16:34:01 -0500 From: Martin Cracauer To: Don Lewis Message-ID: <20031215163401.A68402@cons.org> References: <20031215161928.A68001@cons.org> <200312152128.hBFLSoeF068231@gw.catspoiler.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200312152128.hBFLSoeF068231@gw.catspoiler.org>; from truckman@FreeBSD.org on Mon, Dec 15, 2003 at 01:28:50PM -0800 cc: cracauer@FreeBSD.org cc: cracauer@cons.org cc: current@FreeBSD.org cc: bland@mail.ru Subject: Re: truss issue X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Dec 2003 21:34:16 -0000 Don Lewis wrote on Mon, Dec 15, 2003 at 01:28:50PM -0800: > On 15 Dec, Martin Cracauer wrote: > > Don Lewis wrote on Mon, Dec 15, 2003 at 01:13:58PM -0800: > > >> Hmn, I wonder if it would be cleaner to exec() the executable to be > >> traced in the parent process and run truss in the child ... > > > > I think I misunderstand. The parent is usually your login shell, you > > don't want that one to exec() anything. > > If you type "truss foo" at the shell prompt, the shell will fork and > exec truss, which forks and execs foo. When truss forks, the child > process is the one that execs foo, and the parent process watches what > the child process does. My suggestion is to swap the roles of the > parent and child truss processes. The parent truss process would be the > one that calls exec(), and the child process would be the one doing the > monitoring. When the process being traced exits, the shell would > automagically get the correct exit status. Ah, OK. That would also have the advantage that the pid that the fork() in the starting process gets will continue to stay correct for the child it expects. E.g. truss foo & pid=$! dosomethingwith $pid pid will point to the actual process and not foo, so you can safely insert a truss prefix where you want. I've seen quite some things blow up when breaking the assumption that the child is directly what is expected, usually by people trying to be cute and sneak in a shellscript wrapper around a real program and not exec'ing the wrapper away. Martin -- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Martin Cracauer http://www.cons.org/cracauer/ No warranty. This email is probably produced by one of my cats stepping on the keys. No, I don't have an infinite number of cats.