diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-07-22 20:01:11 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-22 20:01:11 +0200 |
commit | c8e2bb5605adea7fff02a0e51b8246f944ba29ad (patch) | |
tree | ac7155364208f7dd559a5d594e1a47df93427cd0 /Userland/mon.cpp | |
parent | a9adf4c95b8ee3ba892878daec81d6cfc809be75 (diff) | |
download | serenity-c8e2bb5605adea7fff02a0e51b8246f944ba29ad.zip |
Kernel: Add a mechanism for listening for changes to an inode.
The syscall is quite simple:
int watch_file(const char* path, int path_length);
It returns a file descriptor referring to a "InodeWatcher" object in the
kernel. It becomes readable whenever something changes about the inode.
Currently this is implemented by hooking the "metadata dirty bit" in
Inode which isn't perfect, but it's a start. :^)
Diffstat (limited to 'Userland/mon.cpp')
-rw-r--r-- | Userland/mon.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Userland/mon.cpp b/Userland/mon.cpp new file mode 100644 index 0000000000..c8980ca388 --- /dev/null +++ b/Userland/mon.cpp @@ -0,0 +1,29 @@ +#include <AK/LogStream.h> +#include <fcntl.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +int main(int argc, char** argv) +{ + const char* path = argc > 1 ? argv[1] : "."; + int watch_fd = watch_file(path, strlen(path)); + if (watch_fd < 0) { + perror("Unable to watch"); + return 1; + } + for (;;) { + char buffer[256]; + int rc = read(watch_fd, buffer, sizeof(buffer)); + if (rc < 0) { + perror("read"); + return 1; + } + if (rc == 0) { + printf("End-of-file.\n"); + return 0; + } + printf("Something changed about '%s'\n", path); + } + return 0; +} |