coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using posix_spawn in coreutils?


From: Collin Funk
Subject: Re: Using posix_spawn in coreutils?
Date: Tue, 21 Oct 2025 20:51:54 -0700
User-agent: Gnus/5.13 (Gnus v5.13)

PƔdraig Brady <P@draigBrady.com> writes:

>> I notice that glibc's posix_spawn() reaps the child itself upon exec
>> error
>> (which I confirmed with `strace -ff`) but means we only get a single error
>> now from the following:
>> # Old behavior
>>     $ install src/install.c foo -s --strip-program=./foo
>>     install: cannot run './foo': Permission denied
>>     install: strip process terminated abnormally
>> # New behavior
>>     $ src/ginstall src/install.c foo -s --strip-program=./foo
>>     ginstall: cannot run './foo': Permission denied
>> That's fine though, and probably a slight improvement.

Yep, that is my preference as well. The second error message didn't seem
very helpful to me. Hopefully 'install' isn't running so long that you
forget you passed it '--strip-program=./foo'. :)

>> I'd add something in NEWS under "Improvements". Perhaps:
>> 'install' now uses posix_spawn() to invoke the strip program more
>> efficiently.
>> We can augment that message for sort(1) and split(1) if we make the
>> change there too.
>> Otherwise the patch looks good.
>
> Actually I remembered thinking about not bothering about free'ing
> the alloc from file_name_concat() since it was in the temp child process,
> but that's no longer the case, so we do need to manage that.

Right, good catch.

> That also made me realize we should destroy the attr for all errors too.

I noticed that issue a little bit after I sent the patch.

On glibc and NetBSD it doesn't matter since posix_spawnattr_init is just
a memset, and posix_spawnattr_destroy just returns zero.

On FreeBSD and OpenBSD posix_spawnattr_init calloc's a structure and
posix_spawnattr_destroy just calls free and returns zero. So not calling
posix_spawnattr_destroy is an issue there.

That also explains why I don't care about the return value of
posix_spawnattr_destroy.

> The attached should fix both issues and can be squashed into your
> patch.

Thanks, I pushed the attached patch.

Collin

Attachment: 0001-install-prefer-posix_spawnp-to-fork-and-execlp.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]