From owner-freebsd-dtrace@FreeBSD.ORG Wed Jun 4 02:28:17 2014 Return-Path: Delivered-To: freebsd-dtrace@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id AAEFDF5A for ; Wed, 4 Jun 2014 02:28:17 +0000 (UTC) Received: from mail-vc0-x233.google.com (mail-vc0-x233.google.com [IPv6:2607:f8b0:400c:c03::233]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6B2162505 for ; Wed, 4 Jun 2014 02:28:17 +0000 (UTC) Received: by mail-vc0-f179.google.com with SMTP id ij19so3397681vcb.10 for ; Tue, 03 Jun 2014 19:28:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=u4Xu82pVbqZZLrpGOqkgOz7N97bLN8wYmbQ7xoNl9WM=; b=K3y0DvZCLmk0q4C8bKmg8JFrK7Oryu7ik3DpwOdX01I2x9mQlYO2iqAFEPBRQ7M9bV 0PdiuVU+ew5oU31KH7de7xxpMs6tRfDTZZxGuvFehkkRgdu/asr+xeqPd2+X3R4GnU1c 7LWi+6TMmJWGq25n6mZQUsmG3O0pRxlc9bqSOoW8hGKLHeM9yPbSVTy8VdtvGJ8ET92f vIuOEQ0I38cUFHjFlnfO3VGcH6HviwsjAR+k0BCK8kaC7RsF7JjjajZjoAVDHC9kUvvy VEiyA1mnX4vxCxKunREMzS7hPU3h+9ZJM8MkoD24rjbWiwS0g9oH04/E9vd6u89a05xE VrfQ== MIME-Version: 1.0 X-Received: by 10.52.96.8 with SMTP id do8mr34172312vdb.4.1401848896189; Tue, 03 Jun 2014 19:28:16 -0700 (PDT) Sender: markjdb@gmail.com Received: by 10.220.162.68 with HTTP; Tue, 3 Jun 2014 19:28:16 -0700 (PDT) In-Reply-To: <5388A227.7050805@ut.mephi.ru> References: <5388A227.7050805@ut.mephi.ru> Date: Tue, 3 Jun 2014 22:28:16 -0400 X-Google-Sender-Auth: JnZUkYb30k_Te04Ixs2IbG76OB0 Message-ID: Subject: Re: failed to resolve cwd: Unknown variable name From: Mark Johnston To: Dmitry Yu Okunev Content-Type: text/plain; charset=UTF-8 Cc: "freebsd-dtrace@freebsd.org" X-BeenThere: freebsd-dtrace@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "A discussion list for developers working on DTrace in FreeBSD." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jun 2014 02:28:17 -0000 On Fri, May 30, 2014 at 11:22 AM, Dmitry Yu Okunev wrote: > Hello. > > I cannot use dtrace in FreeBSD for my need due to next bug. > > It's said that there's a build-in variable "cwd" contains "the name of > the current working directory of the process associated with the current > thread" [1] > > [1] http://docs.oracle.com/cd/E18752_01/html/819-5488/gcfpz.html > > But when I try to use the variable I get a failure: >> dtrace: invalid probe specifier syscall:::entry { printf("%s", cwd); > }: in action list: failed to resolve cwd: Unknown variable name > > You can get the same error by running a dtrace-script from official > FreeBSD distribution: >> /usr/share/dtrace/toolkit/opensnoop -c Unfortunately, it looks like implementing this variable in FreeBSD would be somewhat non-trivial. illumos (and presumably Solaris) caches a full path to the file backing a given vnode, whereas FreeBSD only caches file names and builds up a full path dynamically in vn_fullpath1(). So one can get a bit of the way there with something ugly like inline string cwd = stringof(curthread->td_proc->p_fd->fd_cdir->v_cache_dst.tqh_first->nc_name); to get the last component of a process' cwd (it needs a check for a missing cache entry), but I don't see any easy way to get at the full cwd. Calling vn_fullpath() in probe context would be a pretty bad idea since it may invoke VFS operations, so adding support for the cwd variable would probably involve adding cache-only lookup code to vfs_cache.c. That said, I'm not super familiar with this stuff, so I could be missing something; this is just based on my previously stymied efforts trying to get a full path for a vnode in a DTrace probe, for example when trying to figure out which files are getting fsync'ed. -Mark