Created
April 15, 2020 04:37
-
-
Save jiangzc/9304974a58e76c38d65d5c3b986a79ce to your computer and use it in GitHub Desktop.
monitor mounting of disks in /proc/self/mountinfo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// complie hint: gcc xxx.c -lmount | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <libmount/libmount.h> | |
int main() | |
{ | |
const char *filename; | |
struct libmnt_monitor *mn = mnt_new_monitor(); | |
mnt_monitor_enable_kernel(mn, 1); | |
printf("waiting for changes...\n"); | |
while (mnt_monitor_wait(mn, -1) > 0) | |
{ | |
while (mnt_monitor_next_change(mn, &filename, NULL) == 0) | |
printf(" %s: change detected\n", filename); | |
} | |
mnt_unref_monitor(mn); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment