Last active
June 13, 2017 16:04
-
-
Save talshorer/61be1bc3472cc2a7b4866b9bd5a239ca to your computer and use it in GitHub Desktop.
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
#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