From nobody Thu Oct 10 20:28:28 2024 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 4XPhCw1skVz5Yb2L; Thu, 10 Oct 2024 20:28:28 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XPhCw1LGSz4TCS; Thu, 10 Oct 2024 20:28:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728592108; 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=PAiFjVfqMAmekgYQoziCWG5F+IH//OTRDdr/Yam3eUA=; b=D4mZKkHrvRWv0lGGgtz2h626aFTPPVjyuLTCpPVmuO6Y10peESV1dYzUZJji+50tMTAah5 KWkZwosc5DCp7W/I+n3obw/aj36zUDgG85ygpOgpvhP+WBl6LCkvIOYDVZUZFmebHl4kg8 Uv/lqLAfzTx+QrS4gAVC+bFH6g1FYZ2/DGPlFjFajculUQ2W53ABi1jjN2Eqk/EPS2lnHY vGy7FWTkdt5oWF9N4vKCUtG/ZUCG7I/67yAYmqXqhDLksfGFMhuGDfE7LdSRxYUuil2Kui S9cCygMY9PIdTsZ2qa/Nyl5GbcOrdHuwnhGc8erjPQef95xxLr0Us98h/kA7Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728592108; 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=PAiFjVfqMAmekgYQoziCWG5F+IH//OTRDdr/Yam3eUA=; b=qkzJWRbCw3vTe1bSSf/0qatvcT7fl/ow8A9vo0G3ULuQDMl9tsB5UPdraB9Z+6WF7A96w0 T57neilpsUY43KaiCh+IhyUZfj0DL8D6Lg+K9KFzHoYqVSPIamgnIjwzwZKAYdtoW7fKRL nq6CJsm0SLS37EkB36uWWJ7e9KwqmndxBTqoD1JfePLkYej7X6PWXPwI7oRl5vfN7/MhVr QzZ1qefdDcahiI5hO4rMLTW4k9Edf2ZohYTG7w3T2adlQ5CPBitTRQdM/KoI/j7XVC+y2L uCyWQOwYKfGeq2XHRFO3J5VOhYUh7I6CTKxi5zO84FLNsBYIBHjvEG3/QxSfnw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728592108; a=rsa-sha256; cv=none; b=GEWYdkP9yi17Yuz/p9ZfxTFalYZ2uD4ugKgB7GqS/PV+HKHb6nrvBjuvjCiTW1Pb845n3A kppG5iBNQN6txoONkDlgoep6RmJ0zZTBykaEjIXPKEWUd4WqDvJpllmhQ7rpjelSqpxpn7 w+ImUrarTFn30OPFk5bhzu0aKFiuS2pwYlefe6VujeLFp+P+EuH3cvsbzlTL8ya/6/JDiJ Rq1/hCUkp23CquMA9LhxLrntbnDAyIti2+WG1qxxLPSkC204oMsCHa9Ge7MSCs2Uy8W4go ATu0UPICDRHSE1+0PP0tV0ckH7F/lmhJDgYRC49tU7wB3T4nF8znLQWPJf7UKA== 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 4XPhCw0sY8z1C7d; Thu, 10 Oct 2024 20:28:28 +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 49AKSSXo005255; Thu, 10 Oct 2024 20:28:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49AKSSse005251; Thu, 10 Oct 2024 20:28:28 GMT (envelope-from git) Date: Thu, 10 Oct 2024 20:28:28 GMT Message-Id: <202410102028.49AKSSse005251@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: cde4ab289dfc - stable/14 - flua: Add wrappers for sys/utsname.h 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: cde4ab289dfc3c802907fa19df166d18b85f59b8 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=cde4ab289dfc3c802907fa19df166d18b85f59b8 commit cde4ab289dfc3c802907fa19df166d18b85f59b8 Author: Mark Johnston AuthorDate: 2024-09-05 15:16:29 +0000 Commit: Mark Johnston CommitDate: 2024-10-10 20:28:20 +0000 flua: Add wrappers for sys/utsname.h This allows one to invoke uname from lua scripts. Reviewed by: bapt, kevans, emaste MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D42017 (cherry picked from commit 1726db7af6b3738eb04d962b351d7f4017e1fc77) --- libexec/flua/linit_flua.c | 1 + libexec/flua/modules/lposix.c | 47 ++++++++++++++++++++++++++++++++++++++++++- libexec/flua/modules/lposix.h | 1 + 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/libexec/flua/linit_flua.c b/libexec/flua/linit_flua.c index 671a0300783c..6bc300095c27 100644 --- a/libexec/flua/linit_flua.c +++ b/libexec/flua/linit_flua.c @@ -58,6 +58,7 @@ static const luaL_Reg loadedlibs[] = { /* FreeBSD Extensions */ {"lfs", luaopen_lfs}, {"posix.sys.stat", luaopen_posix_sys_stat}, + {"posix.sys.utsname", luaopen_posix_sys_utsname}, {"posix.unistd", luaopen_posix_unistd}, {"ucl", luaopen_ucl}, {NULL, NULL} diff --git a/libexec/flua/modules/lposix.c b/libexec/flua/modules/lposix.c index 5b6e80a0309f..fa3fd5f8e589 100644 --- a/libexec/flua/modules/lposix.c +++ b/libexec/flua/modules/lposix.c @@ -24,8 +24,8 @@ * */ -#include #include +#include #include #include @@ -130,12 +130,50 @@ lua_getpid(lua_State *L) return 1; } +static int +lua_uname(lua_State *L) +{ + struct utsname name; + int error, n; + + n = lua_gettop(L); + luaL_argcheck(L, n == 0, 1, "too many arguments"); + + error = uname(&name); + if (error != 0) { + error = errno; + lua_pushnil(L); + lua_pushstring(L, strerror(error)); + lua_pushinteger(L, error); + return (3); + } + + lua_newtable(L); +#define setkv(f) do { \ + lua_pushstring(L, name.f); \ + lua_setfield(L, -2, #f); \ +} while (0) + setkv(sysname); + setkv(nodename); + setkv(release); + setkv(version); + setkv(machine); +#undef setkv + + return (1); +} + #define REG_SIMPLE(n) { #n, lua_ ## n } static const struct luaL_Reg sys_statlib[] = { REG_SIMPLE(chmod), { NULL, NULL }, }; +static const struct luaL_Reg sys_utsnamelib[] = { + REG_SIMPLE(uname), + { NULL, NULL }, +}; + static const struct luaL_Reg unistdlib[] = { REG_SIMPLE(getpid), REG_SIMPLE(chown), @@ -150,6 +188,13 @@ luaopen_posix_sys_stat(lua_State *L) return 1; } +int +luaopen_posix_sys_utsname(lua_State *L) +{ + luaL_newlib(L, sys_utsnamelib); + return 1; +} + int luaopen_posix_unistd(lua_State *L) { diff --git a/libexec/flua/modules/lposix.h b/libexec/flua/modules/lposix.h index 6085bf045d79..e37caaae9d04 100644 --- a/libexec/flua/modules/lposix.h +++ b/libexec/flua/modules/lposix.h @@ -8,4 +8,5 @@ #include int luaopen_posix_sys_stat(lua_State *L); +int luaopen_posix_sys_utsname(lua_State *L); int luaopen_posix_unistd(lua_State *L);