Permalink
Browse files

consistent exit status, and make sure error messages are printed on s…

…tderr
  • Loading branch information...
1 parent f6d396f commit e5b009f9c0f3fd3565ecbfb3cfe7df1cbf3eb32a @poliva committed May 11, 2012
Showing with 22 additions and 18 deletions.
  1. +3 −3 configfile.c
  2. +9 −6 dbus-session.c
  3. +6 −6 functions.c
  4. +4 −3 lightum.c
View
@@ -131,14 +131,14 @@ conf_data config_parse() {
file = default_config_file();
if (!file_exists(file)) {
if (!create_config_file(file)) {
- printf ("failed to create default config file: %s\n", file);
- exit(1);
+ fprintf (stderr,"Failed to create default config file: %s\n", file);
+ exit (1);
}
}
fd = fopen (file, "r");
if (fd == NULL) {
- printf ("Could not open configuration file: %s\n", file);
+ fprintf (stderr,"Could not open configuration file: %s\n", file);
exit (1);
}
View
@@ -81,9 +81,10 @@ DBusGProxy* get_dbus_proxy_session(DBusGConnection *connection, DBusGProxy *prox
ssid,
CK_SESSION_INTERFACE);
- if (proxy == NULL)
- exit(1);
-
+ if (proxy == NULL) {
+ g_warning ("Could not get dbus session proxy");
+ exit (1);
+ }
return proxy;
@@ -98,8 +99,10 @@ DBusGProxy* get_dbus_proxy_manager(DBusGConnection *connection)
CK_NAME,
CK_MANAGER_PATH,
CK_MANAGER_INTERFACE);
- if (proxy == NULL)
- exit(1);
+ if (proxy == NULL) {
+ g_warning ("Could not get dbus manager proxy");
+ exit (1);
+ }
return proxy;
@@ -131,7 +134,7 @@ DBusGConnection* get_dbus_connection()
if (connection == NULL) {
g_message ("Failed to connect to the D-Bus daemon: %s", error->message);
g_error_free (error);
- exit(1);
+ exit (1);
}
return connection;
View
@@ -342,7 +342,7 @@ int create_pid_file() {
fd = open(pidfile, O_RDONLY);
if (fd < 0) {
- printf ("Could not open pid file: %s\n", pidfile);
+ fprintf (stderr,"Could not open pid file: %s\n", pidfile);
return FALSE;
}
cnt=read(fd, buf, sizeof(buf)-1);
@@ -358,7 +358,7 @@ int create_pid_file() {
if (file_exists(procpid)) {
fd = open(procpid, O_RDONLY);
if (fd < 0) {
- printf ("Could not open file: %s\n", procpid);
+ fprintf (stderr,"Could not open file: %s\n", procpid);
return FALSE;
}
@@ -368,7 +368,7 @@ int create_pid_file() {
close(fd);
if (strstr(buf,"lightum") != NULL) {
- printf("Refusing to start as lightum is already running\n");
+ fprintf (stderr,"Refusing to start as lightum is already running\n");
return FALSE;
} else {
if (!remove_pid_file())
@@ -379,7 +379,7 @@ int create_pid_file() {
fd = open(pidfile, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0 ) {
- printf("Could not write pid file: %s\n", pidfile);
+ fprintf(stderr,"Could not write pid file: %s\n", pidfile);
return FALSE;
}
@@ -403,12 +403,12 @@ int remove_pid_file() {
pidfile = default_pid_file();
if (!file_exists(pidfile)) {
- printf("pid file does not exist: %s\n", pidfile);
+ fprintf (stderr,"pid file does not exist: %s\n", pidfile);
return TRUE;
}
if (unlink(pidfile) != 0) {
- printf("Could not delete pid file: %s\n", pidfile);
+ fprintf (stderr,"Could not delete pid file: %s\n", pidfile);
return FALSE;
}
return TRUE;
View
@@ -211,7 +211,7 @@ int main(int argc, char *argv[]) {
tmp = dbus_set_screen_backlight_value_kde(acpi_to_dbus_backlight(backlight_restore));
if (tmp == -1) {
fprintf (stderr, "Can't manage screen backlight on this system.\nPlease disable backlight with config option 'workmode='1' or command line switch '-w 1'.\nIf you believe this is an error, open a bug report: https://github.com/poliva/lightum/issues\n");
- exit (-1);
+ exit (1);
} else {
dbus_backend=1;
}
@@ -224,7 +224,7 @@ int main(int argc, char *argv[]) {
if (conf.idleoff != 0 || conf.screenidle != 0) {
display = XOpenDisplay(NULL);
if (display == NULL) {
- printf("Failed to open display\n");
+ fprintf(stderr,"Failed to open display\n");
exit(1);
}
}
@@ -443,7 +443,8 @@ int main(int argc, char *argv[]) {
usleep(conf.polltime*1000);
}
+ // we should never reach here.
//if (conf.idleoff != 0) XCloseDisplay(display);
//dbus_g_connection_unref(connection);
- exit(0);
+ exit(1);
}

0 comments on commit e5b009f

Please sign in to comment.