[PATCH] posix: Add posix_spawn extension to setup resource limits (BZ 31049)
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Fri Jun 6 13:01:36 GMT 2025
On 06/06/25 03:44, Florian Weimer wrote:
> * Adhemerval Zanella:
>
>> 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.
>
> Why is the separate flag is needed?
Mainly because it was already added by a libc implementation [1] and it
allows to use the same attribute to spawn different process with and
without limits.
>
>> 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).
>
> It would be more general to treat this as a file action, so that the
> limits can be applied after opening files.
>
I think it would really matter if the RLIMIT_NOFILE is less than the
number of file descriptors set by the file actions. And in this case,
setting the limit *after* won't trigger a potential failure for bogus
values, and I am not sure which is better (allow all file operation
or enforce RLIMIT_NOFILE is set, I am more inclined for the latter).
Also, resources are *not* file operation so I really think we should
not tie them together. And make them a file operation would make it
even harder to get consensus on a future standardization.
> Thanks,
> Florian
>
[1] https://justine.lol/cosmopolitan/documentation.html#posix_spawnattr_setrlimit_np
More information about the Libc-alpha
mailing list