Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xmake root 权限安装问题 #111

Closed
71e6fd52 opened this issue May 21, 2017 · 6 comments
Closed

xmake root 权限安装问题 #111

71e6fd52 opened this issue May 21, 2017 · 6 comments
Milestone

Comments

@71e6fd52
Copy link
Contributor

xmake 有没有办法强制在 root 权限下运行?

@ghost
Copy link

ghost commented May 21, 2017

See #61

@71e6fd52
Copy link
Contributor Author

我需要使用 root 运行 xmake

@ghost
Copy link

ghost commented May 21, 2017

#61 described why running xmake as root is deprecated

xmake can run as root. See xmake/core/main.lua line 163:

    -- check run command as root
    if not option.get("root") then
        local ok, errors = main._check_root()
        if not ok then
            utils.error(errors)
            return -1
        end
    end

That is, when option root is got, xmake will accept to run as root.

But, the option root has not been add to common option. That means we cannot use xmake --root. That should be a mistake. @waruqi

After I do this modify, xmake accepts --root

diff --git a/xmake/core/project/task.lua b/xmake/core/project/task.lua
index 35c051ef..7bc08d6c 100644
--- a/xmake/core/project/task.lua
+++ b/xmake/core/project/task.lua
@@ -145,7 +145,8 @@ function task._translate_menu(menu)
                                                               , "    1. The Given Command Argument"
                                                               , "    2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
                                                               , "    3. The Current Directory"              })
-        table.insert(options, 10, {})
+        table.insert(options, 10, {nil,"root","k",nil,"awd"})
+        table.insert(options, 11, {})
 
     end
 

But, there are some problems. After I try running xmake as root, /dev/null becomes unwritable for common users. That might be a bug

That is, I found in core/src/xmake/process/openv.c, the stdout & stderr redirection of process.openv() is impled as this:

    // redirect stdout?
    if (outfile)
    {
        // redirect stdout to file
        attr.outfile = outfile;
        attr.outmode = TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_APPEND;

        // remove the outfile first
        if (tb_file_info(outfile, tb_null))
            tb_file_remove(outfile);
    }

    // redirect stderr?
    if (errfile)
    {
        // redirect stderr to file
        attr.errfile = errfile;
        attr.errmode = TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_APPEND;

        // remove the errfile first
        if (tb_file_info(errfile, tb_null))
            tb_file_remove(errfile);
    }

If the file exists, this function removes it and recreate. As root, the new /dev/null will have wrong permission

@waruqi
Copy link
Member

waruqi commented May 21, 2017

@745275633 我修改了下xmake,master上新版本支持临时允许root运行,通过命令: sudo xmake --root f -c, sudo xmake --root ,所有命令前加上 --root参数..

@waruqi
Copy link
Member

waruqi commented May 21, 2017

@titansnow

But, the option root has not been add to common option. That means we cannot use xmake --root. That should be a mistake. @waruqi

I have modified it as common option.

But, there are some problems. After I try running xmake as root, /dev/null becomes unwritable for common users. That might be a bug

I have fixed it.

@waruqi
Copy link
Member

waruqi commented May 23, 2017

@745275633 see #113.

@waruqi waruqi closed this as completed May 23, 2017
@waruqi waruqi added this to the v2.1.5 milestone Jun 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants