From owner-dev-commits-src-branches@freebsd.org Sun Jan 24 03:49:22 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 049704EA0EB; Sun, 24 Jan 2021 03:49:22 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DNfBT6YL4z3vR0; Sun, 24 Jan 2021 03:49:21 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 C941F1D0A6; Sun, 24 Jan 2021 03:49:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10O3nLWx068607; Sun, 24 Jan 2021 03:49:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10O3nLj2068606; Sun, 24 Jan 2021 03:49:21 GMT (envelope-from git) Date: Sun, 24 Jan 2021 03:49:21 GMT Message-Id: <202101240349.10O3nLj2068606@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: f817905593d4 - stable/12 - flua: implement chmod MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: f817905593d484861e1ffcb6c882ff7410bfe00c Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Jan 2021 03:49:22 -0000 The branch stable/12 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=f817905593d484861e1ffcb6c882ff7410bfe00c commit f817905593d484861e1ffcb6c882ff7410bfe00c Author: Ed Maste AuthorDate: 2020-03-13 15:40:35 +0000 Commit: Kyle Evans CommitDate: 2021-01-24 03:49:11 +0000 flua: implement chmod Lua does not provide a native way to change the permission of a file. (cherry picked from commit 405e3338ac841999673056a2b5537b4c0ad677db) --- libexec/flua/linit_flua.c | 1 + libexec/flua/modules/lposix.c | 38 ++++++++++++++++++++++++++++++++++++++ libexec/flua/modules/lposix.h | 1 + 3 files changed, 40 insertions(+) diff --git a/libexec/flua/linit_flua.c b/libexec/flua/linit_flua.c index 4b4069e9ad62..99818c3b4db7 100644 --- a/libexec/flua/linit_flua.c +++ b/libexec/flua/linit_flua.c @@ -57,6 +57,7 @@ static const luaL_Reg loadedlibs[] = { #endif /* FreeBSD Extensions */ {"lfs", luaopen_lfs}, + {"posix.sys.stat", luaopen_posix_sys_stat}, {"posix.unistd", luaopen_posix_unistd}, {NULL, NULL} }; diff --git a/libexec/flua/modules/lposix.c b/libexec/flua/modules/lposix.c index 208802456fed..adf3a7bb9a1f 100644 --- a/libexec/flua/modules/lposix.c +++ b/libexec/flua/modules/lposix.c @@ -27,6 +27,10 @@ #include __FBSDID("$FreeBSD$"); +#include + +#include +#include #include #include @@ -37,6 +41,28 @@ __FBSDID("$FreeBSD$"); * Minimal implementation of luaposix needed for internal FreeBSD bits. */ +static int +lua_chmod(lua_State *L) +{ + int n; + const char *path; + mode_t mode; + + n = lua_gettop(L); + luaL_argcheck(L, n == 2, n > 2 ? 3 : n, + "chmod takes exactly two arguments"); + path = luaL_checkstring(L, 1); + mode = (mode_t)luaL_checkinteger(L, 2); + if (chmod(path, mode) == -1) { + lua_pushnil(L); + lua_pushstring(L, strerror(errno)); + lua_pushinteger(L, errno); + return 3; + } + lua_pushinteger(L, 0); + return 1; +} + static int lua_getpid(lua_State *L) { @@ -49,12 +75,24 @@ lua_getpid(lua_State *L) } #define REG_SIMPLE(n) { #n, lua_ ## n } +static const struct luaL_Reg sys_statlib[] = { + REG_SIMPLE(chmod), + { NULL, NULL }, +}; + static const struct luaL_Reg unistdlib[] = { REG_SIMPLE(getpid), { NULL, NULL }, }; #undef REG_SIMPLE +int +luaopen_posix_sys_stat(lua_State *L) +{ + luaL_newlib(L, sys_statlib); + return 1; +} + int luaopen_posix_unistd(lua_State *L) { diff --git a/libexec/flua/modules/lposix.h b/libexec/flua/modules/lposix.h index 4c771d79769f..d2d9ec0cd677 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_unistd(lua_State *L);