1.在程序main函数处添加

    setuid(0);

    setgid(0);

 

2.修改executable file(因为app引导时候是不允许root权限的程序运行的)

打开.app,找到其中的可执行文件,复制一份,并用一下内容替换

#!/bin/bash
root=$(dirname "$0")
exec "${root}"/textxt_

(注意标点符号)

(原理:用这个脚本去引导我们的程序,脚本不是root权限的,所以能通过)

 

3.打包deb时候,将postinst脚本写入deb中,postinst脚本内容如下:(脚本的作用是在包被复制到application目录下的时候,修改包中可执行文件的权限)

#!/bin/bash

cd "/Applications/textxt.app/"

# process origin binary
chown root.wheel textxt_
chmod +s textxt_
chmod +x textxt_

 

相关文章:

猜你喜欢
相关资源
相似解决方案