From owner-svn-src-head@freebsd.org Fri Mar 13 15:40:37 2020 Return-Path: Delivered-To: svn-src-head@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 0523A263045; Fri, 13 Mar 2020 15:40:37 +0000 (UTC) (envelope-from emaste@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48f8zS5ZyRz44Lh; Fri, 13 Mar 2020 15:40:36 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5F96484A7; Fri, 13 Mar 2020 15:40:36 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 02DFeaJB078917; Fri, 13 Mar 2020 15:40:36 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 02DFeZ35078915; Fri, 13 Mar 2020 15:40:35 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <202003131540.02DFeZ35078915@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Fri, 13 Mar 2020 15:40:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r358960 - in head/libexec/flua: . modules X-SVN-Group: head X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: in head/libexec/flua: . modules X-SVN-Commit-Revision: 358960 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Mar 2020 15:40:37 -0000 Author: emaste Date: Fri Mar 13 15:40:35 2020 New Revision: 358960 URL: https://svnweb.freebsd.org/changeset/base/358960 Log: flua: implement chmod Lua does not provide a native way to change the permission of a file. Submitted by: Yang Wang <2333@outlook.jp> Reviewed by: kevans Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D24036 Modified: head/libexec/flua/linit_flua.c head/libexec/flua/modules/lposix.c head/libexec/flua/modules/lposix.h Modified: head/libexec/flua/linit_flua.c ============================================================================== --- head/libexec/flua/linit_flua.c Fri Mar 13 14:51:11 2020 (r358959) +++ head/libexec/flua/linit_flua.c Fri Mar 13 15:40:35 2020 (r358960) @@ -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} }; Modified: head/libexec/flua/modules/lposix.c ============================================================================== --- head/libexec/flua/modules/lposix.c Fri Mar 13 14:51:11 2020 (r358959) +++ head/libexec/flua/modules/lposix.c Fri Mar 13 15:40:35 2020 (r358960) @@ -27,6 +27,10 @@ #include __FBSDID("$FreeBSD$"); +#include + +#include +#include #include #include @@ -38,6 +42,28 @@ __FBSDID("$FreeBSD$"); */ 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) { int n; @@ -49,11 +75,23 @@ 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) Modified: head/libexec/flua/modules/lposix.h ============================================================================== --- head/libexec/flua/modules/lposix.h Fri Mar 13 14:51:11 2020 (r358959) +++ head/libexec/flua/modules/lposix.h Fri Mar 13 15:40:35 2020 (r358960) @@ -8,4 +8,5 @@ #include +int luaopen_posix_sys_stat(lua_State *L); int luaopen_posix_unistd(lua_State *L);