From nobody Thu Sep 05 15:54:20 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 4X03nm4m4sz5WHLl; Thu, 05 Sep 2024 15:54:20 +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 4X03nm42Dqz4lfc; Thu, 5 Sep 2024 15:54:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725551660; 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=DtectqnxSLV6xlyiDOS3NL7IoJgYI1Sh0oKA2Yo9RW4=; b=SW8nlZX7zdMfqxLhvBESCSXnnQKOW6BEKK1GHmpv4hs7ULHLY1X7NGqnREiiS9hdFc1t/0 ZgXy4oQHoHnGYTv7wmf3MR9RFzwZN9L2//hLfBVxPM9TPA3iw5965FdxOL21v2vZbwlpdz 79Lc4BmSiJMAK88qlfIinU2XsiCb8wrBWMDpWeIu4RxkKbOVwgsWZHuqjRRowsiHThXrnZ uYiBVVHqoDE27LGJftgNGzL7ktzC0ZKIZrIt+5znYxfLkMGg4jOFzdqcjUoHM9NQ8f4zRm cPTHruDxZJwf5/AOUnkq7V+A1j1MROpNsYdg7S1Bsyuhl8eb7LDjlX76pnpTew== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725551660; a=rsa-sha256; cv=none; b=Sjyg9Y3Xm3JbDO5UYXfV+So4nr2gR0KIQlOagkNbCJHa0Ia+4p9oJmiv8NPlqNhlsUaYc4 PIhTp2R76+jr0n3kPkuf+HrvUs8nnXf5BVN7za79VPnK+bxICujLJUqLpKoaW3cqHwKj0u ah8LEBOAOMNgSnbfg6MHPVpkl3a/nVNaw9Aih3YIiqmRqH088fv9GkuW/6tbR4KmdK0T6c 19sfA6KIjOJk+Tr0c6qadPKKcPg2sk9aNK9tNcpEzqcgZcqu4fcbIs6in3FGdy+aOxKa1H fwe7xZ9LonLY7r94eiqs6TqEpHNgg9FcHyv5ce50GgiYqlo0n02Vy2MBoBVhNg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725551660; 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=DtectqnxSLV6xlyiDOS3NL7IoJgYI1Sh0oKA2Yo9RW4=; b=fclU3WHrNGKIGjw7UtupNi2TdvFfUA9xUYrfjqVVz9jsHfarUcD0IOjXV7UAHZdg4nMqJu eE0UBcDy5i5nu2nJI0HK95fEkHXwADGtwOWmmAUYK9LYZNrOkI9HmkAxWc58Gq5SmZKW64 hYH/lp/hHMOV90lq61WVPMbUT3qHehECO6FJ32u3C69J0MQXILkJTg3bmCj0GhlDeDVOXr UdsnGdMsRM7UCOudZXVrUHVgr+WsMNc/i2CmXRv5M47UcvRhy0jhTRRqV7G9UoRe7SbXXy CHOcMzEIi6ZOhHWRX0iMIxCxxrS+cXAcqKnnf1rXh098OTHSatKnRlWDPnkPZw== 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 4X03nm3dfvzFYn; Thu, 5 Sep 2024 15:54:20 +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 485FsKlf085698; Thu, 5 Sep 2024 15:54:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 485FsKvx085695; Thu, 5 Sep 2024 15:54:20 GMT (envelope-from git) Date: Thu, 5 Sep 2024 15:54:20 GMT Message-Id: <202409051554.485FsKvx085695@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 1726db7af6b3 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 1726db7af6b3738eb04d962b351d7f4017e1fc77 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=1726db7af6b3738eb04d962b351d7f4017e1fc77 commit 1726db7af6b3738eb04d962b351d7f4017e1fc77 Author: Mark Johnston AuthorDate: 2024-09-05 15:16:29 +0000 Commit: Mark Johnston CommitDate: 2024-09-05 15:53:52 +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 --- 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 4d4d69920e94..1b7d83016cfe 100644 --- a/libexec/flua/linit_flua.c +++ b/libexec/flua/linit_flua.c @@ -59,6 +59,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}, {"fbsd", luaopen_fbsd}, 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);