Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* SPDX-License-Identifier: MIT-0 */
- #include <stdio.h>
- #include <string.h>
- #include <sys/inotify.h>
- #include <systemd/sd-event.h>
- #define _cleanup_(f) __attribute__((cleanup(f)))
- static int inotify_handler(sd_event_source *source,
- const struct inotify_event *event, void *userdata)
- {
- char *path = NULL;
- int r = sd_event_source_get_inotify_path(source, &path);
- printf("path: in inotify_handler: %s, err: %d\n", path, r);
- return 0;
- }
- int main(int argc, char **argv)
- {
- sd_event_source *source = NULL;
- sd_event *event = NULL;
- const char *path = argc > 1 ? argv[1] : "/tmp";
- char *path2;
- sd_event_default(&event);
- sd_event_add_inotify(event, &source, path,
- IN_CREATE | IN_DELETE | IN_MODIFY | IN_MOVED_TO,
- inotify_handler, NULL);
- sd_event_source_get_inotify_path(source, &path2);
- printf("path in main: %s\n", path2);
- sd_event_loop(event);
- return 0;
- }
- /*
- $ ./sd
- path in main: /tmp
- path: in inotify_handler: (null), err: -116
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement