Skip to content

Instantly share code, notes, and snippets.

@talshorer
Last active June 13, 2017 16:04
Show Gist options
  • Save talshorer/61be1bc3472cc2a7b4866b9bd5a239ca to your computer and use it in GitHub Desktop.
Save talshorer/61be1bc3472cc2a7b4866b9bd5a239ca to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>
#include <sys/inotify.h>
int main(int argc, char *argv[])
{
int ifd;
union {
struct inotify_event ie;
unsigned char buf[0x200];
} event;
unsigned int i = 1;
int fd;
int n;
char state[0x100];
if (argc < 2)
return i;
i++;
ifd = inotify_init();
if (ifd < 0)
return i;
i++;
if (inotify_add_watch(ifd, argv[1], IN_MODIFY) < 0)
return i;
i++;
while (true) {
read(ifd, &event.ie, sizeof(event.buf));
fd = open(argv[1], O_RDONLY);
if (fd < 0)
return i;
n = read(fd, state, sizeof(state));
state[n - 1] = 0;
close(fd);
if (!strcmp(state, "configured"))
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment