summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-05-21 21:33:30 +0800
committerruki <[email protected]>2017-05-21 21:33:30 +0800
commit83f448dc569b70410765dfe6241fabc351feb54f (patch)
tree7bd1762bf8235d535980ff8223df6c50048a7365
parentb173fc383b9b1e80f0cbd2229d7b6d46ff75f0b6 (diff)
fix write nuldev bug as root
-rw-r--r--xmake/core/base/os.lua33
-rw-r--r--xmake/core/base/utils.lua4
-rw-r--r--xmake/core/main.lua29
-rw-r--r--xmake/core/project/task.lua2
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_program.lua2
-rw-r--r--xmake/core/tool/tool.lua2
6 files changed, 43 insertions, 29 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 21bec949c..d6e802472 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -630,7 +630,38 @@ end
-- get the system null device
function os.nuldev()
- return xmake._NULDEV
+ if os.isroot() then
+ return os.tmpfile()
+ else
+ return xmake._NULDEV
+ end
+end
+
+-- check run command as root
+function os.isroot()
+
+ -- get it from cache
+ if os._ISROOT ~= nil then
+ return os._ISROOT
+ end
+
+ -- check it
+ if os.host() == "windows" then
+ -- TODO
+ else
+ local ok, code = os.iorun("id -u")
+ if ok and code and code:trim() == '0' then
+ os._ISROOT = true
+ end
+ end
+
+ -- not root?
+ if os._ISROOT == nil then
+ os._ISROOT = false
+ end
+
+ -- root?
+ return os._ISROOT
end
-- get version info
diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua
index 3bda8060c..42a55a5e9 100644
--- a/xmake/core/base/utils.lua
+++ b/xmake/core/base/utils.lua
@@ -122,7 +122,7 @@ function utils.verror(format, ...)
if option.get("verbose") and format ~= nil then
-- trace
- utils.cprint("${bright red}error: ${default red}" .. string.tryformat(format, ...))
+ utils.cprint("${bright red}error: ${clear}" .. string.tryformat(format, ...))
end
end
@@ -131,7 +131,7 @@ function utils.error(format, ...)
-- trace
if format ~= nil then
- utils.cprint("${bright red}error: ${default red}" .. string.tryformat(format, ...))
+ utils.cprint("${bright red}error: ${clear}" .. string.tryformat(format, ...))
end
end
diff --git a/xmake/core/main.lua b/xmake/core/main.lua
index a809fc508..b4ca6afab 100644
--- a/xmake/core/main.lua
+++ b/xmake/core/main.lua
@@ -127,26 +127,6 @@ function main._init()
end
end
--- check run command as root
-function main._check_root()
-
- -- TODO not check
- if xmake._HOST == "windows" then
- return true
- end
-
- -- check it
- local ok, code = os.iorun("id -u")
- if ok and code and code:trim() == '0' then
- return false, [[Running xmake as root is extremely dangerous and no longer supported.
- As xmake does not drop privileges on installation you would be giving all
- build scripts full access to your system.]]
- end
-
- -- not root
- return true
-end
-
-- the main function
function main.done()
@@ -162,9 +142,12 @@ function main.done()
-- check run command as root
if not option.get("root") then
- local ok, errors = main._check_root()
- if not ok then
- utils.error(errors)
+ if os.isroot() then
+ utils.error([[Running xmake as root is extremely dangerous and no longer supported.
+As xmake does not drop privileges on installation you would be giving all
+build scripts full access to your system.
+Or you can add `--root` option to allow run as root temporarily.
+ ]])
return -1
end
end
diff --git a/xmake/core/project/task.lua b/xmake/core/project/task.lua
index a237c1dc6..0111dd6e9 100644
--- a/xmake/core/project/task.lua
+++ b/xmake/core/project/task.lua
@@ -196,7 +196,7 @@ function task._interpreter()
local maps =
{
host = xmake._HOST
- , nuldev = xmake._NULDEV
+ , nuldev = os.nuldev()
, tmpdir = os.tmpdir()
, curdir = os.curdir()
, globaldir = global.directory()
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
index d2ee2a0c5..2f6f8b2ab 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
@@ -41,7 +41,7 @@ function sandbox_lib_detect_find_program._check(program, check)
-- no check script? attempt to run it directly
if not check then
- return 0 == os.execv(program, {"--version"}, xmake._NULDEV, xmake._NULDEV)
+ return 0 == os.execv(program, {"--version"}, os.nuldev(), os.nuldev())
end
-- check it
diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua
index d73ccfb13..7b139b12b 100644
--- a/xmake/core/tool/tool.lua
+++ b/xmake/core/tool/tool.lua
@@ -209,7 +209,7 @@ function tool._check(shellname, check)
-- no checker? attempt to run it directly
if not module or not module.check then
- return 0 == os.exec(shellname, xmake._NULDEV, xmake._NULDEV)
+ return 0 == os.exec(shellname, os.nuldev(), os.nuldev())
end
-- check it