1static gboolean 2meta_window_update_snap_id (MetaWindow *window, 3 uint32_t pid) 4{ 5 g_autofree char *security_label_filename = NULL; 6 g_autofree char *security_label_contents = NULL; 7 gsize i, security_label_contents_size = 0; 8 char *contents_start; 9 char *contents_end;10 char *sandboxed_app_id;1112 g_return_val_if_fail (pid != 0, FALSE);13 g_return_val_if_fail (window->sandboxed_app_id == NULL, FALSE);1415 security_label_filename = g_strdup_printf ("/proc/%u/attr/current", pid);1617 if (!g_file_get_contents (security_label_filename,18 &security_label_contents,19 &security_label_contents_size,20 NULL))21 return FALSE;2223 if (!g_str_has_prefix (security_label_contents, SNAP_SECURITY_LABEL_PREFIX))24 return FALSE;2526 /* We need to translate the security profile into the desktop-id.27 * The profile is in the form of 'snap.name-space.binary-name (current)'28 * while the desktop id will be name-space_binary-name.29 */30 security_label_contents_size -= sizeof (SNAP_SECURITY_LABEL_PREFIX) - 1;31 contents_start = security_label_contents + sizeof (SNAP_SECURITY_LABEL_PREFIX) - 1;32 contents_end = strchr (contents_start, ' ');3334 if (contents_end)35 security_label_contents_size = contents_end - contents_start;3637 for (i = 0; i < security_label_contents_size; ++i)38 {39 if (contents_start[i] == '.')40 contents_start[i] = '_';41 }4243 sandboxed_app_id = g_malloc0 (security_label_contents_size + 1);44 memcpy (sandboxed_app_id, contents_start, security_label_contents_size);4546 window->sandboxed_app_id = sandboxed_app_id;4748 return TRUE;49}