mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Tavian Barnes <tavianator@tavianator.com>
To: Rich Felker <dalias@libc.org>
Cc: musl@lists.openwall.com
Subject: Re: [musl] Feature request: posix_spawnattr_setrlimit_np()
Date: Wed, 15 Nov 2023 19:29:56 -0500	[thread overview]
Message-ID: <CABg4E-mpHO9vTFyAB7TQLo42d8N4sbPaEXcs_nag4K5E4AxNHg@mail.gmail.com> (raw)
In-Reply-To: <20231115223902.GY4163@brightrain.aerifal.cx>

On Wed, Nov 15, 2023 at 5:38 PM Rich Felker <dalias@libc.org> wrote:
>
> On Wed, Nov 15, 2023 at 05:00:51PM -0500, Tavian Barnes wrote:
> > I have a program that raises its soft RLIMIT_NOFILE, but wants to
> > spawn processes with the original value (in case they use select(),
> > for example).  There seems to be no nice way to do this with
> > posix_spawn().  I can temporarily lower the rlimit in the parent, but
> > that interferes with other threads, and can make posix_spawn() fail
> > with EMFILE.
> >
> > Corresponding glibc feature request:
> > https://sourceware.org/bugzilla/show_bug.cgi?id=31049
>
> I don't have any objection to this as long as it's coordinated and
> there's agreement from other implementors, but there *is* a way to do
> it already. You posix_spawnp:
>
> sh -c 'ulimit -n whatever && exec "$0" "$@"' your_program args...

True!  Except that ulimit -n is not POSIX.  There are ways around
that, like making a dedicated shim binary that just does

setrlimit(RLIMIT_NOFILE, make_rlimit(argv[1]));
execv(argv[2], argv + 2);

(or making it a special mode of your_program).  But I think it would
be better to have a convenient interface for it.  And the
double-exec() is not free either.

I'm hoping if some libcs implement this, POSIX will reconsider
https://www.austingroupbugs.net/view.php?id=603.  Alternatively I
suppose POSIX could standardize ulimit -n, which is already existing
practice ~everywhere.

> This is the general solution to doing all sorts of "child process
> state setup" things that posix_spawn doesn't have a dedicated
> attribute for.
>
> Note that for a proposal for setting rlimits via an attribute, one
> complication that needs to be specified is whether the limits take
> place before or after file actions, since they could change the
> outcome of file actions. I'm not sure what the answer is, but just
> YOLO'ing an implementation without thinking about that is a bad idea.

True!  Actually when I implemented my own posix_spawn()-like
interface, I had setrlimit() as a file_action.  Then at least the
order is unambiguous.

> Rich

-- 
Tavian Barnes

  reply	other threads:[~2023-11-16  0:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-15 22:00 Tavian Barnes
2023-11-15 22:39 ` Rich Felker
2023-11-16  0:29   ` Tavian Barnes [this message]
2023-11-16 16:23     ` Adhemerval Zanella Netto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABg4E-mpHO9vTFyAB7TQLo42d8N4sbPaEXcs_nag4K5E4AxNHg@mail.gmail.com \
    --to=tavianator@tavianator.com \
    --cc=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).