mirror of
https://github.com/flatpak/flatpak.git
synced 2026-05-19 14:22:18 -04:00
Fix detection of exported dbus-services with dbus-broker
Rather than unlinking and symlinking the new value we symling into a temporary name and then atomically renames on top of the (possibly) pre-existing file. This has two advantages. First it is atomic, whereas the previous code could end up removing the old code without creating the new one, and secondly this will generate a move inotify event which is what dbus-broker uses to detect changes in the services file directory. Fixes https://github.com/flatpak/flatpak/issues/3145
This commit is contained in:
committed by
Alexander Larsson
parent
65bbd6c761
commit
930b3d673d
@@ -7091,20 +7091,31 @@ export_dir (int source_parent_fd,
|
||||
}
|
||||
else if (S_ISREG (stbuf.st_mode))
|
||||
{
|
||||
g_autofree char *symlink_name = g_strdup (".export-symlink-XXXXXX");
|
||||
g_autofree gchar *target = NULL;
|
||||
|
||||
target = g_build_filename (source_symlink_prefix, dent->d_name, NULL);
|
||||
|
||||
if (unlinkat (destination_dfd, dent->d_name, 0) != 0 && errno != ENOENT)
|
||||
for (int count = 0; count < 100; count++)
|
||||
{
|
||||
glnx_set_error_from_errno (error);
|
||||
goto out;
|
||||
}
|
||||
glnx_gen_temp_name (symlink_name);
|
||||
|
||||
if (symlinkat (target, destination_dfd, dent->d_name) != 0)
|
||||
{
|
||||
glnx_set_error_from_errno (error);
|
||||
goto out;
|
||||
if (symlinkat (target, destination_dfd, symlink_name) != 0)
|
||||
{
|
||||
if (errno == EEXIST)
|
||||
continue;
|
||||
|
||||
glnx_set_error_from_errno (error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (renameat (destination_dfd, symlink_name, destination_dfd, dent->d_name) != 0)
|
||||
{
|
||||
glnx_set_error_from_errno (error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user