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

Comments

Projects
None yet
3 participants
@71e6fd52
Contributor

71e6fd52 commented May 21, 2017

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

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 21, 2017

Contributor

See #61

Contributor

TitanSnow commented May 21, 2017

See #61

@71e6fd52

This comment has been minimized.

Show comment
Hide comment
@71e6fd52

71e6fd52 May 21, 2017

Contributor

我需要使用 root 运行 xmake

Contributor

71e6fd52 commented May 21, 2017

我需要使用 root 运行 xmake

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 21, 2017

Contributor

#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

Contributor

TitanSnow 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

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 21, 2017

Member

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

Member

waruqi commented May 21, 2017

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

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 21, 2017

Member

@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.

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

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 23, 2017

Member

@745275633 see #113.

Member

waruqi commented May 23, 2017

@745275633 see #113.

@waruqi waruqi closed this 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