Skip to content

Instantly share code, notes, and snippets.

@jiangzc
Created April 15, 2020 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiangzc/9304974a58e76c38d65d5c3b986a79ce to your computer and use it in GitHub Desktop.
Save jiangzc/9304974a58e76c38d65d5c3b986a79ce to your computer and use it in GitHub Desktop.
monitor mounting of disks in /proc/self/mountinfo
// 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