Skip to content

Commit

Permalink
pk-client: Handle few error cases to avoid crash
Browse files Browse the repository at this point in the history
  • Loading branch information
sidt4 committed Sep 25, 2023
1 parent adb2629 commit 9a99183
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
24 changes: 15 additions & 9 deletions client/pk-console.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define PK_EXIT_CODE_NOTHING_USEFUL 5
#define PK_EXIT_CODE_CANNOT_SETUP 6
#define PK_EXIT_CODE_TRANSACTION_FAILED 7
#define PK_EXIT_CODE_INTERNAL_ERROR 8

#define PK_CONSOLE_ERROR 1

Expand Down Expand Up @@ -664,15 +665,20 @@ pk_console_finished_cb (GObject *object, GAsyncResult *res, gpointer data)
if (results == NULL) {
/* TRANSLATORS: we failed to get any results, which is pretty
* fatal in my book */
g_print ("%s: %s\n", _("Fatal error"), error->message);
switch (error->code - 0xff) {
case PK_ERROR_ENUM_ALL_PACKAGES_ALREADY_INSTALLED:
case PK_ERROR_ENUM_REPO_NOT_AVAILABLE:
ctx->retval = PK_EXIT_CODE_NOTHING_USEFUL;
break;
default:
ctx->retval = PK_EXIT_CODE_TRANSACTION_FAILED;
break;
if (error != NULL) {
g_print ("%s: %s\n", _("Fatal error"), error->message);
switch (error->code - 0xff) {
case PK_ERROR_ENUM_ALL_PACKAGES_ALREADY_INSTALLED:
case PK_ERROR_ENUM_REPO_NOT_AVAILABLE:
ctx->retval = PK_EXIT_CODE_NOTHING_USEFUL;
break;
default:
ctx->retval = PK_EXIT_CODE_TRANSACTION_FAILED;
break;
}
} else {
g_print ("%s: %s\n", _("Fatal error"), _("Internal error"));
ctx->retval = PK_EXIT_CODE_INTERNAL_ERROR;
}
goto out;
}
Expand Down
14 changes: 11 additions & 3 deletions lib/packagekit-glib2/pk-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ pk_client_state_finish (PkClientState *state, const GError *error)
g_object_ref (state->results),
g_object_unref);
} else {
g_autoptr(GError) internal_error = NULL;
if (error == NULL) {
internal_error = g_error_new_literal (PK_CLIENT_ERROR, PK_CLIENT_ERROR_FAILED,
"PackageKit internal error");
error = internal_error;
}

g_simple_async_result_set_from_error (state->res, error);
}

Expand Down Expand Up @@ -1596,13 +1603,14 @@ pk_client_signal_cb (GDBusProxy *proxy,
return;
}
if (g_strcmp0 (signal_name, "Destroy") == 0) {
g_autoptr(GError) local_error = NULL;
if (state->waiting_for_finished) {
g_autoptr(GError) local_error = NULL;

if (state->waiting_for_finished)
local_error = g_error_new_literal (PK_CLIENT_ERROR, PK_CLIENT_ERROR_FAILED,
"PackageKit transaction disappeared");

pk_client_state_finish (state, local_error);
pk_client_state_finish (state, local_error);
}
return;
}
}
Expand Down

0 comments on commit 9a99183

Please sign in to comment.