启动后,我希望我的Linux程序删除root权限并切换到非特权帐户.我在网上找到了各种各样的例子,但对我的要求没有任何规范,特别是:
我发现的最好方法是:
uid_t new_uid = ...;
gid_t new_gid = ...;
gid_t rgid, egid, sgid;
if (setresgid(new_gid, new_gid, new_gid) < 0)
{
perror("setresgid");
exit(EXIT_FAILURE);
}
if (getresgid(&rgid, &egid, &sgid) < 0)
{
perror("getresgid");
exit(EXIT_FAILURE);
}
if (rgid != new_gid || egid != new_gid || sgid != new_gid)
{
printf("unexpected gid");
exit(EXIT_FAILURE);
}
if (setgroups(0, 0) != 0)
{
perror("setgroups");
exit(EXIT_FAILURE);
}
uid_t ruid, euid, suid;
if (setresuid(new_uid, new_uid, new_uid) < 0)
{
perror("setresuid");
exit(EXIT_FAILURE);
}
if …Run Code Online (Sandbox Code Playgroud) 任何人都可以解释为什么git describe使用一个计数作为"git log tag..input会显示的提交数量"[来自git-describe(1) ]?
从概念上讲,我曾经认为git-describe使用了自标签以来提交的数量作为单调增加的计数器.但是,它似乎实际上使用了从'input'可以访问的提交数减去'tag'可以访问的提交数.这是为什么?
在这种特殊情况下,我在分支("1.0")上创建了一个发布标记("1.0.0"),然后是一个补丁发布("1.0.1").我已合并[请参阅http://www.kernel.org/pub/software/scm/git/docs/gitworkflows.html ]分支更改为master.然而,当我git-描述一个关于master的更新的提交时,count会匹配git log tag..input的输出.我希望它匹配git log --ancestry-path tag..input.
谢谢.
我正在尝试使用splice(man 2 splice)将数据从UDP套接字直接复制到文件.不幸的是,第一次调用splice()会返回EINVAL.
手册页指出:
EINVAL Target file system doesn't support splicing; target file is opened in
append mode; neither of the descriptors refers to a pipe; or offset
given for nonseekable device.
Run Code Online (Sandbox Code Playgroud)
但是,我相信这些条件都不适用.我正在使用Fedora 15(内核2.6.40-4),所以我相信所有文件系统都支持splice().目标文件在第一次调用splice时应该是无关紧要的,但为了完整性我将通过它打开它open(path, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR).两个调用都使用管道,除了NULL之外,两个调用都不使用偏移量.
这是我的示例代码:
int sz = splice(sock_fd, 0, mPipeFds[1], 0, 8192, SPLICE_F_MORE);
if (-1 == sz)
{
int err = errno;
LOG4CXX_ERROR(spLogger, "splice from: " << strerror(err));
return 0;
}
sz = splice(mPipeFds[0], 0, file_fd, 0, …Run Code Online (Sandbox Code Playgroud)