diff options
author | Eric Koegel <eric.koegel@gmail.com> | 2015-05-10 09:45:57 +0300 |
---|---|---|
committer | Eric Koegel <eric.koegel@gmail.com> | 2015-05-10 09:45:57 +0300 |
commit | eb16197fb56273331e189f8b30d7e9eed3be998e (patch) | |
tree | a279dae115a8024c8507dec2fec269742eeed347 | |
parent | e71143d0527f4568335b0659896695e098c9b686 (diff) | |
download | ConsoleKit2-eb16197fb56273331e189f8b30d7e9eed3be998e.tar.gz |
Return NULL when there's no sessions or seats
When calling get_sessions/seats return NULL + an error stating
that there's nothing to return. This makes the GDBus branch work
like the pre-GDBus code.
-rw-r--r-- | src/ck-manager.c | 22 | ||||
-rw-r--r-- | src/ck-manager.h | 2 | ||||
-rw-r--r-- | src/ck-seat.c | 10 | ||||
-rw-r--r-- | src/ck-seat.h | 1 |
4 files changed, 22 insertions, 13 deletions
diff --git a/src/ck-manager.c b/src/ck-manager.c index db2035c..dfc5b57 100644 --- a/src/ck-manager.c +++ b/src/ck-manager.c @@ -283,7 +283,9 @@ static const GDBusErrorEntry ck_manager_error_entries[] = { CK_MANAGER_ERROR_NOT_SUPPORTED, DBUS_MANAGER_INTERFACE ".Error.NotSupported" }, { CK_MANAGER_ERROR_INHIBITED, DBUS_MANAGER_INTERFACE ".Error.Inhibited" }, { CK_MANAGER_ERROR_INVALID_INPUT, DBUS_MANAGER_INTERFACE ".Error.InvalidInput" }, - { CK_MANAGER_ERROR_OOM, DBUS_MANAGER_INTERFACE ".Error.OutOfMemory" } + { CK_MANAGER_ERROR_OOM, DBUS_MANAGER_INTERFACE ".Error.OutOfMemory" }, + { CK_MANAGER_ERROR_NO_SEATS, DBUS_MANAGER_INTERFACE ".Error.NoSeats" }, + { CK_MANAGER_ERROR_NO_SESSIONS, DBUS_MANAGER_INTERFACE ".Error.NoSessions" }, }; GQuark @@ -318,6 +320,8 @@ ck_manager_error_get_type (void) ENUM_ENTRY (CK_MANAGER_ERROR_INHIBITED, "Inhibited"), ENUM_ENTRY (CK_MANAGER_ERROR_INVALID_INPUT, "InvalidInput"), ENUM_ENTRY (CK_MANAGER_ERROR_OOM, "OutOfMemory"), + ENUM_ENTRY (CK_MANAGER_ERROR_NO_SEATS, "NoSeats"), + ENUM_ENTRY (CK_MANAGER_ERROR_NO_SESSIONS, "NoSessions"), { 0, 0, 0 } }; g_assert (CK_MANAGER_NUM_ERRORS == G_N_ELEMENTS (values) - 1); @@ -3184,10 +3188,10 @@ dbus_get_sessions_for_unix_user (ConsoleKitManager *ckmanager, sessions = (const gchar**)g_hash_table_get_keys_as_array (manager->priv->sessions, NULL); - /* gdbus/gvariant requires that we return something */ - if (sessions[0] == NULL) { - sessions[0] = ""; - sessions[1] = NULL; + /* gdbus/gvariant requires that we throw an error to return NULL */ + if (sessions == NULL) { + throw_error (context, CK_MANAGER_ERROR_NO_SESSIONS, _("User has no sessions")); + return TRUE; } console_kit_manager_complete_get_sessions_for_unix_user (ckmanager, context, sessions); @@ -3220,10 +3224,10 @@ dbus_get_seats (ConsoleKitManager *ckmanager, seats = (const gchar**)g_hash_table_get_keys_as_array (manager->priv->seats, NULL); - /* gdbus/gvariant requires that we return something */ - if (seats[0] == NULL) { - seats[0] = ""; - seats[1] = NULL; + /* gdbus/gvariant requires that we throw an error to return NULL */ + if (seats == NULL) { + throw_error (context, CK_MANAGER_ERROR_NO_SEATS, _("User has no seats")); + return TRUE; } console_kit_manager_complete_get_seats (ckmanager, context, seats); diff --git a/src/ck-manager.h b/src/ck-manager.h index cdc8b20..edf8cd7 100644 --- a/src/ck-manager.h +++ b/src/ck-manager.h @@ -60,6 +60,8 @@ typedef enum CK_MANAGER_ERROR_INHIBITED, CK_MANAGER_ERROR_INVALID_INPUT, CK_MANAGER_ERROR_OOM, + CK_MANAGER_ERROR_NO_SEATS, + CK_MANAGER_ERROR_NO_SESSIONS, CK_MANAGER_NUM_ERRORS } CkManagerError; diff --git a/src/ck-seat.c b/src/ck-seat.c index df1494a..6251cd8 100644 --- a/src/ck-seat.c +++ b/src/ck-seat.c @@ -91,6 +91,7 @@ static const GDBusErrorEntry ck_seat_error_entries[] = { CK_SEAT_ERROR_NOT_SUPPORTED, CK_SEAT_DBUS_NAME ".Error.NotSupported" }, { CK_SEAT_ERROR_NO_ACTIVE_SESSION, CK_SEAT_DBUS_NAME ".Error.NoActiveSession" }, { CK_SEAT_ERROR_ALREADY_ACTIVE, CK_SEAT_DBUS_NAME ".Error.AlreadyActive" }, + { CK_SEAT_ERROR_NO_SESSIONS, CK_SEAT_DBUS_NAME ".Error.NoSessions" }, }; GQuark @@ -123,6 +124,7 @@ ck_seat_error_get_type (void) ENUM_ENTRY (CK_SEAT_ERROR_NOT_SUPPORTED, "NotSupported"), ENUM_ENTRY (CK_SEAT_ERROR_NO_ACTIVE_SESSION, "NoActiveSession"), ENUM_ENTRY (CK_SEAT_ERROR_ALREADY_ACTIVE, "AlreadyActive"), + ENUM_ENTRY (CK_SEAT_ERROR_NO_SESSIONS, "NoSessions"), { 0, 0, 0 } }; g_assert (CK_SEAT_NUM_ERRORS == G_N_ELEMENTS (values) - 1); @@ -959,10 +961,10 @@ dbus_get_sessions (ConsoleKitSeat *ckseat, sessions = (const gchar**)g_hash_table_get_keys_as_array (seat->priv->sessions, NULL); - /* gdbus/gvariant requires that we return something */ - if (sessions[0] == NULL) { - sessions[0] = ""; - sessions[1] = NULL; + /* gdbus/gvariant requires that we throw an error to return NULL */ + if (sessions == NULL) { + throw_error (context, CK_SEAT_ERROR_NO_SESSIONS, _("Seat has no sessions")); + return TRUE; } console_kit_seat_complete_get_sessions (ckseat, context, sessions); diff --git a/src/ck-seat.h b/src/ck-seat.h index b3f0827..aade9c9 100644 --- a/src/ck-seat.h +++ b/src/ck-seat.h @@ -66,6 +66,7 @@ typedef enum CK_SEAT_ERROR_NOT_SUPPORTED, CK_SEAT_ERROR_NO_ACTIVE_SESSION, CK_SEAT_ERROR_ALREADY_ACTIVE, + CK_SEAT_ERROR_NO_SESSIONS, CK_SEAT_NUM_ERRORS } CkSeatError; |