免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: xiaozhu2007
打印 上一主题 下一主题

[C] 不可重入函数getpwnam的问题 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-09-17 18:49 |只看该作者
原帖由 5毛党党员 于 2008-9-17 17:56 发表

应该是在调用getpwnam的时候产生了alarm信号,alarm的处理函数又调用了getpwnam时产生的



我的疑问就是为什么会在这个过程中产生sigsegv。
调用getpwnam,得到的结构指针指向的都是同一块内存(由后一个getpwnam分配的内存),只不过是内存里的东西被改写,结构没有发生改变

[ 本帖最后由 basical 于 2008-9-17 18:54 编辑 ]

论坛徽章:
0
12 [报告]
发表于 2008-09-17 23:16 |只看该作者
原帖由 xiaozhu2007 于 2007-12-25 23:48 发表
我理解的,getpwnam函数自己申请一个passwd结构的变量,然后只要在同一个进程中的任何地方和时间执行的时候都将得到的口令文件信息存放在这个结构中然后返回这个passwd结构的地址,所以虽然在main中和sig_handl ...
map 3p getpwnam
APPLICATION USAGE
       Three names associated with the current  process  can  be  determined:
       getpwuid(  geteuid())  returns  the name associated with the effective
       user ID of the process; getlogin() returns the  name  associated  with
       the  current  login activity; and getpwuid( getuid()) returns the name
       associated with the real user ID of the process.

       The getpwnam_r() function is thread-safe and returns values in a user-
       supplied  buffer instead of possibly using a static data area that may
       be overwritten by each call.

论坛徽章:
0
13 [报告]
发表于 2008-09-24 19:28 |只看该作者
原帖由 ivhb 于 2008-9-17 23:16 发表



你给我看man有什么用 ,还是没解答我的问题
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP