Bug Summary

File:tools/cafe-session-save.c
Warning:line 256, column 7
This statement is never executed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name cafe-session-save.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/rootdir/tools -fcoverage-compilation-dir=/rootdir/tools -resource-dir /usr/lib/llvm-19/lib/clang/19 -D HAVE_CONFIG_H -I . -I .. -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -D LOCALE_DIR="/usr/share/locale" -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2025-01-23-170107-18295-1 -x c cafe-session-save.c
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 * save-session.c - Small program to talk to session manager.
3
4 Copyright (C) 1998 Tom Tromey
5 Copyright (C) 2008 Red Hat, Inc.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 02110-1301, USA.
21*/
22
23#include <config.h>
24
25#include <unistd.h>
26#include <stdlib.h>
27#include <stdio.h>
28#include <string.h>
29
30#include <glib/gi18n.h>
31#include <ctk/ctk.h>
32
33#define CSM_SERVICE_DBUS"org.gnome.SessionManager" "org.gnome.SessionManager"
34#define CSM_PATH_DBUS"/org/gnome/SessionManager" "/org/gnome/SessionManager"
35#define CSM_INTERFACE_DBUS"org.gnome.SessionManager" "org.gnome.SessionManager"
36
37#define CSM_SERVICE_DBUS_OLD"org.cafe.SessionManager" "org.cafe.SessionManager"
38#define CSM_PATH_DBUS_OLD"/org/cafe/SessionManager" "/org/cafe/SessionManager"
39#define CSM_INTERFACE_DBUS_OLD"org.cafe.SessionManager" "org.cafe.SessionManager"
40
41enum {
42 CSM_LOGOUT_MODE_NORMAL = 0,
43 CSM_LOGOUT_MODE_NO_CONFIRMATION,
44 CSM_LOGOUT_MODE_FORCE
45};
46
47/* True if killing. This is deprecated, but we keep it for compatibility
48 * reasons. */
49static gboolean kill_session = FALSE(0);
50
51/* The real options that should be used now. They are not ambiguous. */
52static gboolean logout = FALSE(0);
53static gboolean force_logout = FALSE(0);
54static gboolean logout_dialog = FALSE(0);
55static gboolean shutdown_dialog = FALSE(0);
56
57/* True if we should use dialog boxes */
58static gboolean show_error_dialogs = FALSE(0);
59
60/* True if we should do the requested action without confirmation */
61static gboolean no_interaction = FALSE(0);
62
63static char* session_name = NULL((void*)0);
64
65static GOptionEntry options[] = {
66 {"logout", '\0', 0, G_OPTION_ARG_NONE, &logout, N_("Log out")("Log out"), NULL((void*)0)},
67 {"force-logout", '\0', 0, G_OPTION_ARG_NONE, &force_logout, N_("Log out, ignoring any existing inhibitors")("Log out, ignoring any existing inhibitors"), NULL((void*)0)},
68 {"logout-dialog", '\0', 0, G_OPTION_ARG_NONE, &logout_dialog, N_("Show logout dialog")("Show logout dialog"), NULL((void*)0)},
69 {"shutdown-dialog", '\0', 0, G_OPTION_ARG_NONE, &shutdown_dialog, N_("Show shutdown dialog")("Show shutdown dialog"), NULL((void*)0)},
70 {"gui", '\0', 0, G_OPTION_ARG_NONE, &show_error_dialogs, N_("Use dialog boxes for errors")("Use dialog boxes for errors"), NULL((void*)0)},
71 /* deprecated options */
72 {"session-name", 's', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &session_name, N_("Set the current session name")("Set the current session name"), N_("NAME")("NAME")},
73 {"kill", '\0', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &kill_session, N_("Kill session")("Kill session"), NULL((void*)0)},
74 {"silent", '\0', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &no_interaction, N_("Do not require confirmation")("Do not require confirmation"), NULL((void*)0)},
75 {NULL((void*)0)}
76};
77
78static void display_error(const char* message)
79{
80 if (show_error_dialogs && !no_interaction)
81 {
82 CtkWidget* dialog = ctk_message_dialog_new(NULL((void*)0), 0, CTK_MESSAGE_ERROR, CTK_BUTTONS_CLOSE, "%s", message);
83
84 ctk_window_set_default_icon_name ("dialog-error");
85
86 ctk_dialog_run(CTK_DIALOG(dialog)((((CtkDialog*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((dialog)), ((ctk_dialog_get_type ()))))))
);
87 ctk_widget_destroy(dialog);
88 }
89 else
90 {
91 g_printerr("%s\n", message);
92 }
93}
94
95static GDBusProxy* get_sm_proxy(void)
96{
97 GError *error = NULL((void*)0);
98 GDBusProxy *sm_proxy = NULL((void*)0);
99
100 sm_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
101 G_DBUS_PROXY_FLAGS_NONE,
102 NULL((void*)0),
103 CSM_SERVICE_DBUS"org.gnome.SessionManager",
104 CSM_PATH_DBUS"/org/gnome/SessionManager",
105 CSM_INTERFACE_DBUS"org.gnome.SessionManager",
106 NULL((void*)0),
107 &error);
108 if (sm_proxy == NULL((void*)0))
109 {
110 g_warning ("Couldn't create DBus proxy: %s", error->message);
111 g_error_free (error);
112
113 /* Try the old name - for the case when we've just upgraded from 1.10
114 * so the old m-s-m is currently running */
115 sm_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
116 G_DBUS_PROXY_FLAGS_NONE,
117 NULL((void*)0),
118 CSM_SERVICE_DBUS_OLD"org.cafe.SessionManager",
119 CSM_PATH_DBUS_OLD"/org/cafe/SessionManager",
120 CSM_INTERFACE_DBUS_OLD"org.cafe.SessionManager",
121 NULL((void*)0),
122 NULL((void*)0));
123 if (sm_proxy == NULL((void*)0))
124 {
125 /* Okay, it wasn't the upgrade case, so now we can give up. */
126 display_error (_("Could not connect to the session manager")gettext ("Could not connect to the session manager"));
127 return NULL((void*)0);
128 }
129 }
130
131 return sm_proxy;
132}
133
134static void do_logout(unsigned int mode)
135{
136 GDBusProxy* sm_proxy;
137 GError* error;
138 GVariant *ret;
139
140 sm_proxy = get_sm_proxy ();
141
142 if (sm_proxy == NULL((void*)0))
143 {
144 return;
145 }
146
147 error = NULL((void*)0);
148 ret = g_dbus_proxy_call_sync (sm_proxy, "Logout",
149 g_variant_new ("(u)", mode),
150 G_DBUS_CALL_FLAGS_NONE,
151 -1,
152 NULL((void*)0),
153 &error);
154
155 if (ret == NULL((void*)0))
156 {
157 g_warning ("Failed to call logout: %s", error->message);
158 g_error_free (error);
159 } else {
160 g_variant_unref (ret);
161 }
162
163 if (sm_proxy != NULL((void*)0))
164 {
165 g_object_unref (sm_proxy);
166 }
167}
168
169static void do_shutdown_dialog(void)
170{
171 GDBusProxy* sm_proxy;
172 GError* error;
173 GVariant *ret;
174
175 sm_proxy = get_sm_proxy ();
176
177 if (sm_proxy == NULL((void*)0))
178 {
179 return;
180 }
181
182 error = NULL((void*)0);
183 ret = g_dbus_proxy_call_sync (sm_proxy, "Shutdown",
184 g_variant_new ("()"),
185 G_DBUS_CALL_FLAGS_NONE,
186 -1,
187 NULL((void*)0),
188 &error);
189 if (ret == NULL((void*)0))
190 {
191 g_warning ("Failed to call shutdown: %s", error->message);
192 g_error_free (error);
193 } else {
194 g_variant_unref (ret);
195 }
196
197 if (sm_proxy != NULL((void*)0))
198 {
199 g_object_unref (sm_proxy);
200 }
201}
202
203int main(int argc, char* argv[])
204{
205 GError* error;
206 int conflicting_options;
207
208 /* Initialize the i18n stuff */
209 bindtextdomain(GETTEXT_PACKAGE"cafe-session-manager", LOCALE_DIR"/usr/share/locale");
210 bind_textdomain_codeset(GETTEXT_PACKAGE"cafe-session-manager", "UTF-8");
211 textdomain(GETTEXT_PACKAGE"cafe-session-manager");
212
213 error = NULL((void*)0);
214
215 if (!ctk_init_with_args(&argc, &argv, NULL((void*)0), options, NULL((void*)0), &error))
216 {
217 g_warning("Unable to start: %s", error->message);
218 g_error_free(error);
219 exit(1);
220 }
221
222 conflicting_options = 0;
223
224 if (kill_session)
225 {
226 conflicting_options++;
227 }
228
229 if (logout)
230 {
231 conflicting_options++;
232 }
233
234 if (force_logout)
235 {
236 conflicting_options++;
237 }
238
239 if (logout_dialog)
240 {
241 conflicting_options++;
242 }
243
244 if (shutdown_dialog)
245 {
246 conflicting_options++;
247 }
248
249 if (conflicting_options > 1)
250 {
251 display_error(_("Program called with conflicting options")gettext ("Program called with conflicting options"));
252 }
253
254 if (kill_session)
255 {
256 if (no_interaction)
This statement is never executed
257 {
258 force_logout = TRUE(!(0));
259 }
260 else
261 {
262 logout_dialog = TRUE(!(0));
263 }
264 }
265
266 if (logout)
267 {
268 do_logout(CSM_LOGOUT_MODE_NO_CONFIRMATION);
269 }
270 else if (force_logout)
271 {
272 do_logout(CSM_LOGOUT_MODE_FORCE);
273 }
274 else if (logout_dialog)
275 {
276 do_logout(CSM_LOGOUT_MODE_NORMAL);
277 }
278 else if (shutdown_dialog)
279 {
280 do_shutdown_dialog();
281 }
282
283 return 0;
284}