From owner-freebsd-hackers@FreeBSD.ORG Mon Nov 3 08:05:32 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3F18A823 for ; Mon, 3 Nov 2014 08:05:32 +0000 (UTC) Received: from mail-wi0-x230.google.com (mail-wi0-x230.google.com [IPv6:2a00:1450:400c:c05::230]) (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 C842F9BB for ; Mon, 3 Nov 2014 08:05:31 +0000 (UTC) Received: by mail-wi0-f176.google.com with SMTP id h11so5673607wiw.9 for ; Mon, 03 Nov 2014 00:05:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=XiffwQT7+gXU8kgHFniv/ubpUTSl//Mu9czkW5OSfcE=; b=rkuLWfsHfHLxGNh5UP5fkh3i5XGtJCfsyl3OQiL0/V94INdxD+chJP9Q1AVqbR2hfC Hj/0WOzBHWvphcEIiIbm33hqHMuNKkrrnaCIqTlVC8fOF3JaQ2qbdAsGaVjOpbkAEIbm cLaGwhHk1MBalsgCFL42u5YTpWiIskTZptYLbemNLt2RnzhqW11qQrSv6ML5m75gRrzy jkof45JyxqMzVp58nBtKrxcxTdIAdP2WTtejnzF/X/iABGulqv6bH6Xch7ktanu90R1E qtA+UzV1KDjthlRcAfmsnIPJMROF4X+WA9SE1RdSiRDu9+Du3uDKQnW1V1tfCc7kw7yh 8a5w== X-Received: by 10.194.92.195 with SMTP id co3mr21184344wjb.29.1415001929919; Mon, 03 Nov 2014 00:05:29 -0800 (PST) Received: from dft-labs.eu (n1x0n-1-pt.tunnel.tserv5.lon1.ipv6.he.net. [2001:470:1f08:1f7::2]) by mx.google.com with ESMTPSA id l4sm17861855wjx.14.2014.11.03.00.05.28 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 03 Nov 2014 00:05:29 -0800 (PST) Date: Mon, 3 Nov 2014 09:05:26 +0100 From: Mateusz Guzik To: Tiwei Bie Subject: Re: [PATCH] Finish the task 'sysctl reporting current working directory' Message-ID: <20141103080526.GE29497@dft-labs.eu> Mail-Followup-To: Mateusz Guzik , Tiwei Bie , freebsd-hackers@freebsd.org References: <1414987325-23280-1-git-send-email-btw@mail.ustc.edu.cn> <20141103051908.GC29497@dft-labs.eu> <20141103064052.GA1739@freebsd> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20141103064052.GA1739@freebsd> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Nov 2014 08:05:32 -0000 On Mon, Nov 03, 2014 at 02:40:52PM +0800, Tiwei Bie wrote: Kernel patch is ok. > > #2. Patch for tmux: > > diff --git a/osdep-freebsd.c b/osdep-freebsd.c > index d596eab..4178f01 100644 > --- a/osdep-freebsd.c > +++ b/osdep-freebsd.c > @@ -132,6 +132,46 @@ error: > return (NULL); > } > > +#ifdef KERN_PROC_CWD > +char * > +osdep_get_cwd(int fd) > +{ > + static char wd[PATH_MAX]; > + pid_t pgrp; > + int mib[4]; > + size_t len; > + struct kinfo_file *info; > + char *buf; > + int error; > + > + if ((pgrp = tcgetpgrp(fd)) == -1) > + return (NULL); > + > + mib[0] = CTL_KERN; > + mib[1] = KERN_PROC; > + mib[2] = KERN_PROC_CWD; Take a look at osdep-openbsd. This should be done along with declaration. > + mib[3] = pgrp; > + > + error = sysctl(mib, 4, NULL, &len, NULL, 0); > + if (error) > + return (NULL); > + > + buf = malloc(len); > + if (buf == NULL) > + return (NULL); > + error = sysctl(mib, 4, buf, &len, NULL, 0); > + if (error) { > + free(buf); > + return (NULL); > + } > + > + info = (struct kinfo_file *)buf; > + strlcpy(wd, info->kf_path, sizeof wd); > + > + free(buf); Why? Just have static kinfo_file. There is no need to allocate or copy anything, nor to query for size. > + return (wd); > +} > +#else /* !KERN_PROC_CWD */ > char * > osdep_get_cwd(int fd) > { > @@ -157,6 +197,7 @@ osdep_get_cwd(int fd) > free(info); > return (NULL); > } > +#endif /* KERN_PROC_CWD */ > > struct event_base * > osdep_event_init(void) > -- > 2.1.0 > > Tiwei Bie > -- Mateusz Guzik