<feed xmlns='http://www.w3.org/2005/Atom'>
<title>src/lib/libc/gen/exec.c, branch releng/12.4</title>
<subtitle>FreeBSD source tree</subtitle>
<id>https://cgit-dev.freebsd.org/src/atom?h=releng%2F12.4</id>
<link rel='self' href='https://cgit-dev.freebsd.org/src/atom?h=releng%2F12.4'/>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/'/>
<updated>2020-06-17T16:22:08Z</updated>
<entry>
<title>MFC r361995-r361996, r361999, r362111: posix_spawnp fixes</title>
<updated>2020-06-17T16:22:08Z</updated>
<author>
<name>Kyle Evans</name>
<email>kevans@FreeBSD.org</email>
</author>
<published>2020-06-17T16:22:08Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=a535dcf21b1cc32c627915f7477542b348359f5f'/>
<id>urn:sha1:a535dcf21b1cc32c627915f7477542b348359f5f</id>
<content type='text'>
r361995:
execvp: fix up the ENOEXEC fallback

If execve fails with ENOEXEC, execvp is expected to rebuild the command
with /bin/sh instead and try again.

The previous version did this, but overlooked two details:

argv[0] can conceivably be NULL, in which case memp would never get
terminated.  We must allocate no less than three * sizeof(char *) so we can
properly terminate at all times. For the non-NULL argv standard case, we
count all the non-NULL elements and actually skip the first argument, so we
end up capturing the NULL terminator in our bcopy().

The second detail is that the spec is actually worded such that we should
have been preserving argv[0] as passed to execvp:

"[...] executed command shall be as if the process invoked the sh utility
using execl() as follows:

execl(&lt;shell path&gt;, arg0, file, arg1, ..., (char *)0);

where &lt;shell path&gt; is an unspecified pathname for the sh utility, file is
the process image file, and for execvp(), where arg0, arg1, and so on
correspond to the values passed to execvp() in argv[0], argv[1], and so on."

So we make this change at this time as well, while we're already touching
it. We decidedly can't preserve a NULL argv[0] as this would be incredibly,
incredibly fragile, so we retain our legacy behavior of using "sh" for
argv[] in this specific instance.

Some light tests are added to try and detect some components of handling the
ENOEXEC fallback; posix_spawnp_enoexec_fallback_null_argv0 is likely not
100% reliable, but it at least won't raise false-alarms and it did result in
useful failures with pre-change libc on my machine.

This is a secondary change in D25038.

r361996:
execvPe: obviate the need for potentially large stack allocations

Some environments in which execvPe may be called have a limited amount of
stack available. Currently, it avoidably allocates a segment on the stack
large enough to hold PATH so that it may be mutated and use strsep() for
easy parsing. This logic is now rewritten to just operate on the immutable
string passed in and do the necessary math to extract individual paths,
since it will be copying out those segments to another buffer anyways and
piecing them together with the name for a full path.

Additional size is also needed for the stack in posix_spawnp(), because it
may need to push all of argv to the stack and rebuild the command with sh in
front of it. We'll make sure it's properly aligned for the new thread, but
future work should likely make rfork_thread a little easier to use by
ensuring proper alignment.

Some trivial cleanup has been done with a couple of error writes, moving
strings into char arrays for use with the less fragile sizeof().

r361999:
Add missing shell script from r361995

r362111:
posix_spawn: fix for some custom allocator setups

libc cannot assume that aligned_alloc and free come from jemalloc, or that
any application providing its own malloc and free is actually providing
aligned_alloc.

Switch back to malloc and just make sure we're passing a properly aligned
stack into rfork_thread, as an application perhaps can't reasonably replace
just malloc or just free without headaches.

This unbreaks ksh93 after r361996, which provides malloc/free but no
aligned_alloc.
</content>
</entry>
<entry>
<title>Clean up the vcs ID strings in libc's gen/ directory.</title>
<updated>2018-07-03T17:31:45Z</updated>
<author>
<name>John Baldwin</name>
<email>jhb@FreeBSD.org</email>
</author>
<published>2018-07-03T17:31:45Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=c1920558b3c4efbeea4d0c833aa9cb4091533ff1'/>
<id>urn:sha1:c1920558b3c4efbeea4d0c833aa9cb4091533ff1</id>
<content type='text'>
- Move CSRG IDs into __SCCSID().
- When a file has been copied, consistently use 'From: &lt;tag&gt;' for strings
  referencing the version of the source file copied from in the license
  block comment.
- Some of the 'From:' tags were using $FreeBSD$ that was being expanded on
  each checkout.  Fix those to hardcode the FreeBSD tag from the file that
  was copied at the time of the copy.
- When multiple strings are present list them in "chronological" order,
  so CSRG (__SCCSID) before FreeBSD (__FBSDID).  If a file came from
  OtherBSD and contains a CSRG ID from the OtherBSD file, use the order
  CSRG -&gt; OtherBSD -&gt; FreeBSD.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D15831
</content>
</entry>
<entry>
<title>General further adoption of SPDX licensing ID tags.</title>
<updated>2017-11-20T19:49:47Z</updated>
<author>
<name>Pedro F. Giffuni</name>
<email>pfg@FreeBSD.org</email>
</author>
<published>2017-11-20T19:49:47Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=8a16b7a18f5d0b031f09832fd7752fba717e2a97'/>
<id>urn:sha1:8a16b7a18f5d0b031f09832fd7752fba717e2a97</id>
<content type='text'>
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
</content>
</entry>
<entry>
<title>Renumber copyright clause 4</title>
<updated>2017-02-28T23:42:47Z</updated>
<author>
<name>Warner Losh</name>
<email>imp@FreeBSD.org</email>
</author>
<published>2017-02-28T23:42:47Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=fbbd9655e5107c68e4e0146ff22b73d7350475bc'/>
<id>urn:sha1:fbbd9655e5107c68e4e0146ff22b73d7350475bc</id>
<content type='text'>
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann &lt;jschauma@stevens.edu&gt;
Pull Request:	https://github.com/freebsd/freebsd/pull/96
</content>
</entry>
<entry>
<title>libc: do not include &lt;sys/types.h&gt; where &lt;sys/param.h&gt; was already included</title>
<updated>2016-04-18T21:05:15Z</updated>
<author>
<name>Andriy Voskoboinyk</name>
<email>avos@FreeBSD.org</email>
</author>
<published>2016-04-18T21:05:15Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=2cf5e9365d299ad70ec7fe8a7e7202fbb925e70c'/>
<id>urn:sha1:2cf5e9365d299ad70ec7fe8a7e7202fbb925e70c</id>
<content type='text'>
According to style(9):
&gt; normally, include &lt;sys/types.h&gt; OR &lt;sys/param.h&gt;, but not both.
(&lt;sys/param.h&gt; already includes &lt;sys/types.h&gt; when LOCORE is not defined).
</content>
</entry>
<entry>
<title>Use ANSI C prototypes.  Eliminates -Wold-style-definition warnings.</title>
<updated>2015-09-20T20:23:16Z</updated>
<author>
<name>Craig Rodrigues</name>
<email>rodrigc@FreeBSD.org</email>
</author>
<published>2015-09-20T20:23:16Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=55b6b759c89e6a44468ff442f11bc2a4a1775699'/>
<id>urn:sha1:55b6b759c89e6a44468ff442f11bc2a4a1775699</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Replace index() and rindex() calls with strchr() and strrchr().</title>
<updated>2012-01-03T18:51:58Z</updated>
<author>
<name>Ed Schouten</name>
<email>ed@FreeBSD.org</email>
</author>
<published>2012-01-03T18:51:58Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=b3608ae18f1e5598bed81d0a10dd585a5080c40d'/>
<id>urn:sha1:b3608ae18f1e5598bed81d0a10dd585a5080c40d</id>
<content type='text'>
The index() and rindex() functions were marked LEGACY in the 2001
revision of POSIX and were subsequently removed from the 2008 revision.
The strchr() and strrchr() functions are part of the C standard.

This makes the source code a lot more consistent, as most of these C
files also call into other str*() routines. In fact, about a dozen
already perform strchr() calls.
</content>
</entry>
<entry>
<title>Remove warnings from exec.c.</title>
<updated>2009-12-05T18:55:16Z</updated>
<author>
<name>Ed Schouten</name>
<email>ed@FreeBSD.org</email>
</author>
<published>2009-12-05T18:55:16Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=bbbe3054ff632f0a8f8abe13fcfea3a0ede0a9b3'/>
<id>urn:sha1:bbbe3054ff632f0a8f8abe13fcfea3a0ede0a9b3</id>
<content type='text'>
The entries in the argv array are not const themselves, but sometimes we
want to fill in const values. Just make the array const and use
__DECONST() to make it const for the execve()-call itself.

Also convert the only K&amp;R prototype to ANSI.
</content>
</entry>
<entry>
<title>Properly use the envp argument in execvPe().</title>
<updated>2009-11-27T13:05:14Z</updated>
<author>
<name>Ed Schouten</name>
<email>ed@FreeBSD.org</email>
</author>
<published>2009-11-27T13:05:14Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=f67d07f0e1236d9cbc2a28508b3da08f41ca7178'/>
<id>urn:sha1:f67d07f0e1236d9cbc2a28508b3da08f41ca7178</id>
<content type='text'>
execvPe() is called by _execvpe(), which we added to implement
posix_spawnp(). We just took execvP() and added the envp argument.
Unfortunately we forgot to change the implementation to use envp over
environ.

This fixes the following piece of code:

| char * const arg[2] = { "env", NULL };
| char * const env[2] = { "FOO=BAR", NULL };
| posix_spawnp(NULL, "/usr/bin/env", NULL, NULL, arg, env);

MFC after:	2 weeks
</content>
</entry>
<entry>
<title>Turn execvpe() into an internal libc routine.</title>
<updated>2008-06-23T05:22:06Z</updated>
<author>
<name>Ed Schouten</name>
<email>ed@FreeBSD.org</email>
</author>
<published>2008-06-23T05:22:06Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=c605eea952146348e5e1ad5cab6c127d7a1bd164'/>
<id>urn:sha1:c605eea952146348e5e1ad5cab6c127d7a1bd164</id>
<content type='text'>
Adding exevpe() has caused some ports to break. Even though execvpe() is
a useful routine, it does not conform to any standards.

This patch is a little bit different from the patch sent to the mailing
list. I forgot to remove execvpe from the Symbol.map (which does not
seem to miscompile libc, though).

Reviewed by:	davidxu
Approved by:	philip
</content>
</entry>
</feed>
