[{"id":3680714,"web_url":"http://patchwork.ozlabs.org/comment/3680714/","msgid":"<874il3lyig.fsf@gmail.com>","list_archive_url":null,"date":"2026-04-22T17:01:59","subject":"Re: [PATCH v2] misc: Optimize getusershell.c","submitter":{"id":88687,"url":"http://patchwork.ozlabs.org/api/people/88687/","name":"Collin Funk","email":"collin.funk1@gmail.com"},"content":"Rocket Ma <marocketbd@gmail.com> writes:\n\n> * misc/getusershell.c: Completely rewrite the unit. Only allocate one\n> big buffer to store shell names. Add a missing unit test.\n>\n> The new implementation read the whole file into one buffer, and wipe out\n> every byte but shell names. Later when addressing shell names from first\n> shell, jump to next '\\0' and then jump to next '/'. This could reduce\n> memory footprint and shall improve some performance.\n>\n> Signed-off-by: Rocket Ma <marocketbd@gmail.com>\n> ---\n> This new patch fixed some unexpected plt links, and use isspace_l to\n> force parsing /etc/shells with C locale. (Is that necessary?)\n\nThanks for the patch.\n\nHowever, I am against this change. The /etc/shells file can be\narbitrarily long, so we shouldn't read it all into memory. It also\nchanges the behavior of the function to be different to all the BSD\nversions. In this version appending a shell while the process is running\nwill not affect subsequent calls to getusershell.\n\n> +  if ((fp = fopen (_PATH_SHELLS, \"rce\")) == NULL)\n> +    goto default_out;\n> +  if ((__fstat64_time64 (__fileno (fp), &fstat)) == -1)\n> +    goto close_out;\n> +  /* Consider if buflen will overflow. */\n> +  if (fstat.st_size < 2 || fstat.st_size > PTRDIFF_MAX - 1)\n> +    goto close_out;\n> +  /* 1 byte for \\n (will be overwritten as \\0). */\n> +  buflen = fstat.st_size + 1;\n> +  if ((shellbuf = malloc (buflen)) == NULL)\n> +    goto close_out;\n> +  shellbuf[buflen - 1] = '\\n';\n> +  _IO_setbuf (fp, NULL);\n> +  if ((_IO_fread (shellbuf, 1, fstat.st_size, fp)) != fstat.st_size)\n> +    goto free_out;\n\nWhat if we call fstat while a user is in the middle of adding a shell?\nE.g., then it is possible we return a truncated shell because we didn't\nallocate enough memory?\n\nCollin","headers":{"Return-Path":"<libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":["incoming@patchwork.ozlabs.org","libc-alpha@sourceware.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","libc-alpha@sourceware.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=X7lIfIwV;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org\n (client-ip=38.145.34.32; helo=vm01.sourceware.org;\n envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=X7lIfIwV","sourceware.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","sourceware.org; spf=pass smtp.mailfrom=gmail.com","server2.sourceware.org;\n arc=none smtp.remote-ip=2607:f8b0:4864:20::1329"],"Received":["from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g15BD3tVzz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 03:02:28 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id A50744BA23FA\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 17:02:26 +0000 (GMT)","from mail-dy1-x1329.google.com (mail-dy1-x1329.google.com\n [IPv6:2607:f8b0:4864:20::1329])\n by sourceware.org (Postfix) with ESMTPS id 2C9B54BA23E7\n for <libc-alpha@sourceware.org>; Wed, 22 Apr 2026 17:02:03 +0000 (GMT)","by mail-dy1-x1329.google.com with SMTP id\n 5a478bee46e88-2de831d2b20so2325268eec.1\n for <libc-alpha@sourceware.org>; Wed, 22 Apr 2026 10:02:03 -0700 (PDT)","from fedora ([2601:646:8081:3770::19df])\n by smtp.gmail.com with ESMTPSA id\n 5a478bee46e88-2e53ab8b89csm24344105eec.12.2026.04.22.10.02.00\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 22 Apr 2026 10:02:00 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org A50744BA23FA","OpenDKIM Filter v2.11.0 sourceware.org 2C9B54BA23E7"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 2C9B54BA23E7","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 2C9B54BA23E7","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776877323; cv=none;\n b=yDFBJ1PNxujImSulTeK3sGv7WBiGC30vhFv2PblS7EBKUlw4Zp50lo+vhnMeSf82QfxxRiQryBC7ukeoNlJhVI35R6Xe/+gNvE8yO5ATrb6LSN8w2AKu4RPY0iOD3I5FyFp28Frp4mPtpBVVEbPdTItVrAO9lAaswXzvUCFEelA=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776877323; c=relaxed/simple;\n bh=qtkfUyNHRtG5ym2K0Wh5JMamImDBdennx8+w6y70wdM=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=CKndB/6QTn93fLYsHOeYL62BHkShpRAjWXA3em2htPvmSTSaE6qozBLEktYy/SOx7VMV8BKGomfTKACpej9VkvNqmk/DUp0a7otJLPs5ypKXMwgtemwhBND5ouzaJBE8YAY8s4RVJMG379hK848dofr3Dc5ZCFSVLUlSV9iSe7A=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1776877322; x=1777482122; darn=sourceware.org;\n h=mime-version:user-agent:message-id:date:references:in-reply-to\n :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to;\n bh=mTf0XvIo9SDcabgrPfaOG/5huAuWeIkb53Ng/blEteQ=;\n b=X7lIfIwVkj7AuLO5n+rp6r+eYXcCpTHujVL7Cfx5A86i+Zkihql6MTPTWy3+m+DRyJ\n TvfOZOmhIrYQ1XkYhDBvlT9UMYh8Ysu0PCXbtnjxMQj6RGWwoeFouPm2Z+u0uUuIMB0z\n LiwEW9Ps7usvR/+0G7ICkbQY2NiUH3iJ6ApHsIf7C5CYXmwZtYK0ZhUQdI68TpaN9LCj\n CRcs6TgWRfpHdc+0OKzZzbX8f0UeTpuXn3bYgnIk7OGcZMW9xeTFSrBYeYP7AGc1JqkI\n fD4iIFro/W/HWU7lTLgps5MQESwV1cztrfqZce6N6o9DfvxpReF4xabtNrd8IHTXuvwJ\n 2AnA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776877322; x=1777482122;\n h=mime-version:user-agent:message-id:date:references:in-reply-to\n :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject\n :date:message-id:reply-to;\n bh=mTf0XvIo9SDcabgrPfaOG/5huAuWeIkb53Ng/blEteQ=;\n b=rGSnOiTVVtYKBXuU8Xc2kuAjnLcbU7QcQsaW0qGcAVUmS9zNEO68qRqa9q723R8HIl\n Hk/LWVgs3SmW6qeZ71l6IltovRv9vbTmFjJrT2mCW4STB4OPKBUJ1p53ClimV6KT8kXj\n 8mtRkx13tA6i4R70uCvySfdIv1fxkygxIYbb8QJmFLZY8ACSQImXzwE4y6hE+rIbhLtj\n bZUZswCu66Hw8aRvcHU1l3ns5Ew1dv9my3Q36/6k9x80lDWDrvkXY9zd5oVzZmIcSF4Y\n 02fzyWXM26HX7GV0aP7v6AL6YJZ7lkhTU6ym1906gEWvutu+t/5SL2ksteWWGPeOjSUa\n /uug==","X-Forwarded-Encrypted":"i=1;\n AFNElJ+k+oK+VEhVT/sWhQWmqTCRBWIIRhcKoi9vHZdUhDRAJsDaKrlBQMPcL4epjLceJrykD0B0DKWyhsAe@sourceware.org","X-Gm-Message-State":"AOJu0YxajeIeqi5hkHEIA0XdZ521jkoLjfD0GLNrI1cJe1yCmrql4ciw\n PjLn1OGaGNBxBCbN+14HnCT+r0/K4KIn9all23Q3lCGbWDXg9zI4WJseli82tg==","X-Gm-Gg":"AeBDietoJFPfXc1Z5i+bxaCESIauVxoBspDsocZJTTa3XTHpYTiq1lfc789BxTKacIs\n z4I0KHIAPQ33O8e1hQ1YGq625UIXRnJW9ONE7pKDtqmWdU0gmDbtPXcwaUwfff+DSOQSYmt9zD5\n WrfD8VaaIefJwOskNiT+fGMoFlee+xjxS9iEVu/4XPX7AD4UIkrKbCrTErO1T3l5p6UUGGH3s+9\n BXuAHjOoax1hRXRn1dboSQeaguVVywXWRVObJPI1JtbpEJZuJwEoP134TvabMN9K7s7QMRa5kNm\n lV3OMpKoNIWeloB06kO830bNoCHXrRIKmUksRgOmtfX8EmIuudQROkQ8INoCqpVSADD8MbFQFBn\n DJh25CUUXmR/TUKR+dybtLFFYNHuY11CWvWkJziSrZ9tTiR+nEDzCwFXid5E2dAiJDdlQ70zAOj\n chN/p/p3bewEPzHCw=","X-Received":"by 2002:a05:693c:300c:b0:2dd:c066:bfe with SMTP id\n 5a478bee46e88-2e478a331bfmr14664094eec.21.1776877321713;\n Wed, 22 Apr 2026 10:02:01 -0700 (PDT)","From":"Collin Funk <collin.funk1@gmail.com>","To":"Rocket Ma <marocketbd@gmail.com>","Cc":"Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,\n libc-alpha@sourceware.org","Subject":"Re: [PATCH v2] misc: Optimize getusershell.c","In-Reply-To":"<20260422164926.62177-1-marocketbd@gmail.com>","References":"<20260422164926.62177-1-marocketbd@gmail.com>","Date":"Wed, 22 Apr 2026 10:01:59 -0700","Message-ID":"<874il3lyig.fsf@gmail.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","Content-Type":"text/plain","X-BeenThere":"libc-alpha@sourceware.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Libc-alpha mailing list <libc-alpha.sourceware.org>","List-Unsubscribe":"<https://sourceware.org/mailman/options/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe>","List-Archive":"<https://sourceware.org/pipermail/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-request@sourceware.org?subject=help>","List-Subscribe":"<https://sourceware.org/mailman/listinfo/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=subscribe>","Errors-To":"libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org"}},{"id":3680723,"web_url":"http://patchwork.ozlabs.org/comment/3680723/","msgid":"<8a969ccf-d65c-466f-8740-1d39e7dd613f@linaro.org>","list_archive_url":null,"date":"2026-04-22T17:28:19","subject":"Re: [PATCH v2] misc: Optimize getusershell.c","submitter":{"id":66065,"url":"http://patchwork.ozlabs.org/api/people/66065/","name":"Adhemerval Zanella","email":"adhemerval.zanella@linaro.org"},"content":"On 22/04/26 14:01, Collin Funk wrote:\n> Rocket Ma <marocketbd@gmail.com> writes:\n> \n>> * misc/getusershell.c: Completely rewrite the unit. Only allocate one\n>> big buffer to store shell names. Add a missing unit test.\n>>\n>> The new implementation read the whole file into one buffer, and wipe out\n>> every byte but shell names. Later when addressing shell names from first\n>> shell, jump to next '\\0' and then jump to next '/'. This could reduce\n>> memory footprint and shall improve some performance.\n>>\n>> Signed-off-by: Rocket Ma <marocketbd@gmail.com>\n>> ---\n>> This new patch fixed some unexpected plt links, and use isspace_l to\n>> force parsing /etc/shells with C locale. (Is that necessary?)\n> \n> Thanks for the patch.\n> \n> However, I am against this change. The /etc/shells file can be\n> arbitrarily long, so we shouldn't read it all into memory. It also\n> changes the behavior of the function to be different to all the BSD\n> versions. In this version appending a shell while the process is running\n> will not affect subsequent calls to getusershell.\n\nThe current code already read the whole file before parsing it, this\nnew approach is no worse.  The BSD code also seems to limit each\nshell to PATH_MAX, while this approach seems to work in-place and\nremoves the extra buffer allocation.\n\n> \n>> +  if ((fp = fopen (_PATH_SHELLS, \"rce\")) == NULL)\n>> +    goto default_out;\n>> +  if ((__fstat64_time64 (__fileno (fp), &fstat)) == -1)\n>> +    goto close_out;\n>> +  /* Consider if buflen will overflow. */\n>> +  if (fstat.st_size < 2 || fstat.st_size > PTRDIFF_MAX - 1)\n>> +    goto close_out;\n>> +  /* 1 byte for \\n (will be overwritten as \\0). */\n>> +  buflen = fstat.st_size + 1;\n>> +  if ((shellbuf = malloc (buflen)) == NULL)\n>> +    goto close_out;\n>> +  shellbuf[buflen - 1] = '\\n';\n>> +  _IO_setbuf (fp, NULL);\n>> +  if ((_IO_fread (shellbuf, 1, fstat.st_size, fp)) != fstat.st_size)\n>> +    goto free_out;\n> \n> What if we call fstat while a user is in the middle of adding a shell?\n> E.g., then it is possible we return a truncated shell because we didn't\n> allocate enough memory?\nI do not think we have this guarantee for current code, and I am not sure\nif would be feasible without some extra support OS.","headers":{"Return-Path":"<libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":["incoming@patchwork.ozlabs.org","libc-alpha@sourceware.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","libc-alpha@sourceware.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256\n header.s=google header.b=EL27XdBt;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256\n header.s=google header.b=EL27XdBt","sourceware.org;\n dmarc=pass (p=none dis=none) header.from=linaro.org","sourceware.org; spf=pass smtp.mailfrom=linaro.org","server2.sourceware.org;\n arc=none smtp.remote-ip=2607:f8b0:4864:20::1234"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g15mc4LcXz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 03:28:48 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 3E73F4B9DB50\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 17:28:45 +0000 (GMT)","from mail-dl1-x1234.google.com (mail-dl1-x1234.google.com\n [IPv6:2607:f8b0:4864:20::1234])\n by sourceware.org (Postfix) with ESMTPS id 00EC24B9DB50\n for <libc-alpha@sourceware.org>; Wed, 22 Apr 2026 17:28:23 +0000 (GMT)","by mail-dl1-x1234.google.com with SMTP id\n a92af1059eb24-12c6df0b9bbso4910857c88.1\n for <libc-alpha@sourceware.org>; Wed, 22 Apr 2026 10:28:23 -0700 (PDT)","from ?IPV6:2804:1b3:a7c3:d5d0:bddf:fa51:e156:c28b?\n ([2804:1b3:a7c3:d5d0:bddf:fa51:e156:c28b])\n by smtp.gmail.com with ESMTPSA id\n a92af1059eb24-12c7b62fe87sm20709772c88.2.2026.04.22.10.28.21\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Wed, 22 Apr 2026 10:28:22 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 3E73F4B9DB50","OpenDKIM Filter v2.11.0 sourceware.org 00EC24B9DB50"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 00EC24B9DB50","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 00EC24B9DB50","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776878904; cv=none;\n b=HiYF41s1KubL0Ax2Hd+mK49trVAFAqFlHJJ9aoI+COlz/QaK30N1uQIUP2kqU2nDWPSenLVt2fZRwObugAsLGfECo+88i+fT9N80BZk0eJkDbDEfSrtibF5Ft/kUjbe5oAcwIQTu1z06VF2u2QKGNQHAJKNAQXrOm6jpSMJ4R5o=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776878904; c=relaxed/simple;\n bh=qX/mLm7bI08bcbbDGy5ORrkoEu+zJSQv8LMgtMdAWfU=;\n h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From;\n b=ZcRqzV1lrJ7XEezx0MGDFKwwf43h6RkpJbTO9sth/sredR36haeabWllDl0uprMZTdhZ/2xf8rHq+5kKMzWaZ+uIisejzqZznKfb8zHjI8RpWbo9JrO177NJKwIFsLULDu5IQuPysaPR0oJ1YQD1lNaQ1lS+DOmBjUOem9+9VDE=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linaro.org; s=google; t=1776878903; x=1777483703; darn=sourceware.org;\n h=content-transfer-encoding:in-reply-to:organization:from\n :content-language:references:cc:to:subject:user-agent:mime-version\n :date:message-id:from:to:cc:subject:date:message-id:reply-to;\n bh=39gViIM4g6YF1OMHiFIRiVfgv+r5AndNxyW+aHbKjY0=;\n b=EL27XdBt2JsRNHUTPfVzEWozWyeym0RH3uddsg0Ieary/RkJS27OVDqWJ3RbzMWCjv\n otWqnvnQdj6Pb/tR2q5o4DJ4jKyGllnGk72aMLfZl366yq+KaMNxXdQ0kS7l5N5L79oS\n DE0h/BSfu06pbHYCazAnowaZDWgDe9IXKN0J1CeD88K5Kbz5dy7cjbRHunAdeFYgCHaK\n zWjsrrZV3goFQxT+f/m09WyfNNqKu7M+lg/JeoMSiodaTQR3dsbouQGSYPqYtpH8qfaz\n GanRywDEwcfDDgpk3JPYMISs64PhpAhTgTZE2mRCKCOqX7XuC31haAYE3Rj6CKNvAJda\n u1QA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776878903; x=1777483703;\n h=content-transfer-encoding:in-reply-to:organization:from\n :content-language:references:cc:to:subject:user-agent:mime-version\n :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n :message-id:reply-to;\n bh=39gViIM4g6YF1OMHiFIRiVfgv+r5AndNxyW+aHbKjY0=;\n b=h6YtCn3ZQ/d3x6GRVlAUbqZYNv1IplPOVp3CrxkkCPkEx8dZcIbD4g819qKzjkVSvD\n 3ahbgOKPi7A7RkX80vLxexvK4j+eG0hp/m9OSt+WJrcQhsTMBqZkabxl2WD4h5aTYFTU\n IxoaXK+Eli3eRC4Sm/cNs/PuuUgEHyLrhXY+Iyiz/aJjI9VQLiB6fJQYyiiEa7rtndaA\n hnWqU5azgVhS7pfhlDnFN1kh/pfVMIWdllJ4W/Xj8Hoj03ycSxIoD/f0JXUF4hVdByKb\n ydOFOE3wzeXPfRaXN2CBORVot4dfiGKbVEtXu6HSR7LLFePm0l+ZaBRApAhcyn0qLiZ0\n JG3w==","X-Gm-Message-State":"AOJu0Yybt+7tPDaTx3KMXPaAwuzz1vnfXMGLsz63uA6aq5SfjNfQqPR6\n 7brRwVRdDOFbahf2MG9zWKb/1Jywy2tc/hYm1lVRy2HJhrgEsf/mov7F2krq53uTKK8=","X-Gm-Gg":"AeBDieu6o1mTbzqUse2xcOt/XzF0dbc5nTJveipwSDRMJ0NMJyvnj7pokmgL6emZifg\n 1rPaVhqBHaNWKxiCwUfmgT5dqOJrvm8n0y7FGLCzH2EDv3VX2WoCp0guofwAQ0Ljw9YLfBzRRyK\n 3ugmnakOZgqCJbiUukm4QnwBbEUzYqHakvnxgAdD4kveGu2guer//XgBGvetTWo0sKLl4n7RYAr\n EpG7kR6/CjZc9IK1RTWc4uva46HFqOhTNQ9LstoIx7gzvtcey0xPCozlXRa7FS/CwSl8w82m/Ka\n QaFZL7pPWcC7MshPUSYS80Qg5K8Sc5+/WvXC7jbqzXj+933btlGdzog8Zv698JZIQjaG1RAStEx\n pusI3EnrKlhuwiVq44X6q3FNaWfpHuuLcFkar3nNEbF0uMK6lyOVX5jnlo6l7oXCfFCWRv8X0Ix\n 65IoDA16LTuGS+bkBZSL1Hn5KYV4a9Sm1Aj5ZHek15cqDUCeKxX56MqcxwrZMbPvTgN5S6fTozy\n pbPx9bR1wRdyDnpAxc+5JYIDu6xa6CF+iuJ1H0H6n7R","X-Received":"by 2002:a05:7022:4199:b0:127:33e0:ea44 with SMTP id\n a92af1059eb24-12c73fab049mr13820080c88.29.1776878902555;\n Wed, 22 Apr 2026 10:28:22 -0700 (PDT)","Message-ID":"<8a969ccf-d65c-466f-8740-1d39e7dd613f@linaro.org>","Date":"Wed, 22 Apr 2026 14:28:19 -0300","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2] misc: Optimize getusershell.c","To":"Collin Funk <collin.funk1@gmail.com>, Rocket Ma <marocketbd@gmail.com>","Cc":"libc-alpha@sourceware.org","References":"<20260422164926.62177-1-marocketbd@gmail.com>\n <874il3lyig.fsf@gmail.com>","Content-Language":"en-US","From":"Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>","Organization":"Linaro","In-Reply-To":"<874il3lyig.fsf@gmail.com>","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"7bit","X-BeenThere":"libc-alpha@sourceware.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Libc-alpha mailing list <libc-alpha.sourceware.org>","List-Unsubscribe":"<https://sourceware.org/mailman/options/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe>","List-Archive":"<https://sourceware.org/pipermail/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-request@sourceware.org?subject=help>","List-Subscribe":"<https://sourceware.org/mailman/listinfo/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=subscribe>","Errors-To":"libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org"}},{"id":3680724,"web_url":"http://patchwork.ozlabs.org/comment/3680724/","msgid":"<CAO_32JrkJOJE6Hs4mFLDmY9g=41LYO7rVKqgHnxejyPrPAWKiw@mail.gmail.com>","list_archive_url":null,"date":"2026-04-22T17:32:23","subject":"Re: [PATCH v2] misc: Optimize getusershell.c","submitter":{"id":92898,"url":"http://patchwork.ozlabs.org/api/people/92898/","name":"Rocket Ma","email":"marocketbd@gmail.com"},"content":"> However, I am against this change. The /etc/shells file can be\n> arbitrarily long, so we shouldn't read it all into memory. It also\n> changes the behavior of the function to be different to all the BSD\n> versions. In this version appending a shell while the process is running\n> will not affect subsequent calls to getusershell.\n>\n> What if we call fstat while a user is in the middle of adding a shell?\n> E.g., then it is possible we return a truncated shell because we didn't\n> allocate enough memory?\n>\n> Collin\n\nFirst, since the old implementation also allocates a buffer with file\nsize, it assumes that the file should be small. Not to mention the\ndynamically allocated array offhead. Second, I tested the behavior\nlocally, if another process is manipulating /etc/shells, fgets will\nnot wait until the process is completed. Once fgets read all of the\nfile, even though some process is still appending, fgets returns NULL.\nSo the old implementation should face the same problem, too. Also,\n/etc/shells should be stable enough that we could read it in one\nfread. The race condition is so rare that it could be treated as an\nundefined behavior.\n\nRocket","headers":{"Return-Path":"<libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":["incoming@patchwork.ozlabs.org","libc-alpha@sourceware.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","libc-alpha@sourceware.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=QBOnPQ+x;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=QBOnPQ+x","sourceware.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","sourceware.org; spf=pass smtp.mailfrom=gmail.com","server2.sourceware.org;\n arc=pass smtp.remote-ip=2a00:1450:4864:20::631"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g15sW1StMz1yGs\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 03:33:03 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 3BD3E4BAD168\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 17:33:01 +0000 (GMT)","from mail-ej1-x631.google.com (mail-ej1-x631.google.com\n [IPv6:2a00:1450:4864:20::631])\n by sourceware.org (Postfix) with ESMTPS id 5BA674B9DB7E\n for <libc-alpha@sourceware.org>; Wed, 22 Apr 2026 17:32:40 +0000 (GMT)","by mail-ej1-x631.google.com with SMTP id\n a640c23a62f3a-ba5b107eaa2so354964166b.3\n for <libc-alpha@sourceware.org>; Wed, 22 Apr 2026 10:32:40 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 3BD3E4BAD168","OpenDKIM Filter v2.11.0 sourceware.org 5BA674B9DB7E"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 5BA674B9DB7E","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 5BA674B9DB7E","ARC-Seal":["i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1776879160; cv=pass;\n b=jZODRw8tFXfE5YQfe+E0D8favweU6cVcvkibLX2d66lyBH4Qgnw7sxwTl9s61cZkyli2uRHtwU4xq+HJ0PL0CWbNmEHS/QfpoYLlrCluWV9b4OzzM1CxHt8wJ5TqS7Ek47USiTx5d7lK6/AlNHn16QB5UNvk3sDFpqyl1b4FO/A=","i=1; a=rsa-sha256; t=1776879159; cv=none;\n d=google.com; s=arc-20240605;\n b=Fxv1uj5yvKoH60/kFM7BKGbheR0MDXQixPV3mP8Pvc+K3VRpwZskfI6644DxkRGesR\n M3btWLJbywTLH5uXSe7z0/EsQTaHyMGwdTcopTIDsj8zBHeYAEnUnjns8AQABZsQVrUR\n wRUX4p685tzeff5+vwqiLYYsWEE/36GIJNePYY40PB9KMeklv9i1UgqBMQIGd1Zp5b+B\n iFKp2bYRAr+oaxG5Vz6CVmYWWFVBZMVwBpNk2nNwmfVkR/TE1/TAJKHgZvLGHbXiNKbL\n T+7d4lVw5RruK7LmSi7qLFKbIFC6mbz8URrHLyo6KtN0gTY6wWWCoxruiqRLQK4Ksrew\n BJpA=="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776879160; c=relaxed/simple;\n bh=KAUGrL3jIFkDwIZjjlAgaXxpBU+tldwyqVJTOz15N08=;\n h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To;\n b=l7I2lwFgLT0D9bdhxicI5Cr7c+V8qDSlZ8kSUXF9dxIy2BejdPPCl1jAzjff1VLzLGBGeRldu29HqJdIH8em88M8twxmggiCFj7rJP0pB59VKEDtNu/JWtwPBGpC76d4BNTQmTObGETaFQSZblkpvSIPLyIhnrAN2PW/Oc24yR4=","i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n s=arc-20240605;\n h=cc:to:subject:message-id:date:from:in-reply-to:references\n :mime-version:dkim-signature;\n bh=KAUGrL3jIFkDwIZjjlAgaXxpBU+tldwyqVJTOz15N08=;\n fh=AQxLhoXsD9+uLXRv7n1VfEx0+GmBrGi6aB/XUZ5zjB4=;\n b=YK+hRlp2Fsav9ZCQey/vabZxDwI8KsbwxNq9f4aoohIPdTmwCpY2x0nZAw03exLCLy\n tYsB3BOG4gd3XRW3iGXs/bP9B5hQQzKOC8tgqm3ULbA3OI2gfJjESSW2X/sKnFBuLjZ/\n OJPQgDCvEfPqCMJYdFY31M/BnXyJ8oLdsAJLGZCnxrg66b8jkAdhfMjBnQ6zLDQaY/M/\n mOPRjSo+r5Jh3Ld864/wX/iCQC/CNTF50fN2mIxSOvoej4OrjwF87i1Ooqe0MLH4vjXp\n IaX0Ozh11kS95h5FlHiHwb7vkAwOXD7zyZ3ZDkT1lVbNm0tJlHmOzf8JVs7MG/9I4NXj\n 53Pw==; darn=sourceware.org"],"ARC-Authentication-Results":["i=2; server2.sourceware.org","i=1; mx.google.com; arc=none"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1776879159; x=1777483959; darn=sourceware.org;\n h=cc:to:subject:message-id:date:from:in-reply-to:references\n :mime-version:from:to:cc:subject:date:message-id:reply-to;\n bh=KAUGrL3jIFkDwIZjjlAgaXxpBU+tldwyqVJTOz15N08=;\n b=QBOnPQ+xdu+1WtvrwQ5ElL49DwnLO6fxKD7RfCQrjOZIHLV27izNvuLl+H1ouwKY67\n kMtLoNi6Ac7iS7dDfpPv9HtPQEsGiDmq70AE17mXoEMIGngQjeKp+Cs9HqPv2dODzyT7\n nHpT6naFDYgZZUQIlExvkkV5fOfzLp3gTse60+FRb0gmLM5o9rqyjuYMkzv36RMHXdVh\n RfjbwNFrJiOoJEnXDtSL/rWnTYVx1ShxzJLyRgq1Etu/wMwkYvYB+jwyd1VWFxPGEsEe\n +nTIvw5GYYKnmiuY55H+UQKsn3exjR1w7P+doN5NcxD24ZGJ9RhpPWodrl/Feq5BCV5K\n v78g==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776879159; x=1777483959;\n h=cc:to:subject:message-id:date:from:in-reply-to:references\n :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n :message-id:reply-to;\n bh=KAUGrL3jIFkDwIZjjlAgaXxpBU+tldwyqVJTOz15N08=;\n b=jsYpixEgVa9AcvnW33VRF2rqrDp+mQGixK+pHD3FBl8vm5rlKjcqEWlx8J2sMe1T/R\n RN0Wry/ztUPQzPXzkFxlNNwY5KDnNe7TY0DJG8dRk9nZa1PNbXopk+/jMK0aWJ7lr639\n YKmFuiPlyRPTMrMpxi2LYKEvkPGg5rphqkur9LzigE6DREkEPtNDtLkbYDJ/09KStCU4\n Qwp1bVdrGE89XRSLycMPIIwlaIknsb37lDHQAMpR40RYc79rzdeKYTw9r+Ozr9CTm82X\n FH+RNmorR4VZiSVw0ytjVnq/AFa6aSQYm2ZWe4+bKPTE8mNaByVQxJBnwHUT+IoxStSq\n t5tg==","X-Gm-Message-State":"AOJu0YxSkd/wYsMb6gTXVT6tD5TFF4PMYAXBr2mbrzdNPTI0sIfThnyd\n vw7t/U9jeQi3v9bIk7rn7X6qPVrc5cKzSEsyl1z5LpzigFZ33feee8D/BHyAXMBuPdG856ukH3M\n EoLvdwe3cs6H64uCk9oDKeoGfT6tELlOHSgsE","X-Gm-Gg":"AeBDievEJPf2SD8bbZPOonPzATqpnlfC0D4hpv0L+X4ej7RTKHPMuD5N2jBY1uxnQOD\n Gtzcp1+f3XDDj9kRp8bLCZIw8+pIlM/wjSvUNPiOHS1Jr+FoVc93KKG/HgR3KogQL7pKMVicqxy\n IY3CYkd5TJznxqJ3CkDC18+w9RcAdJoPFRXNqLMPtyRX61LQG9GPVOOtZ8iIp3bRLfCxoETMt5M\n +OShwOqhtfUIg1+dGYandgTB+zq5+P6BbLRTbnm9z+Pfjz7afeWCj6GpOnsAzr+qxNt27GNfFe3\n KUsASbCSO25vvdTTRm70AIo1WxvMb5eHnhWFfXfC/y3yTW30l13H5oiwm6lWva36ijIg5ILfkVF\n MxiOJFTYjcTDD29wyJnxSGlBWWyFi7FlJVja5+R14P/WqQvLNczVbNy1PByCHxxGzAAPoDOzgGJ\n ALmbE+uquNIg==","X-Received":"by 2002:a17:907:a607:b0:b9d:31c2:37f9 with SMTP id\n a640c23a62f3a-ba41828cbe5mr1281886366b.2.1776879158808; Wed, 22 Apr 2026\n 10:32:38 -0700 (PDT)","MIME-Version":"1.0","References":"<20260422164926.62177-1-marocketbd@gmail.com>\n <874il3lyig.fsf@gmail.com>","In-Reply-To":"<874il3lyig.fsf@gmail.com>","From":"Rocket Ma <marocketbd@gmail.com>","Date":"Thu, 23 Apr 2026 01:32:23 +0800","X-Gm-Features":"AQROBzDhVr3XxySP4rih1zB4fiOhsT7I47voSPlZLR7jpnWAww2VtFCbmTu5QSo","Message-ID":"\n <CAO_32JrkJOJE6Hs4mFLDmY9g=41LYO7rVKqgHnxejyPrPAWKiw@mail.gmail.com>","Subject":"Re: [PATCH v2] misc: Optimize getusershell.c","To":"Collin Funk <collin.funk1@gmail.com>","Cc":"libc-alpha@sourceware.org","Content-Type":"text/plain; charset=\"UTF-8\"","X-BeenThere":"libc-alpha@sourceware.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Libc-alpha mailing list <libc-alpha.sourceware.org>","List-Unsubscribe":"<https://sourceware.org/mailman/options/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe>","List-Archive":"<https://sourceware.org/pipermail/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-request@sourceware.org?subject=help>","List-Subscribe":"<https://sourceware.org/mailman/listinfo/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=subscribe>","Errors-To":"libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org"}},{"id":3681257,"web_url":"http://patchwork.ozlabs.org/comment/3681257/","msgid":"<874il2l6tc.fsf@gmail.com>","list_archive_url":null,"date":"2026-04-23T03:00:15","subject":"Re: [PATCH v2] misc: Optimize getusershell.c","submitter":{"id":88687,"url":"http://patchwork.ozlabs.org/api/people/88687/","name":"Collin Funk","email":"collin.funk1@gmail.com"},"content":"Adhemerval Zanella Netto <adhemerval.zanella@linaro.org> writes:\n\n> On 22/04/26 14:01, Collin Funk wrote:\n>> Rocket Ma <marocketbd@gmail.com> writes:\n>> \n>>> * misc/getusershell.c: Completely rewrite the unit. Only allocate one\n>>> big buffer to store shell names. Add a missing unit test.\n>>>\n>>> The new implementation read the whole file into one buffer, and wipe out\n>>> every byte but shell names. Later when addressing shell names from first\n>>> shell, jump to next '\\0' and then jump to next '/'. This could reduce\n>>> memory footprint and shall improve some performance.\n>>>\n>>> Signed-off-by: Rocket Ma <marocketbd@gmail.com>\n>>> ---\n>>> This new patch fixed some unexpected plt links, and use isspace_l to\n>>> force parsing /etc/shells with C locale. (Is that necessary?)\n>> \n>> Thanks for the patch.\n>> \n>> However, I am against this change. The /etc/shells file can be\n>> arbitrarily long, so we shouldn't read it all into memory. It also\n>> changes the behavior of the function to be different to all the BSD\n>> versions. In this version appending a shell while the process is running\n>> will not affect subsequent calls to getusershell.\n>\n> The current code already read the whole file before parsing it, this\n> new approach is no worse.  The BSD code also seems to limit each\n> shell to PATH_MAX, while this approach seems to work in-place and\n> removes the extra buffer allocation.\n\nAh, thanks to you and Rocket for pointing out my mistake. I think I was\nmixing up the one in glibc and the one I wrote for Gnulib to work around\nsome issues. Sorry for the extra noise.\n\nThe one in Gnulib uses getline, mostly because it was easier. I guess\nthe downside to that is that you might read a very long line which would\nbe impossible to execute as a shell, instead of limiting things to\nPATH_MAX. It looks like OpenBSD decided to go in that direction as well\n[1].\n\nCollin\n\n[1] https://github.com/openbsd/src/blob/7a2e62a4900cc0c671c264dfa2679f73987d45c6/lib/libc/gen/getusershell.c#L103","headers":{"Return-Path":"<libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":["incoming@patchwork.ozlabs.org","libc-alpha@sourceware.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","libc-alpha@sourceware.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=jbwOJcB/;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=jbwOJcB/","sourceware.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","sourceware.org; spf=pass smtp.mailfrom=gmail.com","server2.sourceware.org;\n arc=none smtp.remote-ip=2607:f8b0:4864:20::122e"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g1LSs0CtCz1yD5\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 13:00:40 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 5A6FC4BBF6EB\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 03:00:38 +0000 (GMT)","from mail-dl1-x122e.google.com (mail-dl1-x122e.google.com\n [IPv6:2607:f8b0:4864:20::122e])\n by sourceware.org (Postfix) with ESMTPS id 213404BBAFE4\n for <libc-alpha@sourceware.org>; Thu, 23 Apr 2026 03:00:18 +0000 (GMT)","by mail-dl1-x122e.google.com with SMTP id\n a92af1059eb24-12c8ccc7755so5554048c88.0\n for <libc-alpha@sourceware.org>; Wed, 22 Apr 2026 20:00:18 -0700 (PDT)","from fedora ([2601:646:8081:3770::19df])\n by smtp.gmail.com with ESMTPSA id\n 5a478bee46e88-2e536e54562sm25399143eec.0.2026.04.22.20.00.16\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 22 Apr 2026 20:00:16 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 5A6FC4BBF6EB","OpenDKIM Filter v2.11.0 sourceware.org 213404BBAFE4"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 213404BBAFE4","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 213404BBAFE4","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776913218; cv=none;\n b=gTY7BXOCq7VP3Aqb1UVyas0kbdQjXmfD9AtRujpyOBZI9TWbOq41HE1BRsXF83fGmTKHseQ3/Wn3q+tGE3boty3S/YD3aIgNjomSTu8FUmpsnsMAvuCITCnC7BGVlMHG9eymHBgrdoaMDUgLEfSTwH3+6UlK2XV1ouYdn/kiioo=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776913218; c=relaxed/simple;\n bh=OZr7JHFVD4FfL+VYRRUPUC/tVm6NyCtCKEzKxKKprGs=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=wetPJ27Z7j+RJRChVPusPTX4PskhhB93w1RJNVR1b9Ogr4qTskPbH3/fH9UJvLp5PyCnhdb+gDjBLlQvjgAA73ua9DDWRgD0knEYd7UirC2sXf2leNX34QIjADSQWEGSnF3oPFRajrCxNOGnwIg5BIqFaNqwSRU0v3sLzdIcsPE=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1776913217; x=1777518017; darn=sourceware.org;\n h=mime-version:user-agent:message-id:date:references:in-reply-to\n :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to;\n bh=5hX6VkbS28cRQUBhhVqmC4YxSveQ3zPtTMaHergrBVw=;\n b=jbwOJcB/z3wwVtiMR9Y9mFW1ZfeCGiUx+uD531N4Yl9Jz9L9i+Gt4UXsNE1EH8S5TR\n cSV8ao10xXpZWUvRbjL2hl51aiiS99mOIaL1iPrBE3RYGy8DNs3MXuem5V4tgWPC9P5v\n qcbk/U1myeHyxJZoUK5RAO5kbK2eig4/7B+FCXVMvq27WAYY8PDX0NOvsQGhEtDoonw2\n ba8UsKaznC3J97z5mCF0BmAsr0dlkwDcPA41vKTI5sQHoJdFg0ImDkcpgirnJI9G4QXB\n rrMx7bnzPkLqgzIsK++l/BCvv5DESG3+BQASuNFYD2/QMNo+cp+wdlBGpUCfUSjuV5ci\n k96A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776913217; x=1777518017;\n h=mime-version:user-agent:message-id:date:references:in-reply-to\n :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject\n :date:message-id:reply-to;\n bh=5hX6VkbS28cRQUBhhVqmC4YxSveQ3zPtTMaHergrBVw=;\n b=H17E/i+B6aPBvC1LDR22z9BWXAOZqAwevBa0uHWS6vbHoj1yv0dE7WBb61pzpcaYyt\n v8lT8BhntNtT7XCWKRcwvXKNZMuz00sIMUJ5u8Cl4XmzVmjkxpVIwjWx1qJUtWE+xHKn\n uUrBbEpeJD/vqy5Y7acoa0UxeWj0rY2zqZIqSRP3y5Vk15gwxdEc0xeilBkKonBmBOt2\n 6syF6RExwE7P0vEGbjWH91gqwAAJB3NYMtw2GdhouvVzPTQC8HIj3/IRUyWYfiCxpq2V\n uJraV1f1O7Ko+D0Up1vNMNJXyAbnKBfiwtBpXy9nx3EFfIblk4fm4+GMEU+eICSxb5Rd\n G+1w==","X-Forwarded-Encrypted":"i=1;\n AFNElJ+dMiyujcsibp7kjM8iWEDVzVO1Z3IQVL4FhlqgbBIsEBlVvnm9/W7gkety8IyfKXYz2FzS1AVo8+Ip@sourceware.org","X-Gm-Message-State":"AOJu0YyhcXPVoodjCx2Tt792EQYE4RW1GIDDTVD4+jVKnMbdIpQF2NcN\n rUjr9nGkRbWwe2hH83+D+eQaRwUZzRsW0u5r+x/1fWBGEEIhH+zL5YKa1OxeOg==","X-Gm-Gg":"AeBDievEGvBJaD3ZF9cdi26KoMK+6e/Tn0TFlPY5eYcN1xD0tUiKXkHc/j7FhninopG\n 5tuIOJ2sHTM6aUj46RJ1Yw0wkwSE/l8yuh2i4wRXIdwjoLKU93ZS/JzyhlBFD3hO74eioYdTRG4\n s+7+UFtS5Rx2xSjNSJedRRhJwKo3AEMhUnFnL9U1RsgOO+ESsqUa5S1OzJVO/fpBQNRT/D9IUdZ\n HWeAVVp07W/M+2B5Ym5oNkIEXTH7SVtOjlz+KACTC4S+k/D1k2OJE9hcGQD5UlO9SaZqMcZ3DLu\n efw9oHWLquVonO17arkxadhlagWca4CFXs45o+k5nK5ZUS7EwKh3r5JsEWe+j72AuheVErq2VQ2\n YxXkeO4FodEjBVFIPNq4qfMEU0LT1XrQKIZ7XZPQGFZuJWd5lSPj9/XDTPpIIULFFP4Ht6zWHyJ\n fut+nRdPmWi2z+mA8HJ8BkmJslXw==","X-Received":"by 2002:a05:7301:1f01:b0:2c7:5a7b:e8c0 with SMTP id\n 5a478bee46e88-2e4657714d1mr13254341eec.12.1776913216813;\n Wed, 22 Apr 2026 20:00:16 -0700 (PDT)","From":"Collin Funk <collin.funk1@gmail.com>","To":"Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>","Cc":"Rocket Ma <marocketbd@gmail.com>,  libc-alpha@sourceware.org","Subject":"Re: [PATCH v2] misc: Optimize getusershell.c","In-Reply-To":"<8a969ccf-d65c-466f-8740-1d39e7dd613f@linaro.org>","References":"<20260422164926.62177-1-marocketbd@gmail.com>\n <874il3lyig.fsf@gmail.com>\n <8a969ccf-d65c-466f-8740-1d39e7dd613f@linaro.org>","Date":"Wed, 22 Apr 2026 20:00:15 -0700","Message-ID":"<874il2l6tc.fsf@gmail.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","Content-Type":"text/plain","X-BeenThere":"libc-alpha@sourceware.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Libc-alpha mailing list <libc-alpha.sourceware.org>","List-Unsubscribe":"<https://sourceware.org/mailman/options/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe>","List-Archive":"<https://sourceware.org/pipermail/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-request@sourceware.org?subject=help>","List-Subscribe":"<https://sourceware.org/mailman/listinfo/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=subscribe>","Errors-To":"libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org"}},{"id":3681268,"web_url":"http://patchwork.ozlabs.org/comment/3681268/","msgid":"<CAO_32JqiqAgQ-+FCDg-ChrfRSncnroyZC9RqWeztVd7gzeQOxQ@mail.gmail.com>","list_archive_url":null,"date":"2026-04-23T03:47:20","subject":"Re: [PATCH v2] misc: Optimize getusershell.c","submitter":{"id":92898,"url":"http://patchwork.ozlabs.org/api/people/92898/","name":"Rocket Ma","email":"marocketbd@gmail.com"},"content":"> Ah, thanks to you and Rocket for pointing out my mistake. I think I was\n> mixing up the one in glibc and the one I wrote for Gnulib to work around\n> some issues. Sorry for the extra noise.\n>\n> The one in Gnulib uses getline, mostly because it was easier. I guess\n> the downside to that is that you might read a very long line which would\n> be impossible to execute as a shell, instead of limiting things to\n> PATH_MAX. It looks like OpenBSD decided to go in that direction as well\n> [1].\n>\n> Collin\n>\n> [1] https://github.com/openbsd/src/blob/7a2e62a4900cc0c671c264dfa2679f73987d45c6/lib/libc/gen/getusershell.c#L103\n\nThis patch aims at reducing memory footprint, since it only allocates\none big buffer, then frees it. The old implementation allocates a\nfile-size buffer to store string and (file size / 3 * 8) to store\npointers. The openbsd implementation you pointed out uses getline +\nstrdup with a dynamic array to allocate strings and string pointers,\nleading to multiple malloc calls. For glibc, only allocate one big\nbuffer could help malloc to trim or split it later should improve\nperformance, rather than leave a lot of free chunks that may never be\nused in bins.\n\nRocket","headers":{"Return-Path":"<libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":["incoming@patchwork.ozlabs.org","libc-alpha@sourceware.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","libc-alpha@sourceware.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=UATldQmt;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=UATldQmt","sourceware.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","sourceware.org; spf=pass smtp.mailfrom=gmail.com","server2.sourceware.org;\n arc=pass smtp.remote-ip=2a00:1450:4864:20::62f"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g1MW16fm5z1yD5\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 13:47:57 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id F18654BBD58F\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 03:47:55 +0000 (GMT)","from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com\n [IPv6:2a00:1450:4864:20::62f])\n by sourceware.org (Postfix) with ESMTPS id F2BFE4BBA17D\n for <libc-alpha@sourceware.org>; Thu, 23 Apr 2026 03:47:35 +0000 (GMT)","by mail-ej1-x62f.google.com with SMTP id\n a640c23a62f3a-b932fe2e1a7so29414466b.1\n for <libc-alpha@sourceware.org>; Wed, 22 Apr 2026 20:47:35 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org F18654BBD58F","OpenDKIM Filter v2.11.0 sourceware.org F2BFE4BBA17D"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org F2BFE4BBA17D","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org F2BFE4BBA17D","ARC-Seal":["i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1776916056; cv=pass;\n b=rejKitqMCHvMzReCQ5u0EZSSLZVJQlLGmpZ1pNLl2toY8DRNYy1R6EdQSctiCd93cR3//IosWM3vzfWD/k93xN5RY/fjdk4p1PHWK7A6rHkqXtxoEB2I05gLKdu/j9MpJ98nsWyBETrZmL1JVndmRIvU4vunvqzrfvtgSYCAbFc=","i=1; a=rsa-sha256; t=1776916054; cv=none;\n d=google.com; s=arc-20240605;\n b=e3MB4z+hZ+vgb+77NrX642ZnG2hcwuKm6IhK8AWO8P5rIYQWlOOVjv3T0hTJ7rDCP5\n SJVt2dRfiBpmSnNP/RV8gFH/IoGQKSJrrBgmbooUkq486zjDDyTtl7X/1d+txxMKAU2p\n FjjYtgowLILMZFzwMEPhjMQKQP/Bg5v06xmDIhZKUwd7G45Z58ZuHEfV5qXWUuQ74W6L\n 87j8wu9mcDV+2XIjl9FMnA0LHI5g+4/LgfBT4JCE7++WugdTpOz0vrNVNmVMD0OOFqqE\n LbBM8RPmMwNeqLXadYNJII1QMZuX7KBd1gjBipD0qpoMHS1zY+hRi3KtvPh91j/dR4cY\n 5omA=="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776916056; c=relaxed/simple;\n bh=G6cptW4xgoowbL/wXUAxEiIM+XeMaZNdf9RL4vJum2E=;\n h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To;\n b=GmpbxO9O8+jPCXn/vSivBtdGNQiDNqZokB98sV2GVlcouA2GlqmxBzy92Ho2WB1p+JcXpwAEZZJVzdDoZ9G5CVMs8FYwl11aepTSXwlgfroh6TM+3+BZb6WLSyaLRt7oypgwDsDZ6p+1Nph9a0sSGpPb3ih4jPKbgSaz80r020E=","i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n s=arc-20240605;\n h=cc:to:subject:message-id:date:from:in-reply-to:references\n :mime-version:dkim-signature;\n bh=G6cptW4xgoowbL/wXUAxEiIM+XeMaZNdf9RL4vJum2E=;\n fh=AVe2mgi05HSuy169S2CccSap2QKyQE6g5n83XYPUIM0=;\n b=PEtVUCs+mY/jbz3MNpHAP1PVNKOXJa1f1klB+qjjwroYzJJknGe4aKJ/wYixFFMmZf\n 8gUh7AOKWC3dA/VgzR0SC4gvRoVxBH8Xm6eKgpNpH93/6oZeeFNIQCFPjD5cf6h9B+K1\n dJSAHRga7l4n50TU0JNy4tZLBRwLOzvvMFt1FwTLU81I35r7ZJjwRoWjygZ6enIKlrJC\n 3srvqAO6g/e8nN3DxxJ/uo7gbGGUtdYB8qeEKG0PyhSWkcELceRmk7U5tkYg4LkPHy89\n TVo0Ag1Y9I87SS3VrY80peP9N7zXPQ/0Jx6OiPOTFCTgwYdIMWhObgNNeF9h2+N28o/G\n 1Ktw==; darn=sourceware.org"],"ARC-Authentication-Results":["i=2; server2.sourceware.org","i=1; mx.google.com; arc=none"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1776916054; x=1777520854; darn=sourceware.org;\n h=cc:to:subject:message-id:date:from:in-reply-to:references\n :mime-version:from:to:cc:subject:date:message-id:reply-to;\n bh=G6cptW4xgoowbL/wXUAxEiIM+XeMaZNdf9RL4vJum2E=;\n b=UATldQmt17BZsgyLqwMhsS3gUiYXPZVkAUHI8jsPEpzGymgTHLBHzenpMtkHITxXlQ\n 7gg4maBY9Fw0hh1jfJ/vEMVH8RyNkE7W7SYv5MNT69QBHojryDMLUbTB7jHjT/hrYody\n GLswiUYIzieeKltvnKnIQ6dylQRbnbIiWzy/iP92aeakxKGg+5ZqeYpGRV507sYqgW1f\n gVNF5OHJL0i0zwoEkqmDm2EoSe6F/CtLScXgnStqv7QqAMp+UdcwiW5F3M1cr2cpp4+s\n 7aSQEI2kk/XPeLLsHi55CSpPh5wx1J+dNeSbspm5kohwsiST3xgeFj3UwvgAFW/O9VG4\n c25A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776916054; x=1777520854;\n h=cc:to:subject:message-id:date:from:in-reply-to:references\n :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n :message-id:reply-to;\n bh=G6cptW4xgoowbL/wXUAxEiIM+XeMaZNdf9RL4vJum2E=;\n b=s3pQZ6R5A1KssMQ5QwZgZMVQrc+oD3Oqr2KcUb6XLrYZQuZoBT5o4ioKwKPqIUDdbb\n 44a0uYEngJlJGUx71gozDXMlHEOvH11o0bJtOU7+7X4VW3YgOrQwSVNVmVrCW1wAOOzj\n VIDXEHddpJUUgivC0t/17hZMfbdnviZ495lTZeNoaDuAHPzjJd1IIMNncJeZxlf2GPpd\n 3PXZUT8uB+wEvApuoOetGJUagEhLBF6KU4+hbddP1zPvk1qA+3Az4OAKC4pDyuBKhUHv\n VO9wBkyfdDcjv/3I3t/Bix13eCIxOUVKLYOpu5puqxZwWXEMfNGpfC/7fjlh7tYa+gBn\n B/Rw==","X-Gm-Message-State":"AOJu0Yzh3zMZFqRBxcHXzA6apQPkrhJn/VFQ2x2Qrtfea5Peo9ojdQpi\n JVJpxvDljJiPfshZZM/zNJgWG3RJbz98fHMOHt6+fqco5+JwD4PyIj4T5EeZiUTZd55T5wA9GCK\n ZH8GkkqAoz+4dZT/jh+huhxYzyDUGwwAuikSv","X-Gm-Gg":"AeBDieslMAsXn4MRnw3wIAInlvr9IUQ0Ii2QSB3ThHYXqg9J24x/4n7UzCaBJxgB8I7\n NNsFfb0RvbF+6lkwREQPa/TRYcRJXmBcgUyPcFLDZloXHV+znaDi4ZFpe5+SC6/oQ3hG6RCdJe9\n gFuaEuZW3wN1WgKuRZZCMsqpa82uvGNNJUAnb2yf3bOw0nN2lwhtEDock863+u4diIeL2a1gRfv\n FnMoAtofRE5KtV8YHQ0/arIq8fqpqmdv/NiwcpQSqkdezhJrvrTQJOOohauJ7R6kxysUZl7yEzd\n EhPXtteuC4kEjwT3NTv1/Ajsn4BCD0QNiYftZaCHB9X001LxUkIKVA43eTqlLoX8btWHUCDLU7x\n mKIQ9AKNo/IL1E7icwlRHrZcayAuYjXvk775JiXNiCJfQvplG/X/lvjODb/bnBYGQvM+PcrWCLj\n zYj25b1RGISU1xYg==","X-Received":"by 2002:a17:907:980d:b0:ba3:4d21:92 with SMTP id\n a640c23a62f3a-ba41dd394abmr1220399566b.32.1776916053888; Wed, 22 Apr 2026\n 20:47:33 -0700 (PDT)","MIME-Version":"1.0","References":"<20260422164926.62177-1-marocketbd@gmail.com>\n <874il3lyig.fsf@gmail.com>\n <8a969ccf-d65c-466f-8740-1d39e7dd613f@linaro.org> <874il2l6tc.fsf@gmail.com>","In-Reply-To":"<874il2l6tc.fsf@gmail.com>","From":"Rocket Ma <marocketbd@gmail.com>","Date":"Thu, 23 Apr 2026 11:47:20 +0800","X-Gm-Features":"AQROBzCbp9m9DpOw1lrpdnHkFNWr0JZZ6E0jRTbceeL67Z96vXzBX5IJb7Yc988","Message-ID":"\n <CAO_32JqiqAgQ-+FCDg-ChrfRSncnroyZC9RqWeztVd7gzeQOxQ@mail.gmail.com>","Subject":"Re: [PATCH v2] misc: Optimize getusershell.c","To":"Collin Funk <collin.funk1@gmail.com>","Cc":"libc-alpha@sourceware.org,\n Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>","Content-Type":"text/plain; charset=\"UTF-8\"","X-BeenThere":"libc-alpha@sourceware.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Libc-alpha mailing list <libc-alpha.sourceware.org>","List-Unsubscribe":"<https://sourceware.org/mailman/options/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe>","List-Archive":"<https://sourceware.org/pipermail/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-request@sourceware.org?subject=help>","List-Subscribe":"<https://sourceware.org/mailman/listinfo/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=subscribe>","Errors-To":"libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org"}}]