我正在尝试编写一个程序,并将其与使用Gtk+构建的gui集成。要调用的exe文件已设置了setuid位。然而,Gtk不允许此exe按照gtk社区指定的方式运行。他们说我们必须编写单独的帮助程序之类的东西,但我真的不明白这是什么意思。有人能否请解释一下如何解决这个问题?我真的需要一个即时的解决方案。
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int
main(int ar_argc,
char **ar_argv
)
{
setenv("HOME","/u/wally",1);
/* Set other environment variables as appropriate. */
if(setgid(1234))
{
fprintf(stderr,"setgid() fail\n");
exit(1);
};
if(setuid(1234))
{
fprintf(stderr,"setuid() fail\n");
exit(1);
};
/* Use execl() and friends, or system(), to do what you want here. */
return 0;
}
您仍然应该查看外围设备的权限是否正确,或者为什么需要从只有root才能读取的设备中读取数据。