I’ve never used C before. this script adds a listener onto a directory and notifies the user by echoing to the terminal and then exiting whenever a file event happens. I want to modify the script to NOT exit but instead continuing monitoring the folder. I think the key might be this line:
length = read( fd, buffer, BUF_LEN );
but I don’t really understand what is going on here. The description of the read() function is probably helpful for those who know C really well:
Using inotify is simple: Create a file descriptor, attach one or more watches (a watch is a path and set of events), and use the read() method to receive event information from the descriptor. Rather than burn scarce cycles, read() blocks until events occur.
but I don’t fall into that category.
The program exists simply because nothing stops it from getting to
exit( 0 );once it has caught an event. You could wrap everything fromfd = inotify_init();to( void ) close( fd );in a loop and it will start over as long as you want it to.The problem isn’t in
length = read( fd, buffer, BUF_LEN );. That part just waits for an event to happen and it doesn’t call for the program to exit. It’s really that themainis designed to be executed in one run-through and exit.