免费注册 查看新帖 |

Chinaunix

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

[系统管理] Dnotify fcntl 问题----Dnotify 在redhat4 跟 redhat6下有差别? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-04-26 16:00 |只看该作者 |倒序浏览
本帖最后由 dubin1114 于 2012-04-26 16:41 编辑

代码如下
  1.         #define _GNU_SOURCE     /* needed to get the defines */
  2.         #include <fcntl.h>      /* in glibc 2.2 this has the needed

  3.                                            values defined */

  4.         #include <signal.h>

  5.         #include <stdio.h>

  6.         #include <unistd.h>


  7.         static volatile int event_fd;


  8.         static void handler(int sig, siginfo_t *si, void *data)

  9.         {

  10.                 event_fd = si->si_fd;

  11.         }


  12.         int main(void)

  13.         {

  14.                 struct sigaction act;

  15.                 int fd;


  16.                 act.sa_sigaction = handler;

  17.                 sigemptyset(&act.sa_mask);

  18.                 act.sa_flags = SA_SIGINFO;

  19.                 sigaction(SIGRTMIN + 1, &act, NULL);


  20.                 fd = open("/opt/dnotify", O_RDONLY);

  21.                 fcntl(fd, F_SETSIG, SIGRTMIN + 1);

  22.                 fcntl(fd, F_NOTIFY,DN_ACCESS|DN_MODIFY|DN_CREATE|DN_RENAME|DN_DELETE|DN_ATTRIB|DN_MULTISHOT);

  23.                 /* we will now be notified if any of the files

  24.                    in "." is modified or new files are created */

  25.                 while (1) {


  26.                         pause();

  27.                         printf("Got event on fd=%d\n", event_fd);

  28.                 }

  29.         }
复制代码
以上代码对/opt/dnotify进行了监视。但是在改变被保护文件夹的权限时下面的系统反应不一样。

在redhat4 跟redhat5下:使用 chmod  444 /opt/dnotify  没有事件发生。

但是在redhat6下:同样适用chmod  444 /opt/dnotify  却有事件发生并且程序中断了。

这是为什么?

论坛徽章:
0
2 [报告]
发表于 2012-04-26 18:39 |只看该作者
急啊,自己顶顶!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP