From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 9D6AE3858D1E for ; Tue, 2 May 2023 17:13:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D6AE3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683047628; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=lX1J7TaSh9Qnr7UX3cKMSi9viAId797qjm6S52dMupo=; b=S7kW/4MuCoPVxWwZw+k9SEurATVqUBAg0tP0410h6o1LJtlNbLVsrt9AiwVWMFTwTYNadj B7wXBime0dJAawGZDFn8caq+aij/gxNF/q4j+HHXPwD0Dq39JpXgaFzZzVi7HjpLsRpUtq C7x622BjNZQE6pq6xqgLuFMi6ZzKRuU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-614-ASgaUzhJNh6EVQScSCSXKg-1; Tue, 02 May 2023 13:13:47 -0400 X-MC-Unique: ASgaUzhJNh6EVQScSCSXKg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C16E41066542; Tue, 2 May 2023 17:13:46 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.10]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EB742112132E; Tue, 2 May 2023 17:13:45 +0000 (UTC) From: Florian Weimer To: Luca Boccassi Cc: Adhemerval Zanella via Libc-alpha , Adhemerval Zanella Subject: Re: [PATCH v2 3/3] linux: Add pidfd_getpid References: <20230420142037.4063169-1-adhemerval.zanella@linaro.org> <20230420142037.4063169-4-adhemerval.zanella@linaro.org> <87r0rysomw.fsf@oldenburg.str.redhat.com> Date: Tue, 02 May 2023 19:13:44 +0200 In-Reply-To: (Luca Boccassi's message of "Tue, 2 May 2023 17:19:26 +0100") Message-ID: <87mt2mslkn.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: * Luca Boccassi: > On Tue, 2 May 2023 at 17:07, Florian Weimer wrote: >> >> * Adhemerval Zanella via Libc-alpha: >> > diff --git a/sysdeps/unix/sysv/linux/pidfd_getpid.c b/sysdeps/unix/sysv/linux/pidfd_getpid.c >> > new file mode 100644 >> > index 0000000000..d0c7987791 >> > --- /dev/null >> > +++ b/sysdeps/unix/sysv/linux/pidfd_getpid.c >> > @@ -0,0 +1,94 @@ >> >> > +static bool >> > +parse_fdinfo (const char *l, void *arg) >> > +{ >> > + enum { fieldlen = sizeof ("Pid:") - 1 }; >> > + if (strncmp (l, "Pid:", fieldlen) != 0) >> > + return true; >> > + >> > + l += fieldlen; >> > + >> > + char *endp; >> > + long int n = strtol (l, &endp, 10); >> > + if (l == endp || n > INT_MAX) >> > + return true; >> >> Should this use strtoul? Otherwise I'm not sure the overflow check will >> work on 32-bit. >> >> Rest of the implementation looks okay, but the kernel should really >> provide an ioctl or similar for this. > > This can be -1 when the process is gone, and it is important to get > that distinction (with certainty) to tell the caller ESRCH. We need > this distinction in callers. That shouldn't be a problem, strotul processes leading signs, too. The entire error checking is a bit dubious because it doesn't check much, considering strtol's general flexibility. Thanks, Florian