mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-01-04 06:10:16 +01:00
update_desktop_file_entry: unify cleanup code for success and failure cases
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=33126
This commit is contained in:
parent
fbecc33435
commit
75cfd97fc2
1 changed files with 17 additions and 18 deletions
|
|
@ -264,6 +264,7 @@ update_desktop_file_entry (BusActivation *activation,
|
||||||
DBusStat stat_buf;
|
DBusStat stat_buf;
|
||||||
DBusString file_path;
|
DBusString file_path;
|
||||||
DBusError tmp_error;
|
DBusError tmp_error;
|
||||||
|
dbus_bool_t retval;
|
||||||
|
|
||||||
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
||||||
|
|
||||||
|
|
@ -286,14 +287,14 @@ update_desktop_file_entry (BusActivation *activation,
|
||||||
!_dbus_concat_dir_and_file (&file_path, filename))
|
!_dbus_concat_dir_and_file (&file_path, filename))
|
||||||
{
|
{
|
||||||
BUS_SET_OOM (error);
|
BUS_SET_OOM (error);
|
||||||
goto failed;
|
goto finally;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_dbus_stat (&file_path, &stat_buf, NULL))
|
if (!_dbus_stat (&file_path, &stat_buf, NULL))
|
||||||
{
|
{
|
||||||
dbus_set_error (error, DBUS_ERROR_FAILED,
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
||||||
"Can't stat the service file\n");
|
"Can't stat the service file\n");
|
||||||
goto failed;
|
goto finally;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bus_desktop_file_get_string (desktop_file,
|
if (!bus_desktop_file_get_string (desktop_file,
|
||||||
|
|
@ -301,14 +302,14 @@ update_desktop_file_entry (BusActivation *activation,
|
||||||
DBUS_SERVICE_NAME,
|
DBUS_SERVICE_NAME,
|
||||||
&name,
|
&name,
|
||||||
error))
|
error))
|
||||||
goto failed;
|
goto finally;
|
||||||
|
|
||||||
if (!bus_desktop_file_get_string (desktop_file,
|
if (!bus_desktop_file_get_string (desktop_file,
|
||||||
DBUS_SERVICE_SECTION,
|
DBUS_SERVICE_SECTION,
|
||||||
DBUS_SERVICE_EXEC,
|
DBUS_SERVICE_EXEC,
|
||||||
&exec_tmp,
|
&exec_tmp,
|
||||||
error))
|
error))
|
||||||
goto failed;
|
goto finally;
|
||||||
|
|
||||||
exec = _dbus_strdup (_dbus_replace_install_prefix (exec_tmp));
|
exec = _dbus_strdup (_dbus_replace_install_prefix (exec_tmp));
|
||||||
dbus_free (exec_tmp);
|
dbus_free (exec_tmp);
|
||||||
|
|
@ -325,7 +326,7 @@ update_desktop_file_entry (BusActivation *activation,
|
||||||
if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY))
|
if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY))
|
||||||
{
|
{
|
||||||
dbus_move_error (&tmp_error, error);
|
dbus_move_error (&tmp_error, error);
|
||||||
goto failed;
|
goto finally;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -348,7 +349,7 @@ update_desktop_file_entry (BusActivation *activation,
|
||||||
if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY))
|
if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY))
|
||||||
{
|
{
|
||||||
dbus_move_error (&tmp_error, error);
|
dbus_move_error (&tmp_error, error);
|
||||||
goto failed;
|
goto finally;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -373,14 +374,14 @@ update_desktop_file_entry (BusActivation *activation,
|
||||||
{
|
{
|
||||||
dbus_set_error (error, DBUS_ERROR_FAILED,
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
||||||
"Service %s already exists in activation entry list\n", name);
|
"Service %s already exists in activation entry list\n", name);
|
||||||
goto failed;
|
goto finally;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry = dbus_new0 (BusActivationEntry, 1);
|
entry = dbus_new0 (BusActivationEntry, 1);
|
||||||
if (entry == NULL)
|
if (entry == NULL)
|
||||||
{
|
{
|
||||||
BUS_SET_OOM (error);
|
BUS_SET_OOM (error);
|
||||||
goto failed;
|
goto finally;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry->name = name;
|
entry->name = name;
|
||||||
|
|
@ -394,18 +395,19 @@ update_desktop_file_entry (BusActivation *activation,
|
||||||
exec = NULL;
|
exec = NULL;
|
||||||
user = NULL;
|
user = NULL;
|
||||||
systemd_service = NULL;
|
systemd_service = NULL;
|
||||||
|
|
||||||
entry->s_dir = s_dir;
|
entry->s_dir = s_dir;
|
||||||
entry->filename = _dbus_strdup (_dbus_string_get_const_data (filename));
|
entry->filename = _dbus_strdup (_dbus_string_get_const_data (filename));
|
||||||
if (!entry->filename)
|
if (!entry->filename)
|
||||||
{
|
{
|
||||||
BUS_SET_OOM (error);
|
BUS_SET_OOM (error);
|
||||||
goto failed;
|
goto finally;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_dbus_hash_table_insert_string (activation->entries, entry->name, bus_activation_entry_ref (entry)))
|
if (!_dbus_hash_table_insert_string (activation->entries, entry->name, bus_activation_entry_ref (entry)))
|
||||||
{
|
{
|
||||||
BUS_SET_OOM (error);
|
BUS_SET_OOM (error);
|
||||||
goto failed;
|
goto finally;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_dbus_hash_table_insert_string (s_dir->entries, entry->filename, bus_activation_entry_ref (entry)))
|
if (!_dbus_hash_table_insert_string (s_dir->entries, entry->filename, bus_activation_entry_ref (entry)))
|
||||||
|
|
@ -413,7 +415,7 @@ update_desktop_file_entry (BusActivation *activation,
|
||||||
/* Revert the insertion in the entries table */
|
/* Revert the insertion in the entries table */
|
||||||
_dbus_hash_table_remove_string (activation->entries, entry->name);
|
_dbus_hash_table_remove_string (activation->entries, entry->name);
|
||||||
BUS_SET_OOM (error);
|
BUS_SET_OOM (error);
|
||||||
goto failed;
|
goto finally;
|
||||||
}
|
}
|
||||||
|
|
||||||
_dbus_verbose ("Added \"%s\" to list of services\n", entry->name);
|
_dbus_verbose ("Added \"%s\" to list of services\n", entry->name);
|
||||||
|
|
@ -427,7 +429,7 @@ update_desktop_file_entry (BusActivation *activation,
|
||||||
{
|
{
|
||||||
_dbus_verbose ("The new service name \"%s\" of service file \"%s\" already in cache, ignoring\n",
|
_dbus_verbose ("The new service name \"%s\" of service file \"%s\" already in cache, ignoring\n",
|
||||||
name, _dbus_string_get_const_data (&file_path));
|
name, _dbus_string_get_const_data (&file_path));
|
||||||
goto failed;
|
goto finally;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbus_free (entry->name);
|
dbus_free (entry->name);
|
||||||
|
|
@ -458,13 +460,10 @@ update_desktop_file_entry (BusActivation *activation,
|
||||||
}
|
}
|
||||||
|
|
||||||
entry->mtime = stat_buf.mtime;
|
entry->mtime = stat_buf.mtime;
|
||||||
|
retval = TRUE;
|
||||||
|
|
||||||
_dbus_string_free (&file_path);
|
finally:
|
||||||
bus_activation_entry_unref (entry);
|
/* if these have been transferred into entry, the variables will be NULL */
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
failed:
|
|
||||||
dbus_free (name);
|
dbus_free (name);
|
||||||
dbus_free (exec);
|
dbus_free (exec);
|
||||||
dbus_free (user);
|
dbus_free (user);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue