以root身份运行部分代码 [英] run part of code as root

查看:142
本文介绍了以root身份运行部分代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行使用Gtk并以vala编写的软件包。选择一个文件后会打开一个对话框或一个gui。我希望这个对话框或gui以root身份运行,以便打开并读取这些文件, t打开普通users.I这个代码

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, {});

}

我想运行 ProgressWindow 以root身份运行。是否有可能?

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

推荐答案

要以root用户身份运行,它必须位于单独的进程中,并且必须通过PolicyKit使用 pkexec 运行该进程。以下是Vala中 PolicyKit教程

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.

这篇关于以root身份运行部分代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆