"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "common/flatpak-instance.c" between
flatpak-1.15.1.tar.xz and flatpak-1.15.2.tar.xz

About: Flatpak is a Linux application sandboxing and distribution framework. Pre-release.

flatpak-instance.c  (flatpak-1.15.1.tar.xz):flatpak-instance.c  (flatpak-1.15.2.tar.xz)
skipping to change at line 325 skipping to change at line 325
{ {
g_autofree char *file = NULL; g_autofree char *file = NULL;
g_autoptr(GKeyFile) key_file = NULL; g_autoptr(GKeyFile) key_file = NULL;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
file = g_build_filename (dir, "info", NULL); file = g_build_filename (dir, "info", NULL);
key_file = g_key_file_new (); key_file = g_key_file_new ();
if (!g_key_file_load_from_file (key_file, file, G_KEY_FILE_NONE, &error)) if (!g_key_file_load_from_file (key_file, file, G_KEY_FILE_NONE, &error))
{ {
g_debug ("Failed to load instance info file '%s': %s", file, error->messag e); g_info ("Failed to load instance info file '%s': %s", file, error->message );
return NULL; return NULL;
} }
return g_steal_pointer (&key_file); return g_steal_pointer (&key_file);
} }
static int static int
get_child_pid (const char *dir) get_child_pid (const char *dir)
{ {
g_autofree char *file = NULL; g_autofree char *file = NULL;
skipping to change at line 347 skipping to change at line 347
gsize length; gsize length;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
g_autoptr(JsonParser) parser = NULL; g_autoptr(JsonParser) parser = NULL;
JsonNode *node; JsonNode *node;
JsonObject *obj; JsonObject *obj;
file = g_build_filename (dir, "bwrapinfo.json", NULL); file = g_build_filename (dir, "bwrapinfo.json", NULL);
if (!g_file_get_contents (file, &contents, &length, &error)) if (!g_file_get_contents (file, &contents, &length, &error))
{ {
g_debug ("Failed to load bwrapinfo.json file '%s': %s", file, error->messa ge); g_info ("Failed to load bwrapinfo.json file '%s': %s", file, error->messag e);
return 0; return 0;
} }
parser = json_parser_new (); parser = json_parser_new ();
if (!json_parser_load_from_data (parser, contents, length, &error)) if (!json_parser_load_from_data (parser, contents, length, &error))
{ {
g_debug ("Failed to parse bwrapinfo.json file '%s': %s", file, error->mess age); g_info ("Failed to parse bwrapinfo.json file '%s': %s", file, error->messa ge);
return 0; return 0;
} }
node = json_parser_get_root (parser); node = json_parser_get_root (parser);
if (!node) if (!node)
{ {
g_debug ("Failed to parse bwrapinfo.json file '%s': %s", file, "empty"); g_info ("Failed to parse bwrapinfo.json file '%s': %s", file, "empty");
return 0; return 0;
} }
obj = json_node_get_object (node); obj = json_node_get_object (node);
return json_object_get_int_member (obj, "child-pid"); return json_object_get_int_member (obj, "child-pid");
} }
static int static int
get_pid (const char *dir) get_pid (const char *dir)
{ {
g_autofree char *file = NULL; g_autofree char *file = NULL;
g_autofree char *contents = NULL; g_autofree char *contents = NULL;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
file = g_build_filename (dir, "pid", NULL); file = g_build_filename (dir, "pid", NULL);
if (!g_file_get_contents (file, &contents, NULL, &error)) if (!g_file_get_contents (file, &contents, NULL, &error))
{ {
g_debug ("Failed to load pid file '%s': %s", file, error->message); g_info ("Failed to load pid file '%s': %s", file, error->message);
return 0; return 0;
} }
return (int) g_ascii_strtoll (contents, NULL, 10); return (int) g_ascii_strtoll (contents, NULL, 10);
} }
FlatpakInstance * FlatpakInstance *
flatpak_instance_new (const char *dir) flatpak_instance_new (const char *dir)
{ {
FlatpakInstance *self = g_object_new (flatpak_instance_get_type (), NULL); FlatpakInstance *self = g_object_new (flatpak_instance_get_type (), NULL);
skipping to change at line 770 skipping to change at line 770
* setup and in bwrap. Anyone trying to clean up unused * setup and in bwrap. Anyone trying to clean up unused
* directories need to first verify that there is a .ref * directories need to first verify that there is a .ref
* file and take a write lock on .ref to ensure its not in * file and take a write lock on .ref to ensure its not in
* use. */ * use. */
lock_fd = open (lock_file, O_RDWR | O_CREAT | O_CLOEXEC, 0644); lock_fd = open (lock_file, O_RDWR | O_CREAT | O_CLOEXEC, 0644);
/* There is a tiny race here between the open creating the file and th e lock succeeding. /* There is a tiny race here between the open creating the file and th e lock succeeding.
We work around that by only gc:ing "old" .ref files */ We work around that by only gc:ing "old" .ref files */
if (lock_fd != -1 && fcntl (lock_fd, F_SETLK, &l) == 0) if (lock_fd != -1 && fcntl (lock_fd, F_SETLK, &l) == 0)
{ {
*lock_fd_out = glnx_steal_fd (&lock_fd); *lock_fd_out = glnx_steal_fd (&lock_fd);
g_debug ("Allocated instance id %s", instance_id); g_info ("Allocated instance id %s", instance_id);
*host_dir_out = g_steal_pointer (&instance_dir); *host_dir_out = g_steal_pointer (&instance_dir);
return g_steal_pointer (&instance_id); return g_steal_pointer (&instance_id);
} }
} }
} }
return NULL; return NULL;
} }
FlatpakInstance * FlatpakInstance *
skipping to change at line 993 skipping to change at line 993
return glnx_throw_errno_prefix (error, "lock %s/.ref", per_app_dir); return glnx_throw_errno_prefix (error, "lock %s/.ref", per_app_dir);
if (fstat (per_app_dir_lock_fd, &statbuf) < 0) if (fstat (per_app_dir_lock_fd, &statbuf) < 0)
return glnx_throw_errno_prefix (error, "fstat %s/.ref", per_app_dir); return glnx_throw_errno_prefix (error, "fstat %s/.ref", per_app_dir);
/* Only gc if created at least 3 secs ago, to work around the equivalent /* Only gc if created at least 3 secs ago, to work around the equivalent
* of the race mentioned in flatpak_instance_allocate_id() */ * of the race mentioned in flatpak_instance_allocate_id() */
if (statbuf.st_mtime + 3 >= time (NULL)) if (statbuf.st_mtime + 3 >= time (NULL))
return glnx_throw (error, "lock file too recent, avoiding race condition"); return glnx_throw (error, "lock file too recent, avoiding race condition");
g_debug ("Cleaning up per-app-ID state for %s", app_id); g_info ("Cleaning up per-app-ID state for %s", app_id);
/* /dev/shm is offloaded onto the host's /dev/shm to get consistent /* /dev/shm is offloaded onto the host's /dev/shm to get consistent
* free space behaviour and make sure it's actually in RAM. It could * free space behaviour and make sure it's actually in RAM. It could
* contain relatively large files, so we clean it up. * contain relatively large files, so we clean it up.
* *
* In principle this could be used for other directories such as /tmp, * In principle this could be used for other directories such as /tmp,
* in a loop over an array of paths (hence this indentation), but we * in a loop over an array of paths (hence this indentation), but we
* only do this for /dev/shm right now. */ * only do this for /dev/shm right now. */
do do
{ {
skipping to change at line 1021 skipping to change at line 1021
per_app_dir_lock_fd, per_app_dir_lock_fd,
per_app_dir_fd, per_app_dir_fd,
"dev-shm", "dev-shm",
"/dev/shm", "/dev/shm",
&path, &path,
&local_error)) &local_error))
{ {
g_assert (g_str_has_prefix (path, "/dev/shm/")); g_assert (g_str_has_prefix (path, "/dev/shm/"));
if (unlinkat (per_app_dir_fd, "dev-shm", 0) != 0) if (unlinkat (per_app_dir_fd, "dev-shm", 0) != 0)
g_debug ("Unable to clean up %s/%s: %s", g_info ("Unable to clean up %s/%s: %s",
per_app_dir, "dev-shm", g_strerror (errno)); per_app_dir, "dev-shm", g_strerror (errno));
if (!glnx_shutil_rm_rf_at (AT_FDCWD, path, NULL, &local_error)) if (!glnx_shutil_rm_rf_at (AT_FDCWD, path, NULL, &local_error))
{ {
g_debug ("Unable to clean up %s: %s", g_info ("Unable to clean up %s: %s",
path, local_error->message); path, local_error->message);
g_clear_error (&local_error); g_clear_error (&local_error);
} }
} }
else if (unlinkat (per_app_dir_fd, "dev-shm", 0) < 0 && errno == ENOENT) else if (unlinkat (per_app_dir_fd, "dev-shm", 0) < 0 && errno == ENOENT)
{ {
/* ignore, the symlink wasn't even there anyway */ /* ignore, the symlink wasn't even there anyway */
g_clear_error (&local_error); g_clear_error (&local_error);
} }
else else
{ {
g_debug ("%s/%s no longer points to the expected directory and " g_info ("%s/%s no longer points to the expected directory and "
"was removed: %s", "was removed: %s",
per_app_dir, "dev-shm", local_error->message); per_app_dir, "dev-shm", local_error->message);
g_clear_error (&local_error); g_clear_error (&local_error);
} }
} }
while (0); while (0);
/* We currently allocate the app's /tmp directly in the per-app directory /* We currently allocate the app's /tmp directly in the per-app directory
* on the host's XDG_RUNTIME_DIR, instead of offloading it into /tmp * on the host's XDG_RUNTIME_DIR, instead of offloading it into /tmp
* in a way that's analogous to /dev/shm, so we expect tmp to be a directory * in a way that's analogous to /dev/shm, so we expect tmp to be a directory
* and not a symlink. If it's a symlink, we'll just unlink it. */ * and not a symlink. If it's a symlink, we'll just unlink it. */
if (!glnx_shutil_rm_rf_at (per_app_dir_fd, "tmp", NULL, &local_error)) if (!glnx_shutil_rm_rf_at (per_app_dir_fd, "tmp", NULL, &local_error))
{ {
g_debug ("Unable to clean up %s/tmp: %s", per_app_dir, g_info ("Unable to clean up %s/tmp: %s", per_app_dir,
local_error->message); local_error->message);
g_clear_error (&local_error); g_clear_error (&local_error);
} }
/* Deliberately don't clean up the .ref lock file or the directory itself. /* Deliberately don't clean up the .ref lock file or the directory itself.
* If we did that, we'd defeat our locking scheme, because a concurrent * If we did that, we'd defeat our locking scheme, because a concurrent
* process could open the .ref file just before we unlink it. */ * process could open the .ref file just before we unlink it. */
return TRUE; return TRUE;
} }
void void
skipping to change at line 1107 skipping to change at line 1107
fstat (lock_fd, &statbuf) == 0 && fstat (lock_fd, &statbuf) == 0 &&
/* Only gc if created at least 3 secs ago, to work around race men tioned in /* Only gc if created at least 3 secs ago, to work around race men tioned in
* flatpak_instance_allocate_id() */ * flatpak_instance_allocate_id() */
statbuf.st_mtime + 3 < time (NULL) && statbuf.st_mtime + 3 < time (NULL) &&
fcntl (lock_fd, F_GETLK, &l) == 0 && fcntl (lock_fd, F_GETLK, &l) == 0 &&
l.l_type == F_UNLCK) l.l_type == F_UNLCK)
{ {
g_autoptr(GError) local_error = NULL; g_autoptr(GError) local_error = NULL;
/* The instance is not used, remove it */ /* The instance is not used, remove it */
g_debug ("Cleaning up unused container id %s", dent->d_name); g_info ("Cleaning up unused container id %s", dent->d_name);
if (!flatpak_instance_gc_per_app_dirs (dent->d_name, &local_error) ) if (!flatpak_instance_gc_per_app_dirs (dent->d_name, &local_error) )
flatpak_debug2 ("Not cleaning up per-app dir: %s", local_error-> message); g_debug ("Not cleaning up per-app dir: %s", local_error->message );
glnx_shutil_rm_rf_at (iter.fd, dent->d_name, NULL, NULL); glnx_shutil_rm_rf_at (iter.fd, dent->d_name, NULL, NULL);
continue; continue;
} }
if (out_instances != NULL) if (out_instances != NULL)
g_ptr_array_add (out_instances, flatpak_instance_new_for_id (dent->d _name)); g_ptr_array_add (out_instances, flatpak_instance_new_for_id (dent->d _name));
} }
} }
} }
 End of changes. 13 change blocks. 
18 lines changed or deleted 18 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)