/* * Copyright (C) 2017 Hewlett Packard Enterprise Development LP * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. */ #include #include #include #include #include #include #include int main(int argc, char **argv) { int fd, ret; fd_set fds; char buf[256]; if (argc != 2) { printf("USAGE: test_sysfs_notify badblocks-path\n"); exit(1); } if ((fd = open(argv[1], O_RDONLY)) < 0) { printf("Unable to open %s\n", argv[1]); exit(1); } printf("Monitoring %s - ctl-c to stop\n", argv[1]); while (1) { memset(buf, 0, sizeof(buf)); ret = lseek(fd, 0, SEEK_SET); ret = read(fd, buf, sizeof(buf)); printf("%s\n", buf); FD_ZERO(&fds); FD_SET(fd, &fds); ret = select(fd + 1, NULL, NULL, &fds, NULL); if (ret <= 0) { printf("error (%d)\n", ret); exit(1); } else if (FD_ISSET(fd, &fds)) { printf("NOTIFIED!!\n"); } } close(fd); }