From owner-svn-src-head@FreeBSD.ORG Thu Oct 31 09:29:38 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 8EF8BE33; Thu, 31 Oct 2013 09:29:38 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 637D02CFF; Thu, 31 Oct 2013 09:29:38 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9V9TcTk016174; Thu, 31 Oct 2013 09:29:38 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9V9TcGS016173; Thu, 31 Oct 2013 09:29:38 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201310310929.r9V9TcGS016173@svn.freebsd.org> From: Konstantin Belousov Date: Thu, 31 Oct 2013 09:29:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r257430 - head/usr.bin/limits X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Oct 2013 09:29:38 -0000 Author: kib Date: Thu Oct 31 09:29:37 2013 New Revision: 257430 URL: http://svnweb.freebsd.org/changeset/base/257430 Log: Remove the dependency on procfs. Use sysctl KERN_PROC_PATHNAME and KERN_PROC_PID to obtain the parent process pathname and command, used to determine the calling shell. Submitted by: Stefan Neudorf PR: bin/183484 MFC after: 1 week Modified: head/usr.bin/limits/limits.c Modified: head/usr.bin/limits/limits.c ============================================================================== --- head/usr.bin/limits/limits.c Thu Oct 31 09:20:30 2013 (r257429) +++ head/usr.bin/limits/limits.c Thu Oct 31 09:29:37 2013 (r257430) @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -705,27 +706,32 @@ getshelltype(void) pid_t ppid = getppid(); if (ppid != 1) { - FILE * fp; + struct kinfo_proc kp; struct stat st; - char procdir[MAXPATHLEN], buf[128]; - int l = sprintf(procdir, "/proc/%ld/", (long)ppid); + char path[MAXPATHLEN]; char * shell = getenv("SHELL"); + int mib[4]; + size_t len; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[3] = ppid; if (shell != NULL && stat(shell, &st) != -1) { struct stat st1; - strcpy(procdir+l, "file"); - /* $SHELL is actual shell? */ - if (stat(procdir, &st1) != -1 && memcmp(&st, &st1, sizeof st) == 0) - return getshellbyname(shell); - } - strcpy(procdir+l, "status"); - if (stat(procdir, &st) == 0 && (fp = fopen(procdir, "r")) != NULL) { - char * p = fgets(buf, sizeof buf, fp)==NULL ? NULL : strtok(buf, " \t"); - fclose(fp); - if (p != NULL) - return getshellbyname(p); + mib[2] = KERN_PROC_PATHNAME; + len = sizeof(path); + if (sysctl(mib, 4, path, &len, NULL, 0) != -1) { + /* $SHELL is actual shell? */ + if (stat(path, &st1) != -1 && memcmp(&st, &st1, sizeof st) == 0) + return getshellbyname(shell); + } } + mib[2] = KERN_PROC_PID; + len = sizeof(kp); + if (sysctl(mib, 4, &kp, &len, NULL, 0) != -1) + return getshellbyname(kp.ki_comm); } return SH_SH; }