~helene-verhaeghe27/cairo-dock-core/bugfix

« back to all changes in this revision

Viewing changes to src/cairo-dock.c

  • Committer: Fabrice Rey
  • Date: 2011-07-06 00:00:24 UTC
  • Revision ID: fabounet03@gmail.com-20110706000024-rukixs6w52bmu1pv
handle crash nicely

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
gboolean g_bLocked;
119
119
 
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;
127
 
 
128
 
 
129
 
/*
130
 
-o -w 2 -T -m -x clock
131
 
 
132
 
main:
133
 
remove "-w n", '-q n', -x, -m
134
 
start
135
 
wait 5s
136
 
 
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 ""
141
 
*/
 
127
static gint s_iNbCrashes = 0;
 
128
 
 
129
 
142
130
static gboolean _cairo_dock_successful_launch (gpointer data)
143
131
{
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;
148
134
        
149
135
        // new year greetings.
180
166
}
181
167
static void _cairo_dock_intercept_signal (int signal)
182
168
{
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");
 
172
        
 
173
        // if a module is responsible, expose it to public shame.
186
174
        if (g_pCurrentModule != NULL)
187
175
        {
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);
190
179
        }
191
180
        else
192
181
        {
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");
194
183
        }
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);
 
184
        
 
185
        // if the crash occurs on startup, take additionnal measures; else just respawn quietly.
 
186
        if (! s_bSucessfulLaunch)  // a crash on startup,
 
187
        {
 
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.
 
194
        
 
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");
198
199
}
199
200
static void _cairo_dock_set_signal_interception (void)
263
264
 
264
265
int main (int argc, char** argv)
265
266
{
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
        int i;
270
271
        for (i = 1; i < argc; i ++)
271
272
        {
272
273
                //g_print ("'%s'\n", argv[i]);
273
 
                if (strcmp (argv[i], "-m") == 0)
274
 
                        iNbMaintenance ++;
275
274
                if (strcmp (argv[i], "-q") == 0)  // this option is only set by the dock itself, at the end of the command line.
276
275
                {
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.
279
278
                        argv[i] = NULL;
280
279
                        break;
289
288
                }
290
289
                else  // keep this option in the command line.
291
290
                {
292
 
                        g_string_append_printf (sCommandString, " %s", argv[i]);
 
291
                        g_string_append_printf (s_pLaunchCommand, " %s", argv[i]);
293
292
                }
294
293
        }
295
 
        if (iNbMaintenance > 1)
 
294
        if (s_iNbCrashes > 3)
296
295
        {
297
296
                g_print ("Sorry, Cairo-Dock has encoutered some problems, and will quit.\n");
298
297
                return 1;
299
298
        }
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);
304
300
        
305
301
        gtk_init (&argc, &argv);
306
302
        gtk_gl_init (&argc, &argv);
674
670
                g_main_loop_unref (pBlockingLoop);
675
671
        }
676
672
        
677
 
        if (cExcludeModule != NULL)
678
 
        {
679
 
                //g_print ("on enleve %s de '%s'\n", cExcludeModule, s_cLaunchCommand);
680
 
                gchar *str = g_strstr_len (s_cLaunchCommand, -1, " -x ");
681
 
                if (str)
682
 
                {
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);
685
 
                }
686
 
                else
687
 
                {
688
 
                        g_free (cExcludeModule);
689
 
                        cExcludeModule = NULL;
690
 
                }
691
 
        }
692
 
        
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.
757
737
        }
758
738
        else if (cExcludeModule != NULL && ! bMaintenance)
759
739
        {
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);
 
740
                gchar *cMessage;
 
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);
 
743
                else
 
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);
761
745
                
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));
770
754
        
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"
 
766
        "- \n"
 
767
        "- \n"
 
768
        "- \n"
 
769
        "- \n"
782
770
        "\n");
783
771
        
784
772
        gtk_main ();
792
780
        
793
781
        rsvg_term ();
794
782
        xmlCleanupParser ();
 
783
        g_string_free (s_pLaunchCommand, TRUE);
795
784
        
796
785
        cd_message ("Bye bye !");
797
786
        g_print ("\033[0m\n");