From nobody Sat Sep 13 17:43:04 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4cPJY41mzBz67HC9; Sat, 13 Sep 2025 17:43:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cPJY41C6Fz45gZ; Sat, 13 Sep 2025 17:43:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757785384; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iqSge8wV3bc3Q/ZwbIxeJCqklWmy1SeJhux+csCBjzg=; b=Q0kcZV1E53O5/Npmv8i6QUCaZVvKWArMpV9xaEvWkq/UnIu3iubmkTGTZrY+8QAG+6Z9ls i5POkRHVfPBpbptIVHcMtz5YdfFAXn4xIRLYA1NZ2lVUOAtTij6aHGLuxhZxuNTjahD5m5 WXvTY/2GNKyHaAyFfDUDDtYT2sVt6i+ly7y3T9n4shDABU2Uw1iz0AVPtrzUJ6Pl4/oYyw Wjl8T/nIHF6FU6X84s4ShJKda8GmXx/isALXOHvyxf6IKJYCTNcxCgV39Wp8vMbt/LVNNJ /zFXBndZRnp2/vfzT1OvukwA4i49q/Kw4gFa60SWWF00x0G+NNoqRhW0WwoSvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757785384; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iqSge8wV3bc3Q/ZwbIxeJCqklWmy1SeJhux+csCBjzg=; b=WcBfnIMI1hLeZeIcuePzMC3Ke7M2UOItH2ax5HEUF0lhHPcGBkFeRNPgIuFWroqyTn6zMT ce/dC3gezF92MC61PSW2EGE8eCmT9bGMWwnPXANC0pMzqPHEGzEu0CsK3GGi1PP/1/mbgn mtMVpSd9f0B4kfVmT6WVsNDWiS5eN+2gGM1mvtJ6rTnnG3rSOtWtb4LkZcbjUQZ/QH0Jyu Z0eqZZT2qYWMQvIgkwwFc6rH3RjG/SQ/Dcia0Dtpls+GREDFi6L0KPgL0FnICGtgZLIbTA +AO4Kfd5qemHIAVhrRgFMnMH1lvOxe6YX/LSkfb9h2gVkpVfarv3nv/Vls/zdw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1757785384; a=rsa-sha256; cv=none; b=fuOB9tCqVG4itQ6aI47sLuuLdDBGycVmXKeykzEon+8FoCInc6gqhLcIv8kmcA+XnUWD7C dZ8xweBLWNDjpiF4siOus3t/0HjLOd11ECD1rgdvAhujSqSocau6HBXO8aUzr51tJ20PaB qHTRt6EVyiCdT/DZPxfhI9YEzvx6DcSfo+OYQ0ci7PJmiDN9O9uSftu7gUqm5Zzly8egnT QaCtkovo4SIPUneQEe9+k3urjFFsUzPJ4UlIo3vihhygGbJAS240CFCnSfPK4kGgDMDgbX GWO5tv89uIgm7aLYi37zYHEe1i6/Kqid0NS2OzgX6+0QfrswbGFbo2Qf3SBtbA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cPJY40YNczq6D; Sat, 13 Sep 2025 17:43:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 58DHh4Dp075680; Sat, 13 Sep 2025 17:43:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58DHh4S7075677; Sat, 13 Sep 2025 17:43:04 GMT (envelope-from git) Date: Sat, 13 Sep 2025 17:43:04 GMT Message-Id: <202509131743.58DHh4S7075677@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: e9e9c912c5c2 - stable/14 - flua: add posix.unistd.execp List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: e9e9c912c5c28d15fe485e5d8850da231b1bb371 Auto-Submitted: auto-generated The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=e9e9c912c5c28d15fe485e5d8850da231b1bb371 commit e9e9c912c5c28d15fe485e5d8850da231b1bb371 Author: Isaac Freund AuthorDate: 2025-05-05 09:57:13 +0000 Commit: Ed Maste CommitDate: 2025-09-13 17:42:38 +0000 flua: add posix.unistd.execp This matches the interface of lposix, although I do wonder why they went with execp rather than execvp for the function name here. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D50177 (cherry picked from commit 7080a0c170daf8e4b3f331ec33003b2f8893dc23) --- libexec/flua/modules/lposix.c | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/libexec/flua/modules/lposix.c b/libexec/flua/modules/lposix.c index 4ccfcdaa46e7..75cdd345aeaa 100644 --- a/libexec/flua/modules/lposix.c +++ b/libexec/flua/modules/lposix.c @@ -207,6 +207,62 @@ err: return (3); } +static int +lua_execp(lua_State *L) +{ + int argc, error; + const char *file; + const char **argv; + + enforce_max_args(L, 2); + + file = luaL_checkstring(L, 1); + luaL_checktype(L, 2, LUA_TTABLE); + + lua_len(L, 2); + argc = lua_tointeger(L, -1); + + /* + * Use lua_newuserdatauv() to allocate a scratch buffer that is tracked + * and freed by lua's GC. This avoid any chance of a leak if a lua error + * is raised later in this function (e.g. by luaL_argerror()). + * The (argc + 2) size gives enough space in the buffer for argv[0] and + * the terminating NULL. + */ + argv = lua_newuserdatauv(L, (argc + 2) * sizeof(char *), 0); + + /* + * Sequential tables in lua start at index 1 by convention. + * If there happens to be a string at index 0, use that to + * override the default argv[0]. This matches the lposix API. + */ + lua_pushinteger(L, 0); + lua_gettable(L, 2); + argv[0] = lua_tostring(L, -1); + if (argv[0] == NULL) { + argv[0] = file; + } + + for (int i = 1; i <= argc; i++) { + lua_pushinteger(L, i); + lua_gettable(L, 2); + argv[i] = lua_tostring(L, -1); + if (argv[i] == NULL) { + luaL_argerror(L, 2, + "argv table must contain only strings"); + } + } + argv[argc + 1] = NULL; + + execvp(file, (char **)argv); + error = errno; + + lua_pushnil(L); + lua_pushstring(L, strerror(error)); + lua_pushinteger(L, error); + return (3); +} + static int lua_fnmatch(lua_State *L) { @@ -522,6 +578,7 @@ static const struct luaL_Reg unistdlib[] = { REG_SIMPLE(chown), REG_DEF(close, lua_pclose), REG_SIMPLE(dup2), + REG_SIMPLE(execp), REG_SIMPLE(fork), REG_SIMPLE(getpid), REG_SIMPLE(pipe),