From patchwork Thu Jun 5 18:02:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 894195 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:ecd:b0:3a4:ee3f:8f15 with SMTP id ea13csp97185wrb; Thu, 5 Jun 2025 11:03:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUFW1Lqo8tHqrXe3bx4XaHTWu8b8nqN/6ZCghGZFfujP7B/4fqNbnnD2RHdsPdIdkIjoFKWfA==@linaro.org X-Google-Smtp-Source: AGHT+IGLE1asZjYXcUGhEMLnisx7PgOz0fQg4Fo6DeFEEFezQ4j3uWrfw2YLQw9JE/cCS9gTjm+5 X-Received: by 2002:a2e:a988:0:b0:32a:82d7:6d63 with SMTP id 38308e7fff4ca-32ae00a801cmr542861fa.12.1749146584326; Thu, 05 Jun 2025 11:03:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1749146584; cv=pass; d=google.com; s=arc-20240605; b=lRuzy5IyR6ab2XhV8i6kqXtHUExOmb9PYj8D6gt+TYgi6QoSI0wGCZfdThxKJsAaZQ +zXikAWdOjEjw6G1EANlQ0ilbHEGNcfEKyfGhUugwFjP3pgODu1NCLWQnBkSaeCW2Ltl IpV7k3OrGbQrCTMuqoVQn0pcnz2L2f1Bkbd8pFDFGz+9D8oOyZASy8okALenzAelGHHt v0HK3mKf+xYVMgwHZtJs7GKSuGTr75AMzyT5i1MwwM8K8sO7D9s1i79gNdg4FmsflFME Nik0SDu8WrVGhZLyHX8oEcsgI0s+BYrQdB5e7hqQg/sR4oL66tEqTwFEzaGvBIdlTZUz Kyug== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :dkim-filter:arc-filter:dmarc-filter:delivered-to:dkim-filter; bh=l5YE2ToWFcAdaNnyf/ONi0CE8JodY4EeIPLybGCYXB0=; fh=dHLBnA+MhGtNtN2B2JMAELi4oD+gmgMg7DL8H0jYbkI=; b=BATIWV/LA75ja1mBoGP/D0XuYUsn2gBzLSy9Di7i5DQ7oTrIvxMd6GshDNRjmZLGTH B3Hv2ndWIJj8YWTMu4j/r22EbDy3mOY8TByftBUkssQzxGawB5saoz7EbLzyi6KNZhc7 +hEHPwO9TwluvxS//NTbLGoticPHERIJgLgZC3TpIcKnUQXufNCVQkeEJs1srHpgpAMv MfPm3x+CUk6MoV2dw3khI0AfrvSrrTPF6yPiJRGUO6kZOcg9B2vx9o9OkD9YE/TTnf6T ++5aOq1GqrhJFOEAia6wmgOmi5KsHBQvPyDZSDxblhBngaInTlXZbi+MS3tcY9CJA22l ZFFQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tsiIJWL2; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 38308e7fff4ca-32a85bc6569si59531321fa.516.2025.06.05.11.03.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jun 2025 11:03:04 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tsiIJWL2; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A9B4385694F for ; Thu, 5 Jun 2025 18:03:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A9B4385694F Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=tsiIJWL2 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-vk1-xa33.google.com (mail-vk1-xa33.google.com [IPv6:2607:f8b0:4864:20::a33]) by sourceware.org (Postfix) with ESMTPS id 737DB3857706 for ; Thu, 5 Jun 2025 18:02:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 737DB3857706 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 737DB3857706 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::a33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749146557; cv=none; b=xh3fI6SO3jhpeN9CZbJhjYJwBgP1EXIuL1N4y9ckVyP46otGXQ8mn6GN3QbN4+owcgHGRVLwE8DE6T1C5DA1nvF7XX/chgb4d/NJNDjXdvfaaMn3CEh6/DRU6QtoqMdgXij/mG+do47YuA/cn/Y3XrlkNSgT2urMeVibUdiSBMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749146557; c=relaxed/simple; bh=HPgxCSu2AmUket2qx2J+K7WIRxTkxRnjeWuxO6EZvnY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vtNSkRSDEImq/5im5XTsWFBN+T1krG5ISmYfP1S8fQSMLPVtPC6WchAl2jbVNdqyXfi96tgRaa5ohhdvVE7DjP482fmVkWWqQtytetXHitrjz9sUHcKkDkeLNn3WgFK1Dw9Y9442A2F9jDT43lZsuDEm8ADzSitMtExvK3gWQV0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 737DB3857706 Received: by mail-vk1-xa33.google.com with SMTP id 71dfb90a1353d-525b44ec88aso438875e0c.3 for ; Thu, 05 Jun 2025 11:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1749146556; x=1749751356; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=l5YE2ToWFcAdaNnyf/ONi0CE8JodY4EeIPLybGCYXB0=; b=tsiIJWL2xhnToQ+jVVusekcTzHIHc85oADga0zIgwQOiPX5AyzxAUoVCEM6jfJUd9E IlASfWj58LLWyQm6nRjvVCVTIvrTFKogqVsPAAAT/2iFszvMqnCdm2JulqlYVrQWVQCj kHeDlPo3xf9Ay5PVBGy5aw0EIOarL6TwOgU60ZdkOoHsJbECOsuHWHCnsvW+KruSBzWQ dOmddwN08dT8nF19Pvju4FmP9lwsgcdhOEGdc89LC6CxTewEWlJP9zY6lklOScN9GjJ2 S72DtorMbytgTvlTSDWy5EKQehArz15TXkqai/f6CHmNCm10tnGPKU92hi1WlFdHa15b yflA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749146556; x=1749751356; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=l5YE2ToWFcAdaNnyf/ONi0CE8JodY4EeIPLybGCYXB0=; b=u5VLABjHzVO8xFsV8Sf+LMnr+g/twjmQN6nsGUVvXmk0ukonKBx92GuPCMkiZsZVmP +FECmjN/P/sluQ1Ohh8l43LVhP+ycytLMMg5NgR9svdbb1pWo3RX12SInZQNVx5EHT7g 4lWTz10pKCySSEeSWlBhQgvGFJzskoxc3+TRSLDUNowNjtsHR4A5sDobYBipLqDOCRvk B3AvRaZz2Jlv7ai8eFAQGiWCuXzEzCYF1IE/7nNBzfEIY4PO5OwZRqHbWnuo/vGl9xdU /KtpuRyZTwKBFZqEeBbeG6sd8PavHcyjE7NVC12hBUJd2qqNHpxMqigXy4dbJHHgwXCz G7iQ== X-Gm-Message-State: AOJu0YzZQaf7cMgvsYqn8qrwCCTc36sfzfQehc8hJShWVYCKV2ZP7DRe GVhQgO3WIA9w0+6SZQuchfDsH2qV/mK7wrvlhJWCNwovlo9mOaoJhbZw0cF46Bca8I9BvwTkNa4 9xEfU X-Gm-Gg: ASbGncshjxsnUdaeng1boReHbVx2sAva06/92UyaypjGPCZkdoGUME92ePrp+fVdf8F Ug7KvI8GfR2wyEkC9U3q6SrslChQLsqm+2ff8lso2I1KsmJyqAxdp9edUkDlcHb0TMf2cj/dpN4 ba4d0oMrPtXdNmURsE7l7OW4xr6mtbVdQWiZfnWOGo9vbRriRKYOFfpbOVSYfk1MLt4n0vnVAML 0B3xRyHtrXv9KyKX3E4Fy42/fwsH1/jREpdJBonbXcaFQciQwRgKuwebKbosYhGhHOLd/2Vg0IL rueBViHHxMGYMubmPBDsTgtsb8TSJ5nRZ0YaGAkRRJvJ4Qb8b+aAogAnd0nE/C8= X-Received: by 2002:a05:6122:6588:b0:530:63d9:115a with SMTP id 71dfb90a1353d-530e47dc2fdmr709874e0c.4.1749146555562; Thu, 05 Jun 2025 11:02:35 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:8c5f:395a:7eb3:11e:d37c]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-53074b06741sm13054045e0c.21.2025.06.05.11.02.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jun 2025 11:02:35 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] posix: Add posix_spawn extension to setup resource limits (BZ 31049) Date: Thu, 5 Jun 2025 15:02:14 -0300 Message-ID: <20250605180231.1427626-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patch=linaro.org@sourceware.org This patch adds two new functions: int posix_spawnattr_setrlimit_np (posix_spawnattr_t *restrict __attr, int resource, const struct rlimit *rlim); int posix_spawnattr_getrlimit_np (posix_spawnattr_t *__restrict __attr, int resource, struct rlimit *rlim) Along with a new POSIX_SPAWN_SETRLIMIT flag. It allows to setup the new process resource limits, similar to call setlimit/prlimit before execve. It work for both posix_spawn and pidfd_spawn. To create a process with a resource limit, one can use the: posix_spawnattr_t attr; posix_spawnattr_init (&attr); posix_spawnattr_setflags (&attr, POSIX_SPAWN_SETRLIMIT); posix_spawnattr_setrlimit_np (&attr, RLIMIT_STACK, & (const struct rlimit) { RLIM_INFINITY, RLIM_INFINITY }); posix_spawn (...); The resources limits are applied after the effective user and group IDs change (POSIX_SPAWN_RESETIDS) and before the file actions. Only LFS supported is provided (non-LFS prototypes are not exported or implemented). Checked on x86_64-linux-gnu and aarch64-linux-gnu. --- NEWS | 6 + bits/resource.h | 7 +- include/sys/resource.h | 3 + posix/Makefile | 6 + posix/Versions | 4 + posix/spawn.h | 16 ++ posix/spawn_int.h | 3 + posix/spawnattr_destroy.c | 6 +- posix/spawnattr_getrlimit_np.c | 46 ++++ posix/spawnattr_setflags.c | 3 +- posix/spawnattr_setrlimit_np.c | 54 +++++ posix/tst-spawn8.c | 226 ++++++++++++++++++ resource/setrlimit64.c | 4 +- sysdeps/mach/hurd/bits/typesizes.h | 5 + sysdeps/mach/hurd/i386/libc.abilist | 2 + sysdeps/mach/hurd/spawni.c | 14 ++ sysdeps/mach/hurd/x86_64/libc.abilist | 4 +- sysdeps/unix/sysv/linux/Makefile | 4 + sysdeps/unix/sysv/linux/aarch64/libc.abilist | 2 + sysdeps/unix/sysv/linux/alpha/bits/resource.h | 7 +- sysdeps/unix/sysv/linux/alpha/libc.abilist | 2 + sysdeps/unix/sysv/linux/alpha/setrlimit64.c | 2 +- sysdeps/unix/sysv/linux/arc/libc.abilist | 2 + sysdeps/unix/sysv/linux/arm/be/libc.abilist | 2 + sysdeps/unix/sysv/linux/arm/le/libc.abilist | 2 + sysdeps/unix/sysv/linux/bits/resource.h | 7 +- sysdeps/unix/sysv/linux/csky/libc.abilist | 2 + sysdeps/unix/sysv/linux/hppa/libc.abilist | 2 + sysdeps/unix/sysv/linux/i386/libc.abilist | 2 + .../sysv/linux/loongarch/lp64/libc.abilist | 2 + .../sysv/linux/m68k/coldfire/libc.abilist | 2 + .../unix/sysv/linux/m68k/m680x0/libc.abilist | 2 + .../sysv/linux/microblaze/be/libc.abilist | 2 + .../sysv/linux/microblaze/le/libc.abilist | 2 + sysdeps/unix/sysv/linux/mips/bits/resource.h | 7 +- .../sysv/linux/mips/mips32/fpu/libc.abilist | 2 + .../sysv/linux/mips/mips64/n32/libc.abilist | 2 + .../sysv/linux/mips/mips64/n64/libc.abilist | 2 + sysdeps/unix/sysv/linux/or1k/libc.abilist | 2 + .../linux/powerpc/powerpc32/fpu/libc.abilist | 2 + .../powerpc/powerpc32/nofpu/libc.abilist | 2 + .../linux/powerpc/powerpc64/be/libc.abilist | 2 + .../linux/powerpc/powerpc64/le/libc.abilist | 2 + .../unix/sysv/linux/riscv/rv32/libc.abilist | 2 + .../unix/sysv/linux/riscv/rv64/libc.abilist | 2 + .../unix/sysv/linux/s390/s390-32/libc.abilist | 2 + .../unix/sysv/linux/s390/s390-64/libc.abilist | 2 + sysdeps/unix/sysv/linux/setrlimit64.c | 7 +- sysdeps/unix/sysv/linux/sh/be/libc.abilist | 2 + sysdeps/unix/sysv/linux/sh/le/libc.abilist | 2 + sysdeps/unix/sysv/linux/sparc/bits/resource.h | 7 +- .../sysv/linux/sparc/sparc32/libc.abilist | 2 + .../sysv/linux/sparc/sparc64/libc.abilist | 2 + sysdeps/unix/sysv/linux/spawni.c | 14 ++ sysdeps/unix/sysv/linux/tst-spawn8-pidfd.c | 20 ++ .../unix/sysv/linux/x86_64/64/libc.abilist | 2 + .../unix/sysv/linux/x86_64/x32/libc.abilist | 2 + 57 files changed, 531 insertions(+), 15 deletions(-) create mode 100644 posix/spawnattr_getrlimit_np.c create mode 100644 posix/spawnattr_setrlimit_np.c create mode 100644 posix/tst-spawn8.c create mode 100644 sysdeps/unix/sysv/linux/tst-spawn8-pidfd.c diff --git a/NEWS b/NEWS index afe8076dfc..e6de652859 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,12 @@ Major new features: * The ISO C2Y family of unsigned abs functions, i.e. uabs, ulabs, ullabs and uimaxabs, are now supported. +* The functions posix_spawnattr_getrlimit_np and + posix_spawnattr_setrlimit_np have been added, along with the + POSIX_SPAWN_SETRLIMIT flag. They allow posix_spawn, posix_spawnp, + pidfd_spawn, and pidfd_spawnp to set a process resource limit in the new + process, similiar to setrlimit or prlimit. + Deprecated and removed features, and other changes affecting compatibility: * The glibc.rtld.execstack now supports a compatibility mode to allow diff --git a/bits/resource.h b/bits/resource.h index a42a338b44..f4ff02ebcc 100644 --- a/bits/resource.h +++ b/bits/resource.h @@ -16,7 +16,10 @@ License along with the GNU C Library; if not, see . */ -#ifndef _SYS_RESOURCE_H +#ifndef _BITS_RESOURCE_H +#define _BITS_RESOURCE_H + +#if !defined _SYS_RESOURCE_H && !defined _SPAWN_H # error "Never use directly; include instead." #endif @@ -151,3 +154,5 @@ enum __priority_which PRIO_USER = 2 /* WHO is a user ID. */ #define PRIO_USER PRIO_USER }; + +#endif diff --git a/include/sys/resource.h b/include/sys/resource.h index 21d3908714..b1f019a4d1 100644 --- a/include/sys/resource.h +++ b/include/sys/resource.h @@ -135,6 +135,9 @@ extern int __setrlimit (enum __rlimit_resource __resource, const struct rlimit *__rlimits) __nonnull ((2)); libc_hidden_proto (__setrlimit); +extern __typeof (setrlimit64) __setrlimit64; +libc_hidden_proto (__setrlimit64); + #if __TIMESIZE == 64 # define __getrusage64 __getrusage # define __wait4_time64 __wait4 diff --git a/posix/Makefile b/posix/Makefile index 240de15123..395d817112 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -161,6 +161,7 @@ routines := \ spawnattr_getdefault \ spawnattr_getflags \ spawnattr_getpgroup \ + spawnattr_getrlimit_np \ spawnattr_getschedparam \ spawnattr_getschedpolicy \ spawnattr_getsigmask \ @@ -168,6 +169,7 @@ routines := \ spawnattr_setdefault \ spawnattr_setflags \ spawnattr_setpgroup \ + spawnattr_setrlimit_np \ spawnattr_setschedparam \ spawnattr_setschedpolicy \ spawnattr_setsigmask \ @@ -317,6 +319,7 @@ tests := \ tst-spawn5 \ tst-spawn6 \ tst-spawn7 \ + tst-spawn8 \ tst-sysconf \ tst-sysconf-empty-chroot \ tst-truncate \ @@ -601,6 +604,8 @@ CFLAGS-fork.c = $(libio-mtsafe) $(config-cflags-wno-ignored-attributes) tstgetopt-ARGS = -a -b -cfoobar --required foobar --optional=bazbug \ --none random --col --color --colour +CFLAGS-tst-spawn8.c += -D_FILE_OFFSET_BITS=64 + tst-exec-ARGS = -- $(host-test-program-cmd) tst-exec-static-ARGS = $(tst-exec-ARGS) tst-execvpe5-ARGS = -- $(host-test-program-cmd) @@ -609,6 +614,7 @@ tst-spawn-static-ARGS = $(tst-spawn-ARGS) tst-spawn5-ARGS = -- $(host-test-program-cmd) tst-spawn6-ARGS = -- $(host-test-program-cmd) tst-spawn7-ARGS = -- $(host-test-program-cmd) +tst-spawn8-ARGS = -- $(host-test-program-cmd) tst-posix_spawn-setsid-ARGS = -- $(host-test-program-cmd) tst-dir-ARGS = `pwd` `cd $(common-objdir)/$(subdir); pwd` `cd $(common-objdir); pwd` $(objpfx)tst-dir tst-chmod-ARGS = $(objdir) diff --git a/posix/Versions b/posix/Versions index 0624d24bcc..c741ce425c 100644 --- a/posix/Versions +++ b/posix/Versions @@ -159,6 +159,10 @@ libc { GLIBC_2.35 { posix_spawn_file_actions_addtcsetpgrp_np; } + GLIBC_2.42 { + posix_spawnattr_setrlimit_np; + posix_spawnattr_getrlimit_np; + } GLIBC_PRIVATE { __libc_fork; __libc_pread; __libc_pwrite; __nanosleep_nocancel; __pause_nocancel; diff --git a/posix/spawn.h b/posix/spawn.h index a2ff3fa4a2..bed7c0102f 100644 --- a/posix/spawn.h +++ b/posix/spawn.h @@ -59,6 +59,7 @@ typedef struct # define POSIX_SPAWN_USEVFORK 0x40 # define POSIX_SPAWN_SETSID 0x80 # define POSIX_SPAWN_SETCGROUP 0x100 +# define POSIX_SPAWN_SETRLIMIT 0x200 #endif @@ -199,6 +200,21 @@ extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t * __THROW __nonnull ((1)); #ifdef __USE_MISC + +#include + +#if __RLIM_T_MATCHES_RLIM64_T || defined __USE_FILE_OFFSET64 +extern int posix_spawnattr_setrlimit_np (posix_spawnattr_t *__restrict __attr, + int __resource, + const struct rlimit *__rlim) + __THROW __nonnull ((1, 3)); + +extern int posix_spawnattr_getrlimit_np (posix_spawnattr_t *__restrict __attr, + int __resource, + struct rlimit *__rlim) + __THROW __nonnull ((1, 3)); +#endif + /* Add an action changing the directory to PATH during spawn. This affects the subsequent file actions. */ extern int posix_spawn_file_actions_addchdir_np (posix_spawn_file_actions_t * diff --git a/posix/spawn_int.h b/posix/spawn_int.h index 2af524fad6..6b25cebff9 100644 --- a/posix/spawn_int.h +++ b/posix/spawn_int.h @@ -22,6 +22,7 @@ #include #include #include +#include struct __spawn_attr { @@ -36,6 +37,8 @@ struct __spawn_attr struct sched_param __sp; int __policy; int __cgroup; + uint32_t __rlimitset; + struct rlimit64 *__rlimits; }; char __size[__SIZEOF_POSIX_SPAWNATTR_T]; }; diff --git a/posix/spawnattr_destroy.c b/posix/spawnattr_destroy.c index bae3fc38cb..e1ec29e635 100644 --- a/posix/spawnattr_destroy.c +++ b/posix/spawnattr_destroy.c @@ -16,12 +16,16 @@ . */ #include +#include +#include /* Initialize data structure for file attribute for `spawn' call. */ int __posix_spawnattr_destroy (posix_spawnattr_t *attr) { - /* Nothing to do in the moment. */ + struct __spawn_attr *at = (struct __spawn_attr *) attr; + free (at->__rlimits); + return 0; } weak_alias (__posix_spawnattr_destroy, posix_spawnattr_destroy) diff --git a/posix/spawnattr_getrlimit_np.c b/posix/spawnattr_getrlimit_np.c new file mode 100644 index 0000000000..349dc1eee6 --- /dev/null +++ b/posix/spawnattr_getrlimit_np.c @@ -0,0 +1,46 @@ +/* Implement posix_spawn extension to setup resource limits. + Copyright (C) 2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +int +__posix_spawnattr_getrlimit_np (posix_spawnattr_t *__restrict attr, + int resource, +#if __RLIM_T_MATCHES_RLIM64_T + struct rlimit *rlim +#else + struct rlimit64 *rlim +#endif + ) +{ + if (resource < 0 || resource >= RLIM_NLIMITS) + return EINVAL; + + struct __spawn_attr *at = (struct __spawn_attr *) attr; + if (!(at->__rlimitset & (1u << resource))) + return ENOENT; + + rlim->rlim_cur = at->__rlimits[resource].rlim_cur; + rlim->rlim_max = at->__rlimits[resource].rlim_max; + + return 0; +} +weak_alias (__posix_spawnattr_getrlimit_np, posix_spawnattr_getrlimit_np) diff --git a/posix/spawnattr_setflags.c b/posix/spawnattr_setflags.c index bbe5838b9f..186c1ca17d 100644 --- a/posix/spawnattr_setflags.c +++ b/posix/spawnattr_setflags.c @@ -28,7 +28,8 @@ | POSIX_SPAWN_SETSCHEDULER \ | POSIX_SPAWN_SETSID \ | POSIX_SPAWN_USEVFORK \ - | POSIX_SPAWN_SETCGROUP) + | POSIX_SPAWN_SETCGROUP \ + | POSIX_SPAWN_SETRLIMIT) /* Store flags in the attribute structure. */ int diff --git a/posix/spawnattr_setrlimit_np.c b/posix/spawnattr_setrlimit_np.c new file mode 100644 index 0000000000..b6a748835b --- /dev/null +++ b/posix/spawnattr_setrlimit_np.c @@ -0,0 +1,54 @@ +/* Implement posix_spawn extension to setup resource limits. + Copyright (C) 2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +/* Initialize data structure for file attribute for `spawn' call. */ +int +__posix_spawnattr_setrlimit_np (posix_spawnattr_t *__restrict attr, + int resource, +#if __RLIM_T_MATCHES_RLIM64_T + const struct rlimit *rlim +#else + const struct rlimit64 *rlim +#endif + ) +{ + if (resource < 0 || resource >= RLIM_NLIMITS) + return EINVAL; + + struct __spawn_attr *at = (struct __spawn_attr *) attr; + + if (at->__rlimits == NULL) + { + at->__rlimits = __libc_reallocarray (at->__rlimits, RLIM_NLIMITS, + sizeof (struct rlimit64)); + if (at->__rlimits == NULL) + return ENOMEM; + } + + at->__rlimitset |= 1u << resource; + at->__rlimits[resource].rlim_cur = rlim->rlim_cur; + at->__rlimits[resource].rlim_max = rlim->rlim_max; + + return 0; +} +weak_alias (__posix_spawnattr_setrlimit_np, posix_spawnattr_setrlimit_np) diff --git a/posix/tst-spawn8.c b/posix/tst-spawn8.c new file mode 100644 index 0000000000..263d033fb9 --- /dev/null +++ b/posix/tst-spawn8.c @@ -0,0 +1,226 @@ +/* Tests for posix_spawn resource limit set. + Copyright (C) 2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CMDLINE_OPTIONS \ + { "restart", no_argument, &restart, 1 }, +static int restart; + +#pragma GCC optimize ("O0") + +static char *spargs[4 /* The four initial arguments. */ + + 1 /* The extra --direct. */ + + 1 /* The extra --restart. */ + + RLIM_NLIMITS /* The resources to check. */ + + RLIM_NLIMITS /* The soft limit. */ + + RLIM_NLIMITS /* The maximum limit. */ + + 1 /* The final NULL. */]; +static int start_args; + +_Noreturn static void +handle_restart (int argc, char *argv[]) +{ + TEST_VERIFY_EXIT (argc % 3 == 0); + + for (int i = 0; i < argc; i += 3) + { + int resource; + { + char *endp; + resource = strtol (argv[0], &endp, 10); + TEST_VERIFY (endp != argv[0]); + } + TEST_VERIFY_EXIT (resource < RLIM_NLIMITS); + rlim64_t cur; + { + char *endp; + cur = strtoumax (argv[1], &endp, 10); + TEST_VERIFY (endp != argv[1]); + } + rlim64_t max; + { + char *endp; + max = strtoumax (argv[2], &endp, 10); + TEST_VERIFY (endp != argv[2]); + } + + struct rlimit rlimit; + TEST_VERIFY_EXIT (getrlimit (resource, &rlimit) == 0); + TEST_COMPARE (rlimit.rlim_cur, cur); + TEST_COMPARE (rlimit.rlim_max, max); + } + + exit (EXIT_SUCCESS); +} + +static int +do_basic_test (void) +{ + { + posix_spawnattr_t attr; + TEST_COMPARE (posix_spawnattr_init (&attr), 0); + TEST_COMPARE (posix_spawnattr_getrlimit_np (&attr, -1, + &(struct rlimit) {}), + EINVAL); + TEST_COMPARE (posix_spawnattr_getrlimit_np (&attr, RLIM_NLIMITS, + &(struct rlimit) {}), + EINVAL); + TEST_COMPARE (posix_spawnattr_destroy (&attr), 0); + } + + for (int i = 0; i < RLIM_NLIMITS; i++) + { + posix_spawnattr_t attr; + + TEST_COMPARE (posix_spawnattr_init (&attr), 0); + + /* Query a non initialized resource. */ + TEST_COMPARE (posix_spawnattr_getrlimit_np (&attr, i, + &(struct rlimit) {}), + ENOENT); + + /* Set the value. */ + TEST_COMPARE (posix_spawnattr_setrlimit_np (&attr, i, + &(const struct rlimit) + { 0, RLIM_INFINITY }), 0); + { + struct rlimit rlim; + TEST_COMPARE (posix_spawnattr_getrlimit_np (&attr, i, &rlim), + 0); + TEST_COMPARE (rlim.rlim_cur, 0); + TEST_COMPARE (rlim.rlim_max, RLIM_INFINITY); + } + + /* Query a valid, but not already set value. */ + if (i != RLIM_NLIMITS - 1) + TEST_COMPARE (posix_spawnattr_getrlimit_np (&attr, i + 1, + &(struct rlimit) {}), + ENOENT); + + /* Overwrite the resource value. */ + TEST_COMPARE (posix_spawnattr_setrlimit_np (&attr, i, + &(const struct rlimit) + { RLIM_INFINITY, 0 }), 0); + { + struct rlimit rlim; + TEST_COMPARE (posix_spawnattr_getrlimit_np (&attr, i, &rlim), + 0); + TEST_COMPARE (rlim.rlim_cur, RLIM_INFINITY); + TEST_COMPARE (rlim.rlim_max, 0); + } + + TEST_COMPARE (posix_spawnattr_destroy (&attr), 0); + } + + return 0; +} + +static int +do_test_spawn (void) +{ + struct rlimit rlimits[RLIM_NLIMITS]; + for (int i = 0; i < RLIM_NLIMITS; i++) + TEST_VERIFY_EXIT (getrlimit (i, &rlimits[i]) == 0); + + char resource_str[RLIM_NLIMITS][INT_STRLEN_BOUND (int)]; + char cur_limit_str[RLIM_NLIMITS][INT_STRLEN_BOUND (uintmax_t)]; + char max_limit_str[RLIM_NLIMITS][INT_STRLEN_BOUND (uintmax_t)]; + + posix_spawnattr_t attr; + TEST_COMPARE (posix_spawnattr_init (&attr), 0); + + int argc = start_args; + for (int i = 0; i < RLIM_NLIMITS; i++) + { + if (rlimits[i].rlim_max == 0) + continue; + + rlimits[i].rlim_cur /= 2; + rlimits[i].rlim_max /= 2; + + TEST_COMPARE (posix_spawnattr_setrlimit_np (&attr, i, &rlimits[i]), 0); + + snprintf (resource_str[i], sizeof resource_str[i], "%d", i); + snprintf (cur_limit_str[i], sizeof cur_limit_str[i], "%ju", + (uintmax_t) rlimits[i].rlim_cur); + snprintf (max_limit_str[i], sizeof max_limit_str[i], "%ju", + (uintmax_t) rlimits[i].rlim_max); + + spargs[argc++] = resource_str[i]; + spargs[argc++] = cur_limit_str[i]; + spargs[argc++] = max_limit_str[i]; + } + spargs[argc] = NULL; + + TEST_COMPARE (posix_spawnattr_setflags (&attr, POSIX_SPAWN_SETRLIMIT), 0); + + PID_T_TYPE pid; + TEST_COMPARE (POSIX_SPAWN (&pid, spargs[0], NULL, &attr, spargs, environ), + 0); + + TEST_COMPARE (posix_spawnattr_destroy (&attr), 0); + + siginfo_t sinfo; + TEST_COMPARE (WAITID (P_ALL, 0, &sinfo, WEXITED), 0); + TEST_COMPARE (sinfo.si_code, CLD_EXITED); + TEST_COMPARE (sinfo.si_status, 0); + + return 0; +} + +static int +do_test (int argc, char *argv[]) +{ + if (restart) + handle_restart (argc - 1, &argv[1]); + TEST_VERIFY_EXIT (argc == 2 || argc == 5); + + do_basic_test (); + + { + int i; + for (i = 0; i < argc - 1; i++) + spargs[i] = argv[i + 1]; + spargs[i++] = (char *) "--direct"; + spargs[i++] = (char *) "--restart"; + start_args = i; + } + + do_test_spawn (); + + return 0; +} + + +#define TEST_FUNCTION_ARGV do_test +#include diff --git a/resource/setrlimit64.c b/resource/setrlimit64.c index 25fe5f1bb7..d28bf399f1 100644 --- a/resource/setrlimit64.c +++ b/resource/setrlimit64.c @@ -23,7 +23,7 @@ Only the super-user can increase hard limits. Return 0 if successful, -1 if not (and sets errno). */ int -setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits) +__setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits) { struct rlimit rlimits32; @@ -38,3 +38,5 @@ setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits) return __setrlimit (resource, &rlimits32); } +libc_hidden_def (__setrlimit64) +weak_alias (__setrlimit64, setrlimit64) diff --git a/sysdeps/mach/hurd/bits/typesizes.h b/sysdeps/mach/hurd/bits/typesizes.h index 6192bb1243..38c22742f2 100644 --- a/sysdeps/mach/hurd/bits/typesizes.h +++ b/sysdeps/mach/hurd/bits/typesizes.h @@ -69,5 +69,10 @@ fsfilcnt64_t are not the same type for all ABI purposes. */ # define __STATFS_MATCHES_STATFS64 0 +#ifdef __LP64__ +# define __RLIM_T_MATCHES_RLIM64_T 1 +#else +# define __RLIM_T_MATCHES_RLIM64_T 0 +#endif #endif /* bits/typesizes.h */ diff --git a/sysdeps/mach/hurd/i386/libc.abilist b/sysdeps/mach/hurd/i386/libc.abilist index 3e183f5c02..5a9d173c01 100644 --- a/sysdeps/mach/hurd/i386/libc.abilist +++ b/sysdeps/mach/hurd/i386/libc.abilist @@ -2586,6 +2586,8 @@ GLIBC_2.41 pthread_mutexattr_settype F GLIBC_2.41 pthread_sigmask F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_barrier_destroy F GLIBC_2.42 pthread_barrier_init F GLIBC_2.42 pthread_barrier_wait F diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/spawni.c index b1f934b0dd..d8c574ff51 100644 --- a/sysdeps/mach/hurd/spawni.c +++ b/sysdeps/mach/hurd/spawni.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "spawn_int.h" /* Spawn a new process executing PATH with the attributes describes in *ATTRP. @@ -478,6 +479,19 @@ retry: } __mutex_unlock (&_hurd_dtable_lock); + /* Set the process resource limits. */ + if ((attrp->__flags & POSIX_SPAWN_SETRLIMIT) != 0) + { + uint32_t rlimitset = attrp->__rlimitset; + while (rlimitset != 0) + { + int resource = stdc_trailing_zeros (rlimitset); + if (__setrlimit64 (resource, &attrp->__rlimits[resource]) == -1) + goto out; + rlimitset &= ~(1u << resource); + } + } + /* Safe to let signals happen now. */ _hurd_critical_section_unlock (ss); diff --git a/sysdeps/mach/hurd/x86_64/libc.abilist b/sysdeps/mach/hurd/x86_64/libc.abilist index 688ee26f4b..4d4afa0769 100644 --- a/sysdeps/mach/hurd/x86_64/libc.abilist +++ b/sysdeps/mach/hurd/x86_64/libc.abilist @@ -607,7 +607,7 @@ GLIBC_2.38 _libc_intl_domainname D 0x5 GLIBC_2.38 _longjmp F GLIBC_2.38 _mcleanup F GLIBC_2.38 _mcount F -GLIBC_2.38 _nl_default_dirname D 0xe +GLIBC_2.38 _nl_default_dirname D 0x12 GLIBC_2.38 _nl_domain_bindings D 0x8 GLIBC_2.38 _nl_msg_cat_cntr D 0x4 GLIBC_2.38 _obstack_allocated_p F @@ -2269,6 +2269,8 @@ GLIBC_2.41 pthread_mutexattr_settype F GLIBC_2.41 pthread_sigmask F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_barrier_destroy F GLIBC_2.42 pthread_barrier_init F GLIBC_2.42 pthread_barrier_wait F diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index ebcf820403..42af360440 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -536,6 +536,7 @@ tests += \ tst-spawn5-pidfd \ tst-spawn6-pidfd \ tst-spawn7-pidfd \ + tst-spawn8-pidfd \ # tests tests-static += \ @@ -551,11 +552,14 @@ CFLAGS-getpid.o = -fomit-frame-pointer CFLAGS-getpid.os = -fomit-frame-pointer CFLAGS-tst-spawn3-pidfd.c += -DOBJPFX=\"$(objpfx)\" +CFLAGS-tst-spawn8-pidfd.c += -D_FILE_OFFSET_BITS=64 + tst-spawn-cgroup-ARGS = -- $(host-test-program-cmd) tst-spawn-pidfd-ARGS = -- $(host-test-program-cmd) tst-spawn5-pidfd-ARGS = -- $(host-test-program-cmd) tst-spawn6-pidfd-ARGS = -- $(host-test-program-cmd) tst-spawn7-pidfd-ARGS = -- $(host-test-program-cmd) +tst-spawn8-pidfd-ARGS = -- $(host-test-program-cmd) tst-posix_spawn-setsid-pidfd-ARGS = -- $(host-test-program-cmd) endif diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist index aa6bf483dd..d0d856532e 100644 --- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist +++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist @@ -2752,6 +2752,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/alpha/bits/resource.h b/sysdeps/unix/sysv/linux/alpha/bits/resource.h index 225ed98915..9c7a44a91c 100644 --- a/sysdeps/unix/sysv/linux/alpha/bits/resource.h +++ b/sysdeps/unix/sysv/linux/alpha/bits/resource.h @@ -16,7 +16,10 @@ License along with the GNU C Library. If not, see . */ -#ifndef _SYS_RESOURCE_H +#ifndef _BITS_RESOURCE_H +#define _BITS_RESOURCE_H + +#if !defined _SYS_RESOURCE_H && !defined _SPAWN_H # error "Never use directly; include instead." #endif @@ -221,3 +224,5 @@ extern int prlimit64 (__pid_t __pid, enum __rlimit_resource __resource, #endif __END_DECLS + +#endif diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist index d5df9656a8..2378442fe8 100644 --- a/sysdeps/unix/sysv/linux/alpha/libc.abilist +++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist @@ -3099,6 +3099,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/alpha/setrlimit64.c b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c index fd6c50cb27..d340164a8a 100644 --- a/sysdeps/unix/sysv/linux/alpha/setrlimit64.c +++ b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c @@ -17,7 +17,7 @@ #define USE_VERSIONED_RLIMIT #include -versioned_symbol (libc, __setrlimit, setrlimit, GLIBC_2_27); +versioned_symbol (libc, __setrlimit64, setrlimit, GLIBC_2_27); versioned_symbol (libc, __setrlimit64, setrlimit64, GLIBC_2_27); #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_27) diff --git a/sysdeps/unix/sysv/linux/arc/libc.abilist b/sysdeps/unix/sysv/linux/arc/libc.abilist index c46c08da85..c884f7764a 100644 --- a/sysdeps/unix/sysv/linux/arc/libc.abilist +++ b/sysdeps/unix/sysv/linux/arc/libc.abilist @@ -2513,6 +2513,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/arm/be/libc.abilist b/sysdeps/unix/sysv/linux/arm/be/libc.abilist index 4df150c0f0..fef1b8d2ff 100644 --- a/sysdeps/unix/sysv/linux/arm/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/arm/be/libc.abilist @@ -2805,6 +2805,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/arm/le/libc.abilist b/sysdeps/unix/sysv/linux/arm/le/libc.abilist index be294783f6..f03c28c065 100644 --- a/sysdeps/unix/sysv/linux/arm/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/arm/le/libc.abilist @@ -2802,6 +2802,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/bits/resource.h b/sysdeps/unix/sysv/linux/bits/resource.h index 51c07da019..8cbd494432 100644 --- a/sysdeps/unix/sysv/linux/bits/resource.h +++ b/sysdeps/unix/sysv/linux/bits/resource.h @@ -16,7 +16,10 @@ License along with the GNU C Library; if not, see . */ -#ifndef _SYS_RESOURCE_H +#ifndef _BITS_RESOURCE_H +#define _BITS_RESOURCE_H + +#if !defined _SYS_RESOURCE_H && !defined _SPAWN_H # error "Never use directly; include instead." #endif @@ -221,3 +224,5 @@ extern int prlimit64 (__pid_t __pid, enum __rlimit_resource __resource, #endif __END_DECLS + +#endif diff --git a/sysdeps/unix/sysv/linux/csky/libc.abilist b/sysdeps/unix/sysv/linux/csky/libc.abilist index f123757134..5133b265a9 100644 --- a/sysdeps/unix/sysv/linux/csky/libc.abilist +++ b/sysdeps/unix/sysv/linux/csky/libc.abilist @@ -2789,6 +2789,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist index 2dc85b9533..984b55f31c 100644 --- a/sysdeps/unix/sysv/linux/hppa/libc.abilist +++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist @@ -2826,6 +2826,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist index 1e38217ec6..863dc10ad8 100644 --- a/sysdeps/unix/sysv/linux/i386/libc.abilist +++ b/sysdeps/unix/sysv/linux/i386/libc.abilist @@ -3009,6 +3009,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist b/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist index 927fc21445..5cb5864b71 100644 --- a/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist +++ b/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist @@ -2273,6 +2273,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist index 74da49d9da..e84db96f17 100644 --- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist +++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist @@ -2785,6 +2785,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist index e5d678111f..fdb16fdb6a 100644 --- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist +++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist @@ -2952,6 +2952,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist index 4dbd4b6045..2db46c6479 100644 --- a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist @@ -2838,6 +2838,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist index c5965bb50c..715333baf0 100644 --- a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist @@ -2835,6 +2835,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/mips/bits/resource.h b/sysdeps/unix/sysv/linux/mips/bits/resource.h index 05f8e6ad35..50b9239ea8 100644 --- a/sysdeps/unix/sysv/linux/mips/bits/resource.h +++ b/sysdeps/unix/sysv/linux/mips/bits/resource.h @@ -16,7 +16,10 @@ License along with the GNU C Library. If not, see . */ -#ifndef _SYS_RESOURCE_H +#ifndef _BITS_RESOURCE_H +#define _BITS_RESOURCE_H + +#if !defined _SYS_RESOURCE_H && !defined _SPAWN_H # error "Never use directly; include instead." #endif @@ -229,3 +232,5 @@ extern int prlimit64 (__pid_t __pid, enum __rlimit_resource __resource, #endif __END_DECLS + +#endif diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist index 10715e0777..78b2343bb8 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist @@ -2913,6 +2913,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist index e4cb45275b..cef4c3fdfc 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist @@ -2919,6 +2919,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist index 8a32d2585d..88552d3d83 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist @@ -2821,6 +2821,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/or1k/libc.abilist b/sysdeps/unix/sysv/linux/or1k/libc.abilist index 64dac95b2a..eafbc801f7 100644 --- a/sysdeps/unix/sysv/linux/or1k/libc.abilist +++ b/sysdeps/unix/sysv/linux/or1k/libc.abilist @@ -2263,6 +2263,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist index cc5e93c77c..fa84873e19 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist @@ -3142,6 +3142,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist index 9814997083..f108b01d47 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist @@ -3187,6 +3187,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist index 7f46295c11..7cbf55204f 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist @@ -2896,6 +2896,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist index f24f81bb5f..ca2abbee1e 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist @@ -2972,6 +2972,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist index 9330c7ab76..8f750dc78c 100644 --- a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist +++ b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist @@ -2516,6 +2516,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist index ea4555d39e..12e755d237 100644 --- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist +++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist @@ -2716,6 +2716,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist index 3e625fa4e9..fe663d1f20 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist +++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist @@ -3140,6 +3140,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist index 46b4a04f65..e17b3d2a3a 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist +++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist @@ -2933,6 +2933,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/setrlimit64.c b/sysdeps/unix/sysv/linux/setrlimit64.c index d62ea94acf..b7ca64d914 100644 --- a/sysdeps/unix/sysv/linux/setrlimit64.c +++ b/sysdeps/unix/sysv/linux/setrlimit64.c @@ -24,12 +24,9 @@ /* Add this redirection so the strong_alias for __RLIM_T_MATCHES_RLIM64_T linking setrlimit64 to {__}setrlimit does not throw a type error. */ #undef setrlimit -#undef __setrlimit #define setrlimit setrlimit_redirect -#define __setrlimit __setrlimit_redirect #include #undef setrlimit -#undef __setrlimit /* Set the soft and hard limits for RESOURCE to *RLIMITS. Only the super-user can increase hard limits. @@ -39,17 +36,17 @@ __setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits) { return INLINE_SYSCALL_CALL (prlimit64, 0, resource, rlimits, NULL); } +libc_hidden_def (__setrlimit64) /* Alpha defines a versioned setrlimit{64}. */ #ifndef USE_VERSIONED_RLIMIT weak_alias (__setrlimit64, setrlimit64) #endif #if __RLIM_T_MATCHES_RLIM64_T -strong_alias (__setrlimit64, __setrlimit) # ifndef USE_VERSIONED_RLIMIT weak_alias (__setrlimit64, setrlimit) # endif # ifdef SHARED -__hidden_ver1 (__setrlimit64, __GI___setrlimit, __setrlimit64); +strong_alias (__setrlimit64, __GI___setrlimit) # endif #endif diff --git a/sysdeps/unix/sysv/linux/sh/be/libc.abilist b/sysdeps/unix/sysv/linux/sh/be/libc.abilist index 36a94c9210..807321c07f 100644 --- a/sysdeps/unix/sysv/linux/sh/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/sh/be/libc.abilist @@ -2832,6 +2832,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/sh/le/libc.abilist b/sysdeps/unix/sysv/linux/sh/le/libc.abilist index f79aba6aab..df23a1db81 100644 --- a/sysdeps/unix/sysv/linux/sh/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/sh/le/libc.abilist @@ -2829,6 +2829,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/sparc/bits/resource.h b/sysdeps/unix/sysv/linux/sparc/bits/resource.h index 193c94657d..727914ab3d 100644 --- a/sysdeps/unix/sysv/linux/sparc/bits/resource.h +++ b/sysdeps/unix/sysv/linux/sparc/bits/resource.h @@ -16,7 +16,10 @@ License along with the GNU C Library; if not, see . */ -#ifndef _SYS_RESOURCE_H +#ifndef _BITS_RESOURCE_H +#define _BITS_RESOURCE_H + +#if !defined _SYS_RESOURCE_H && !defined _SPAWN_H # error "Never use directly; include instead." #endif @@ -236,3 +239,5 @@ extern int prlimit64 (__pid_t __pid, enum __rlimit_resource __resource, #endif __END_DECLS + +#endif diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist index 4a6acc08e0..876f2529f7 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist @@ -3161,6 +3161,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist index 931109dab1..8d1bd80545 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist @@ -2797,6 +2797,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c index d78298d8b4..bfeeb0cf4f 100644 --- a/sysdeps/unix/sysv/linux/spawni.c +++ b/sysdeps/unix/sysv/linux/spawni.c @@ -27,6 +27,7 @@ #include #include #include +#include /* The Linux implementation of posix_spawn{p} uses the clone syscall directly with CLONE_VM and CLONE_VFORK flags and an allocated stack. The new stack @@ -171,6 +172,19 @@ __spawni_child (void *arguments) || local_setegid (__getgid ()) != 0)) goto fail; + /* Set the process resource limits. */ + if ((attr->__flags & POSIX_SPAWN_SETRLIMIT) != 0) + { + uint32_t rlimitset = attr->__rlimitset; + while (rlimitset != 0) + { + int resource = stdc_trailing_zeros (rlimitset); + if (__setrlimit64 (resource, &attr->__rlimits[resource]) == -1) + goto fail; + rlimitset &= ~(1u << resource); + } + } + /* Execute the file actions. */ if (file_actions != NULL) { diff --git a/sysdeps/unix/sysv/linux/tst-spawn8-pidfd.c b/sysdeps/unix/sysv/linux/tst-spawn8-pidfd.c new file mode 100644 index 0000000000..5322e9b12c --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-spawn8-pidfd.c @@ -0,0 +1,20 @@ +/* Tests for spawn pidfd extension. + Copyright (C) 2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist index 7ab9073e3a..bbe7d8b606 100644 --- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist @@ -2748,6 +2748,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist index e11876f6ab..0c3fde8fa7 100644 --- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist @@ -2767,6 +2767,8 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 posix_spawnattr_getrlimit_np F +GLIBC_2.42 posix_spawnattr_setrlimit_np F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F