From owner-freebsd-arch@freebsd.org Wed May 30 02:10:52 2018 Return-Path: Delivered-To: freebsd-arch@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 05808EF3820 for ; Wed, 30 May 2018 02:10:52 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from mail.baldwin.cx (bigwig.baldwin.cx [96.47.65.170]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AC5FE69516 for ; Wed, 30 May 2018 02:10:51 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from John-Baldwins-MacBook-Pro-2.local (96-86-69-187-static.hfc.comcastbusiness.net [96.86.69.187]) by mail.baldwin.cx (Postfix) with ESMTPSA id 89A7C10AFD4 for ; Tue, 29 May 2018 22:10:44 -0400 (EDT) Subject: Re: Rationale for setting COMMLEN to 19 in struct kinfo_proc To: freebsd-arch@freebsd.org References: <20180530001638.GN99063@spindle.one-eyed-alien.net> From: John Baldwin Message-ID: <6cdb7530-b689-7666-7ce4-9b91acfc6255@FreeBSD.org> Date: Tue, 29 May 2018 22:10:39 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180530001638.GN99063@spindle.one-eyed-alien.net> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.4.3 (mail.baldwin.cx); Tue, 29 May 2018 22:10:44 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.99.2 at mail.baldwin.cx X-Virus-Status: Clean X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 May 2018 02:10:52 -0000 -- John Baldwin On 5/29/18 8:16 PM, Brooks Davis wrote: > On Tue, May 29, 2018 at 11:42:47PM +0300, Gleb Popov wrote: >> Hello. >> >> I've been debugging a failing Qt (KDE, to be precise) test and found that >> process name returned in kinfo_proc structure gets truncated to 19 symbols. >> This causes other errors in the application. I'm wondering why is this >> field so small and is there possibility to increase it? I think, having >> applications with names longer than 19 characters is not that rare. >> >> Relevant header: /usr/include/sys/user.h >> >> Simple testcase to feature the problem: >> >> # cat k.cpp >> #include >> #include >> #include >> #include >> >> #include >> #include >> #include >> #include >> >> int main() >> { >> auto pid = getpid(); >> struct kinfo_proc kp; >> int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)pid }; >> >> size_t len = sizeof(kp); >> u_int mib_len = sizeof(mib)/sizeof(u_int); >> >> if (sysctl(mib, mib_len, &kp, &len, NULL, 0) < 0) >> return -1; >> >> puts(kp.ki_tdname); >> puts(kp.ki_comm); >> >> return 0; >> } >> # c++ -o abcdefghijklmnopqrstuvwxyz >> # ./abcdefghijklmnopqrstuvwxyz >> abcdefghijklmnop >> abcdefghijklmnopqrs > > Changing the size of fields in kinfo_proc would be enormously > disruptive. Take a look at all the source that uses KERN_PROC_PID for a > subset of things that would break. > > Sometimes we can break these interfaces, but I think this one would > require new sysctl mibs. If we did that we should come up with an > interface that is identical between 32-bit and 32-bit systems and > doesn't export pointers. p_comm[] in struct proc is only 20 bytes long (19 chars + nul), so you can't make it bigger in kinfo_proc anyway as we only store 19 chars in the kernel. (Note that we do have room to grow char arrays if needed without having to completely rototill though; we use a hack to store the "rest" of the thread name in a separate array to export the full 19 chars of the thread name now.) If you want the raw command line you can't get that via kinfo_proc. You can use the kern.proc.args sysctl or wrapper functions like kvm_getargv() or procstat_getargv(). You can then use argv[0] as the command name instead. -- John Baldwin