免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2838 | 回复: 0
打印 上一主题 下一主题

[操作系统] setuid() hang in multithread application [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-12-13 19:18 |只看该作者 |倒序浏览
hi, 各位大侠

在Freescale P1020RDB上,gcc-4.3.74 + linux .32 + eglibc-2.8.74, 我遇到了这样一个问题:
     libc setuid() function hang in multithread application, 无论是main thread还是之后fork出的thread,只要有多threads,就一定会hang。


单独运行是就hang住了,但用strace跟踪就不会hang。  

发现在sys_setuid()中的确是看到system call是成功了的,但thread是hang在了do_futex()中。


我的测试程序如下:
/*
*        a subthread to setuid(0)
*/
void* tfunc_setuid(void *arg)
{
        int i = 0;

                setuid(0);

        return NULL;
}

int main(int args, char **argv)
{
        pthread_t tid_setuid = 0;
        int i = 0;

        pthread_create(&tid_setuid, NULL, tfunc_setuid, NULL);

        pthread_join(tid_setuid, NULL);

        return 0;
}


"strace"的输出如下:

clone(Process 7456 attached
child_stack=0x4882e030, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_
THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, pare
nt_tidptr=0x4882e4f8, tls=0x48835930, child_tidptr=0x4882e4f = 7456
[pid  7455] futex(0x4882e4f8, FUTEX_WAIT, 7456, NULL <unfinished ...>
[pid  7456] get_robust_list(0x4882e500, 0xc, 0x4882e4f = 0
[pid  7456] tgkill(7455, 7455, SIGRT_1) = 0
[pid  7455] <... futex resumed> )       = ? ERESTARTSYS (To be restarted)
[pid  7456] futex(0x4882dd48, FUTEX_WAIT_PRIVATE, 1, NULL <unfinished ...>
[pid  7455] --- SIGRT_1 (Unknown signal 33) @ 0 (0) ---
[pid  7455] setuid(0)                   = 0                                                                                # 这里一个setuid(),为什么main thread会调用setuid(0)  ???
[pid  7455] futex(0x4882dd48, FUTEX_WAKE_PRIVATE, 1 <unfinished ...>
[pid  7456] <... futex resumed> )       = 0
[pid  7455] <... futex resumed> )       = 1
[pid  7456] tgkill(7455, 7455, SIGRT_1 <unfinished ...>
[pid  7455] futex(0x4801f608, FUTEX_WAKE_PRIVATE, 1 <unfinished ...>
[pid  7456] <... tgkill resumed> )      = 0
[pid  7455] <... futex resumed> )       = 0
[pid  7456] futex(0x4882dd48, FUTEX_WAIT_PRIVATE, 1, NULL <unfinished ...>
[pid  7455] futex(0x4882dd48, FUTEX_WAKE_PRIVATE, 1 <unfinished ...>
[pid  7456] <... futex resumed> )       = -1 EAGAIN (Resource temporarily unavai
lable)
[pid  7455] <... futex resumed> )       = 0
[pid  7456] setuid(0 <unfinished ...>                                                                            # 这里是sub thread的setuid(0)
[pid  7455] rt_sigreturn(0 <unfinished ...>
[pid  7456] <... setuid resumed> )      = 0
[pid  7455] <... rt_sigreturn resumed> ) = -1216537848
[pid  7456] exit(0)                     = ?
Process 7456 detached
--- SIGRT_1 (Unknown signal 33) @ 0 (0) ---
syscall_268436712(0, 0x4882dd60, 0x100004e8, 0xbfac32a0, 0x4882e4f8, 0x48835930,
0x4882dd38, 0xffffe2e1, 0x4801f474, 0x100350, 0x10018854, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0x4882e6ac, 0x4801f410, 0xffed230, 0xffed1f8, 0x4882e4b0, 0xff
cc8a4, 0x2d900, 0) = -1 (errno 3
futex(0x4882dd48, FUTEX_WAKE_PRIVATE, 1) = 0
futex(0x4801f608, FUTEX_WAKE_PRIVATE, 1) = 0
rt_sigreturn(0)                         = -1216537848
futex(0x4882e4f8, FUTEX_WAIT, 7456, NULL) = -1 EAGAIN (Resource temporarily unav
ailable)
exit_group(0)                           = ?   



我不理解的地方有:
     从strace的输出来看,为什么main thread和sub thread都有setuid(),而在C code里我只在sub thread里调用了setuid() ?
     为什么会hang,是不是这个eglic在thread和signal上有什么问题?  在strace下这个测试程序是不会hang的,是不是和程序处于TASK_TRACED有关系。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP