run part of code as root

2019-03-03 21:54发布

I have a package which runs uses Gtk and written in vala.A dialog box or a gui opens after selecting a file.I want this dialog box or gui to run as root so as to open and read the files which don't open with normal users.I have this code

static void open_file(string filename) {
    selected_file = filename;
    stdout.printf(selected_file);
    new ProgressWindow(selected_file, {});

}

I want to run ProgressWindow to run as root.Is it possible?

标签: gtk root gtk3 vala
1条回答
姐就是有狂的资本
2楼-- · 2019-03-03 21:58

No. To run as root, it must be in a separate process and you must run that process using pkexec via PolicyKit. Here's a tutorial on PolicyKit in Vala.

查看更多
登录 后发表回答