If you have a path unit with:
DirectoryNotEmpty=/foo
and "/foo" does not exist, creating it later escapes the attention of systemd.
When adding watches for parent directories, systemd never adds one for the root
directory. It attempts to add a watch for an empty string instead, which fails.
If the path is "/", we must not trim the slash.
};
bool exists = false;
- char *k;
+ char *k, *slash;
int r;
assert(p);
if ((s->primary_wd = inotify_add_watch(s->inotify_fd, k, flags_table[s->type])) >= 0)
exists = true;
- for (;;) {
+ do {
int flags;
- char *slash;
/* This assumes the path was passed through path_kill_slashes()! */
if (!(slash = strrchr(k, '/')))
break;
- *slash = 0;
+ /* Trim the path at the last slash. Keep the slash if it's the root dir. */
+ slash[slash == k] = 0;
flags = IN_DELETE_SELF|IN_MOVE_SELF|IN_ATTRIB;
if (!exists)
if (inotify_add_watch(s->inotify_fd, k, flags) >= 0)
exists = true;
- }
+ } while (slash != k);
return 0;