diff options
| author | TitanSnow <[email protected]> | 2017-05-22 07:14:04 +0800 |
|---|---|---|
| committer | TitanSnow <[email protected]> | 2017-05-22 07:25:43 +0800 |
| commit | 24cf9ef118cb14176b7f750e71db92a8c599823a (patch) | |
| tree | 260357f60e33d076454daf4165f682e32da06108 /core/src | |
| parent | 433c76d7735fc8006ab400850e0e08a4e5bffdc0 (diff) | |
add os.uid() and use os.uid() to check if root instead of id -u
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/machine.c | 6 | ||||
| -rw-r--r-- | core/src/xmake/makefile | 1 | ||||
| -rw-r--r-- | core/src/xmake/os/uid.c | 65 |
3 files changed, 72 insertions, 0 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index 4001af365..753ff579d 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -81,6 +81,9 @@ tb_int_t xm_os_emptydir(lua_State* lua); tb_int_t xm_os_strerror(lua_State* lua); tb_int_t xm_os_getwinsize(lua_State* lua); tb_int_t xm_os_versioninfo(lua_State* lua); +#ifndef TB_CONFIG_OS_WINDOWS +tb_int_t xm_os_uid(lua_State* lua); +#endif // the path functions tb_int_t xm_path_relative(lua_State* lua); @@ -141,6 +144,9 @@ static luaL_Reg const g_os_functions[] = , { "strerror", xm_os_strerror } , { "getwinsize", xm_os_getwinsize} , { "versioninfo", xm_os_versioninfo} +#ifndef TB_CONFIG_OS_WINDOWS +, { "uid", xm_os_uid } +#endif , { tb_null, tb_null } }; diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index 0b9770bf6..b1b29ed83 100644 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -37,6 +37,7 @@ xmake_C_FILES += \ os/strerror \ os/getwinsize \ os/versioninfo \ + os/uid \ path/relative \ path/absolute \ path/translate \ diff --git a/core/src/xmake/os/uid.c b/core/src/xmake/os/uid.c new file mode 100644 index 000000000..d19bbd88e --- /dev/null +++ b/core/src/xmake/os/uid.c @@ -0,0 +1,65 @@ +/*!The Make-like Build Utility based on Lua + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright (C) 2015 - 2017, TBOOX Open Source Group. + * + * @author TitanSnow + * @file uid.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "uid" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" +#ifndef TB_CONFIG_OS_WINDOWS +# include <unistd.h> + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ + +// get uid & euid +tb_int_t xm_os_uid(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // get uid & euid + uid_t uid = getuid(), euid = geteuid(); + + // push + lua_newtable(lua); + lua_pushstring(lua, "uid"); + lua_pushinteger(lua, uid); + lua_settable(lua, -3); + lua_pushstring(lua, "euid"); + lua_pushinteger(lua, euid); + lua_settable(lua, -3); + + // ok + return 1; +} + +#endif |
