From nobody Fri Dec 17 05:21:04 2021 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 1AAF718EE75F for ; Fri, 17 Dec 2021 05:21:05 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JFclN5zyfz4nFD for ; Fri, 17 Dec 2021 05:21:04 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AE3DB15F5D for ; Fri, 17 Dec 2021 05:21:04 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 1BH5L4ZL072782 for ; Fri, 17 Dec 2021 05:21:04 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 1BH5L4c1072781 for bugs@FreeBSD.org; Fri, 17 Dec 2021 05:21:04 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 260487] sched_getaffinity(3)/sched_setaffinity(3): wrong handling of PID 0 Date: Fri, 17 Dec 2021 05:21:04 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: sigsys@gmail.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639718464; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=r2E1RWiTw5nCEjabhNng3w3+J9kHQzBk4ifNNKSTjDE=; b=YS6tIAMg3V7DHuFQeHZu6nrY18znlos3VqG8G+Y8r35pS9ucNFQHFXAILk8NCxOuzkuXmu l4sCwSzQrNzuETau22YtpuGGOHCmu9yag4oATyL5Edtvwm98IZ1nPPZif65AovxpCbG5V9 IQGniXyIakl64NZqgWDoWKcNv3GaiTDsUeoaAMYrFTW9hNrSYDQnBAh43fePT6DnXyJ7rz atq6pq8b50b8f/Q7A92fV3ERFBICKH8sUwem15+lfZ9MJFaAZkhsLjvrUHyvd5G9ADmnex w1cja/68J3JnNG7o8JP/VIDcneVvUUfGetscB3i1soa7JP6KyhF1jE2yrLCBBA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639718464; a=rsa-sha256; cv=none; b=fKFlHSz183Fd/sxn0ZpMM82bZ6+AbCJPLwh9e4HjZ54rVvPz3FfryxiIAK4HXU6gHjsaz1 3/ZR7rK6wFD/XNQgaLupmWs1EmB3IVYTA5FgzZUJqJpfXEhrJ2r+uUp7qnsBb19+LI5CI1 jNqeWGiNFnA0MHGFeVnXXzzWVpzTSu7nFdmR8krtFiSSL7UkQkvmEMV0GfJ3wpTYWa/i/F JSSvNvlhop9e6ugSvjZmqNVqM51QOo9gR4HKuiDPaUSNgc96rTjbGZx6Ep5Dzai44gWDPc lyYarziXTZZnLK70lUOiEdFZw1JVAGy6p8NBiU2WblvdsG8qMEE5EkH4Dn6Bxg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D260487 Bug ID: 260487 Summary: sched_getaffinity(3)/sched_setaffinity(3): wrong handling of PID 0 Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: bin Assignee: bugs@FreeBSD.org Reporter: sigsys@gmail.com sched_getaffinity(3)/sched_setaffinity(3) are documented to use PID 0 to re= fer to the current process, but the underlying cpuset_getaffinity(2)/cpuset_setaffinity(2) only do so with PID -1. I noticed FFmpeg library code passing PID 0 to sched_getaffinity(). diff --git a/lib/libc/gen/sched_getaffinity.c b/lib/libc/gen/sched_getaffinity.c index 5557d3d93b47..7fca53e39b4b 100644 --- a/lib/libc/gen/sched_getaffinity.c +++ b/lib/libc/gen/sched_getaffinity.c @@ -32,6 +32,6 @@ int sched_getaffinity(pid_t pid, size_t cpusetsz, cpuset_t *cpuset) { - return (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid, - cpusetsz, cpuset)); + return (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, + pid =3D=3D 0 ? -1 : pid, cpusetsz, cpuset)); } diff --git a/lib/libc/gen/sched_setaffinity.c b/lib/libc/gen/sched_setaffinity.c index ad775b5dbce5..1c083b4b108a 100644 --- a/lib/libc/gen/sched_setaffinity.c +++ b/lib/libc/gen/sched_setaffinity.c @@ -32,6 +32,6 @@ int sched_setaffinity(pid_t pid, size_t cpusetsz, const cpuset_t *cpuset) { - return (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid, - cpusetsz, cpuset)); + return (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, + pid =3D=3D 0 ? -1 : pid, cpusetsz, cpuset)); } --=20 You are receiving this mail because: You are the assignee for the bug.=