run part of code as root

2019-03-03 21:48发布

问题:

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?

回答1:

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.



标签: gtk root gtk3 vala