118
118
gboolean g_bLocked;
120
120
static gboolean s_bSucessfulLaunch = FALSE;
121
static gchar *s_cLaunchCommand = NULL;
121
static GString *s_pLaunchCommand = NULL;
122
122
static gchar *s_cLastVersion = NULL;
123
123
static gchar *s_cDefaulBackend = NULL;
124
124
static gint s_iGuiMode = 0; // 0 = simple mode, 1 = advanced mode
125
125
static gint s_iLastYear = 0;
126
126
static void (*s_activate_composite) (gboolean) = NULL;
130
-o -w 2 -T -m -x clock
133
remove "-w n", '-q n', -x, -m
137
1st crash before 5s (q = 0) -> restart with -w 2 -q 1
138
q-th crash before 5s (q > 0) -> if module && q<3: restart with -x -q n+1, else: restart with -m -q n+1
139
3rd crash before 5s -> restart with -x or -m
140
crash after 5s -> restart -x toto or ""
127
static gint s_iNbCrashes = 0;
142
130
static gboolean _cairo_dock_successful_launch (gpointer data)
144
132
// successful launch, remove the maintenance mode from the command line.
145
if (g_str_has_suffix (s_cLaunchCommand, " -m"))
146
s_cLaunchCommand[strlen (s_cLaunchCommand)-3] = '\0'; // on enleve le mode maintenance.
147
133
s_bSucessfulLaunch = TRUE;
149
135
// new year greetings.
181
167
static void _cairo_dock_intercept_signal (int signal)
183
cd_warning ("Cairo-Dock has crashed (sig %d).\nIt will be restarted now (%s).\nFeel free to report this bug on glx-dock.org to help improving the dock !", signal, s_cLaunchCommand);
169
cd_warning ("Cairo-Dock has crashed (sig %d).\nIt will be restarted now.\nFeel free to report this bug on glx-dock.org to help improving the dock!", signal);
184
170
g_print ("info on the system :\n");
185
171
int r = system ("uname -a");
173
// if a module is responsible, expose it to public shame.
186
174
if (g_pCurrentModule != NULL)
188
176
g_print ("The applet '%s' may be the culprit", g_pCurrentModule->pModule->pVisitCard->cModuleName);
189
s_cLaunchCommand = g_strdup_printf ("%s -x \"%s\"", s_cLaunchCommand, g_pCurrentModule->pModule->pVisitCard->cModuleName);
177
if (! s_bSucessfulLaunch) // else, be quiet.
178
g_string_append_printf (s_pLaunchCommand, " -x \"%s\"", g_pCurrentModule->pModule->pVisitCard->cModuleName);
193
182
g_print ("Couldn't guess if it was an applet's fault or not. It may have crashed inside the core or inside a thread\n");
195
execl ("/bin/sh", "/bin/sh", "-c", s_cLaunchCommand, (char *)NULL); // on ne revient pas de cette fonction.
196
//execlp ("cairo-dock", "cairo-dock", s_cLaunchCommand, (char *)0);
185
// if the crash occurs on startup, take additionnal measures; else just respawn quietly.
186
if (! s_bSucessfulLaunch) // a crash on startup,
188
if (s_iNbCrashes < 2) // the first 2 crashes, restart with a delay (in case we were launched too early on startup).
189
g_string_append (s_pLaunchCommand, " -w 2"); // 2s delay.
190
else if (g_pCurrentModule == NULL) // several crashes, and no culprit => start in maintenance mode.
191
g_string_append (s_pLaunchCommand, " -m");
192
g_string_append_printf (s_pLaunchCommand, " -q %d", s_iNbCrashes + 1); // increment the first-crash counter.
193
} // else a random crash, respawn quietly.
195
g_print ("restarting with '%s'...\n", s_pLaunchCommand->str);
196
execl ("/bin/sh", "/bin/sh", "-c", s_pLaunchCommand->str, (char *)NULL); // on ne revient pas de cette fonction.
197
//execlp ("cairo-dock", "cairo-dock", s_pLaunchCommand->str, (char *)0);
197
198
cd_warning ("Sorry, couldn't restart the dock");
199
200
static void _cairo_dock_set_signal_interception (void)
264
265
int main (int argc, char** argv)
266
//\___________________ show the config panel if something has gone wrong in a previous life, or just quit to prevent infinite crash loop.
267
int i, iNbCrashes = 0, iNbMaintenance=0;
268
GString *sCommandString = g_string_new (argv[0]);
267
//\___________________ build the command line used to respawn, and check if we have been launched from another life.
268
s_pLaunchCommand = g_string_new (argv[0]);
269
269
gchar *cDisableApplet = NULL;
270
271
for (i = 1; i < argc; i ++)
272
273
//g_print ("'%s'\n", argv[i]);
273
if (strcmp (argv[i], "-m") == 0)
275
274
if (strcmp (argv[i], "-q") == 0) // this option is only set by the dock itself, at the end of the command line.
277
iNbCrashes = atoi (argv[i+1]);
276
s_iNbCrashes = atoi (argv[i+1]);
278
277
argc = i; // remove this option, as it doesn't belong to the options table.
290
289
else // keep this option in the command line.
292
g_string_append_printf (sCommandString, " %s", argv[i]);
291
g_string_append_printf (s_pLaunchCommand, " %s", argv[i]);
295
if (iNbMaintenance > 1)
294
if (s_iNbCrashes > 3)
297
296
g_print ("Sorry, Cairo-Dock has encoutered some problems, and will quit.\n");
300
///g_string_append (sCommandString, " -m"); // if it crashes before 5s, we'll restart it quietly 1 time.
301
g_print (">>> restart cmd line: %s\n", sCommandString->str);
302
s_cLaunchCommand = sCommandString->str;
303
g_string_free (sCommandString, FALSE);
299
g_print (">>> restart cmd line: %s\n", s_pLaunchCommand->str);
305
301
gtk_init (&argc, &argv);
306
302
gtk_gl_init (&argc, &argv);
674
670
g_main_loop_unref (pBlockingLoop);
677
if (cExcludeModule != NULL)
679
//g_print ("on enleve %s de '%s'\n", cExcludeModule, s_cLaunchCommand);
680
gchar *str = g_strstr_len (s_cLaunchCommand, -1, " -x ");
683
*str = '\0'; // enleve le module de la ligne de commande, ainsi que le le -m courant.
684
g_print ("s_cLaunchCommand <- '%s'\n", s_cLaunchCommand);
688
g_free (cExcludeModule);
689
cExcludeModule = NULL;
693
673
//\___________________ load the current theme.
694
674
cd_message ("loading theme ...");
695
675
if (! g_file_test (g_cConfFile, G_FILE_TEST_EXISTS)) // no theme yet, copy the default theme first.
758
738
else if (cExcludeModule != NULL && ! bMaintenance)
760
gchar *cMessage = g_strdup_printf (_("The module '%s' may have encountered a problem.\nIt has been restored successfully, but if it happens again, please report it at http://glx-dock.org"), cExcludeModule);
741
if (s_iNbCrashes < 2)
742
cMessage = g_strdup_printf (_("The module '%s' may have encountered a problem.\nIt has been restored successfully, but if it happens again, please report it at http://glx-dock.org"), cExcludeModule);
744
cMessage = g_strdup_printf ("The module '%s' has been deactivated because it may have caused some problems.\nYou can reactivate it, if it happens again thanks to report it at http://glx-dock.org", cExcludeModule);
762
746
CairoDockModule *pModule = cairo_dock_find_module_from_name (cExcludeModule);
763
747
Icon *icon = cairo_dock_get_dialogless_icon ();
769
753
g_timeout_add_seconds (5, _cairo_dock_successful_launch, GINT_TO_POINTER (bFirstLaunch));
771
755
g_print ("\n\nTODO:\n"
772
"- old systray (in dialog mode?)\n"
773
756
"- test drop (Shortcuts, between applets or applis, Panel view, etc).\n"
774
757
"- draw a preview of the dock in opengl\n"
775
758
"- test locale on third-party applets\n"
776
759
"- handle icon path in .desktop files.\n"
777
"- compil kde integration\n"
760
"- kde integration ++\n"
778
761
"- find Kwin config tool for Composite-manager\n"
779
"- test multi-stacks\n"
780
762
"- review Help hints\n"
781
763
"- handle first crash nicely\n"
764
"- configure non active applets (Help, ...) in both modes\n"
765
"- test import question in Folders\n"