summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortest-tools <test-tools>2006-10-10 13:13:26 +0000
committertest-tools <test-tools>2006-10-10 13:13:26 +0000
commitce0b5c2b490d76ea53a38a0ab3cdeef390653464 (patch)
treecc1a7dcb00958e6db7cfdc0e6a8d50ce8f0de559 /src
parent9e43d44bf66db4c2d72a19d75d977cd8f60b06de (diff)
downloadberyl-manager-ce0b5c2b490d76ea53a38a0ab3cdeef390653464.tar.gz
beryl-manager-ce0b5c2b490d76ea53a38a0ab3cdeef390653464.tar.bz2
man page update, enhanced error reporting&handling,
should probably fix #434, prevents from respawning itself.
Diffstat (limited to 'src')
-rw-r--r--src/main.c61
1 files changed, 45 insertions, 16 deletions
diff --git a/src/main.c b/src/main.c
index fb452c4..6eea8be 100644
--- a/src/main.c
+++ b/src/main.c
@@ -17,6 +17,9 @@
#define gettext_noop(String) String
#define N_(String) gettext_noop (String)
+//better error handling
+#define manager_error(String) g_critical("%s: %s", String, g_strerror(errno))
+
Atom wmAtom;
GMutex * mutx;
EggTrayIcon * mainIcon;
@@ -86,6 +89,20 @@ GtkWidget * reloadDecoratorItem;
void launchWM();
+void beryl_manager_log_handler (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer user_data)
+{
+ g_log_default_handler (log_domain, log_level, message, user_data);
+
+ if (isatty(0))
+ g_on_error_query (NULL);
+ else
+ abort();
+}
+
+
GSList * parse_xlsclients(gchar * output)
{
GSList * ret = NULL;
@@ -190,14 +207,14 @@ gboolean is_running(const gchar * command)
if (!g_spawn_command_line_sync(
g_strdup_printf("sh -c \"ps xo comm | egrep '^%s$' > /dev/null\"",command),
NULL,NULL,&ex,NULL))
- g_error(_("can't use this app, no ps or grep"));
+ manager_error(_("can't use this app, no ps or grep"));
if (WIFEXITED(ex))
{
if (WEXITSTATUS(ex)==0)
return TRUE;
}
else
- g_error(_("something went wrong with ps or grep"));
+ manager_error(_("something went wrong with ps or grep"));
return FALSE;
}
gboolean is_decor_running()
@@ -384,7 +401,7 @@ void killWM()
else
{
if (!cli)
- g_error(_("No output from xlsclients, bailing."));
+ manager_error(_("No output from xlsclients, bailing."));
xls=parse_xlsclients(cli);
g_free(cli);
g_slist_foreach(xls,(GFunc)killIfWM,d);
@@ -426,9 +443,9 @@ gpointer berylThread(gpointer d)
killWM();
if (!g_spawn_command_line_sync(beryl_command,NULL,NULL,&ex,NULL)) {
if (XGL)
- g_error(_("can't execute beryl-xgl"));
+ manager_error(_("can't execute beryl-xgl"));
else
- g_error(_("can't execute beryl"));
+ manager_error(_("can't execute beryl"));
}
if (reloadingBeryl)
{
@@ -614,14 +631,14 @@ gboolean detect_app(const gchar * app)
if (!g_spawn_command_line_sync(
g_strdup_printf("sh -c 'which %s > /dev/null'",app),
NULL,NULL,&ex,NULL))
- g_error(_("can't use this app, no which"));
+ manager_error(_("can't use this app, no which"));
if (WIFEXITED(ex))
{
if (WEXITSTATUS(ex)==0)
return TRUE;
}
else
- g_error(_("something went wrong with which"));
+ manager_error(_("something went wrong with which"));
return FALSE;
}
gboolean detect_wm(gint wm)
@@ -841,7 +858,7 @@ void detect_nvidia()
gint ex=0;
if (!g_spawn_command_line_sync("sh -c 'glxinfo | grep -i NVIDIA > /dev/null'",
NULL,NULL,&ex,NULL))
- g_error(_("can't use this app, no glxinfo or no grep"));
+ manager_error(_("can't use this app, no glxinfo or no grep"));
if (WIFEXITED(ex))
{
if (WEXITSTATUS(ex)==0)
@@ -850,7 +867,7 @@ void detect_nvidia()
NV9XXX=FALSE;
}
else
- g_error(_("something went wrong with glxinfo or grep"));
+ manager_error(_("something went wrong with glxinfo or grep"));
}
void detect_xgl()
@@ -859,7 +876,7 @@ void detect_xgl()
gint ex=0;
if (!g_spawn_command_line_sync("sh -c 'xvinfo | grep -i Xgl > /dev/null'",
NULL,NULL,&ex,NULL))
- g_error(_("can't use this app, no xvinfo or no grep"));
+ manager_error(_("can't use this app, no xvinfo or no grep"));
if (WIFEXITED(ex))
{
if (WEXITSTATUS(ex)==0)
@@ -868,7 +885,7 @@ void detect_xgl()
XGL=FALSE;
}
else
- g_error(_("something went wrong with xvinfo or grep"));
+ manager_error(_("something went wrong with xvinfo or grep"));
}
int main(int argc, char ** argv)
{
@@ -876,6 +893,14 @@ int main(int argc, char ** argv)
gint e;
Display * d;
+ //Intialise error handler
+ g_log_set_handler (G_LOG_DOMAIN,
+ G_LOG_LEVEL_WARNING |
+ G_LOG_LEVEL_ERROR |
+ G_LOG_LEVEL_CRITICAL,
+ beryl_manager_log_handler,
+ NULL);
+
//set the locale stuff
setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
@@ -885,8 +910,10 @@ int main(int argc, char ** argv)
for (fd=0;fd<argc;fd++)
if (strcmp(argv[fd],"-d")==0)
break;
- if (fd==argc)
- daemon(0,1);
+ if (fd==argc) {
+ daemon(1,1);
+ close(0);
+ }
fd = creat(g_strconcat(g_get_home_dir(),"/.beryl-manager.lock",NULL)
,00755);
@@ -901,8 +928,10 @@ int main(int argc, char ** argv)
return 1;
}
if (flock(fd,LOCK_EX | LOCK_NB)!=0)
- {
- execlp("beryl-manager","beryl-manager",NULL);
+ {
+ // Commenting out, too much respawned beryl-managers
+ //execlp("beryl-manager","beryl-manager",NULL);
+ manager_error(_("Couldn't get lock on lockfile"));
}
dprintf(fd,"%d\n",getpid());
if (!XInitThreads())
@@ -966,7 +995,7 @@ int main(int argc, char ** argv)
}
}
if (DM==-1)
- g_error("No Display Manager Found!");
+ manager_error("No Display Manager Found!");
save_settings();
if (!is_wm_running(WM))