From ee04e7ef1cd18268a956a4ff3521642b2cfff84e Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Tue, 5 Nov 2013 13:59:20 +0100 Subject: owfd: p2pd: ignore inotify_add_watch() failure If the parent directory does not exist, yet, we cannot watch it. We would have to watch the parent of it until the directory itself is created (maybe multiple layers). Avoid this complexity by just polling with reasonable timeouts instead. Same for the file itself which might already exist (due to unclean shutdown) and might get recreated. Signed-off-by: David Herrmann --- src/p2pd_interface.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/p2pd_interface.c b/src/p2pd_interface.c index 8a17864..8f2bfab 100644 --- a/src/p2pd_interface.c +++ b/src/p2pd_interface.c @@ -127,8 +127,10 @@ static int wait_for_wpa(struct owfd_p2pd_interface *iface, w = inotify_add_watch(fd, iface->config->wpa_ctrldir, IN_CREATE | IN_MOVED_TO | IN_ONLYDIR); if (w < 0) { - r = log_ERRNO(); - goto err_close; + /* Ignore failure to watch directory. The directory might not + * have been created, yet (neither it's parents). Avoid any + * complexity to watch the parent-path and just poll for + * changes below with a reasonable sleep-time. */ } /* verify wpa_supplicant is still alive */ @@ -186,14 +188,14 @@ static int wait_for_wpa(struct owfd_p2pd_interface *iface, } /* remove directory watch */ - inotify_rm_watch(fd, w); + if (w >= 0) + inotify_rm_watch(fd, w); /* add socket watch */ w = inotify_add_watch(fd, file, IN_OPEN | IN_DELETE_SELF | IN_MOVE_SELF); if (w < 0) { - r = log_ERRNO(); - goto err_close; + /* see above why we can ignore this */ } /* verify wpa_supplicant is still alive */ -- cgit v1.2.3