您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

通过/ proc / mounts监视挂载点更改

通过/ proc / mounts监视挂载点更改

linux内核中有一个错误修复描述了这种行为:

SUSv3说“常规文件应始终对TRUE进行读写”。参见http://www.opengroup.org/onlinepubs/009695399/functions/poll.html

因此,您必须在POLLPRI中使用poll | POLLERR标志。像这样:

     int mfd = open("/proc/mounts", O_RDONLY, 0);
     struct pollfd pfd;
     int rv;

     int changes = 0;
     pfd.fd = mfd;
     pfd.events = POLLERR | POLLPRI;
     pfd.revents = 0;
     while ((rv = poll(&pfd, 1, 5)) >= 0) {
          if (pfd.revents & POLLERR) {
               fprintf(stdout, "Mount points changed. %d.\n", changes++);
          }

          pfd.revents = 0;
          if (changes > 10) {
               exit(EXIT_FAILURE);
          }
     }
其他 2022/1/1 18:22:47 有633人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶