Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 04 Mar 2026 15:22:59 +0000
From:      Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 40e52e0edd03 - main - system(3): Unwrap execve()
Message-ID:  <69a84e53.317d4.78cb8c78@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=40e52e0edd038460a2a2aca017b3ac5a513fe37b

commit 40e52e0edd038460a2a2aca017b3ac5a513fe37b
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-03-04 15:22:42 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-03-04 15:22:42 +0000

    system(3): Unwrap execve()
    
    There is no need to call execl(), which will allocate an array and copy
    our arguments into it, when we can use a static array and call execve()
    directly.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Reviewed by:    kevans
    Differential Revision:  https://reviews.freebsd.org/D55648
---
 lib/libc/stdlib/system.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/libc/stdlib/system.c b/lib/libc/stdlib/system.c
index 94f7460c9b68..a2f472502bfd 100644
--- a/lib/libc/stdlib/system.c
+++ b/lib/libc/stdlib/system.c
@@ -60,6 +60,8 @@ __libc_system(const char *command)
 	static struct sigaction ointact, oquitact;
 	struct sigaction ign;
 	sigset_t sigblock, osigblock;
+	char *argv[] = { "sh", "-c", __DECONST(char *, command), NULL };
+	extern char **environ;
 	int pstat = -1, serrno = 0;
 	pid_t pid;
 
@@ -101,7 +103,7 @@ __libc_system(const char *command)
 		/*
 		 * Exec the command.
 		 */
-		execl(_PATH_BSHELL, "sh", "-c", command, NULL);
+		_execve(_PATH_BSHELL, argv, environ);
 		_exit(127);
 	} else {				/* parent */
 		/*


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69a84e53.317d4.78cb8c78>