Skip to content

Instantly share code, notes, and snippets.

@talshorer
Last active June 13, 2017 16:04

Revisions

  1. talshorer revised this gist Jun 13, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion wait_udc_configured.c
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ int main(int argc, char *argv[])
    read(ifd, &event.ie, sizeof(event.buf));
    fd = open(argv[1], O_RDONLY);
    if (fd < 0)
    continue;
    return i;
    n = read(fd, state, sizeof(state));
    state[n - 1] = 0;
    close(fd);
  2. talshorer created this gist Jun 13, 2017.
    41 changes: 41 additions & 0 deletions wait_udc_configured.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #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)
    continue;
    n = read(fd, state, sizeof(state));
    state[n - 1] = 0;
    close(fd);
    if (!strcmp(state, "configured"))
    return 0;
    }
    }