From 1eb1626f08952de0fc1e47065c95c63f27b9539b Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 1 Mar 2012 22:06:18 +0000 Subject: [PATCH] Improve logging Use %m for strerror. Switch to use 0 for fail return code. --- WHATS_NEW_DM | 1 + daemons/dmeventd/dmeventd.c | 43 ++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index fb143630e..e594e3812 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.73 - ==================================== + Improve logging for fifo startup in dmeventd. Add few pointer validation in dmsetup. Support dm_task_get_driver_version() query without version string. Log failure of pthread_join when cleaning unused threads in dmeventd. diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c index bfd5d36e7..b9f1363ed 100644 --- a/daemons/dmeventd/dmeventd.c +++ b/daemons/dmeventd/dmeventd.c @@ -1245,67 +1245,66 @@ static void _init_fifos(struct dm_event_fifos *fifos) /* Open fifos used for client communication. */ static int _open_fifos(struct dm_event_fifos *fifos) { - int orig_errno; struct stat st; /* Create client fifo. */ (void) dm_prepare_selinux_context(fifos->client_path, S_IFIFO); if ((mkfifo(fifos->client_path, 0600) == -1) && errno != EEXIST) { - syslog(LOG_ERR, "%s: Failed to create client fifo.\n", __func__); - orig_errno = errno; + syslog(LOG_ERR, "%s: Failed to create client fifo %s: %m.\n", + __func__, fifos->client_path); (void) dm_prepare_selinux_context(NULL, 0); - stack; - return -orig_errno; + return 0; } /* Create server fifo. */ (void) dm_prepare_selinux_context(fifos->server_path, S_IFIFO); if ((mkfifo(fifos->server_path, 0600) == -1) && errno != EEXIST) { - syslog(LOG_ERR, "%s: Failed to create server fifo.\n", __func__); - orig_errno = errno; + syslog(LOG_ERR, "%s: Failed to create server fifo %s: %m.\n", + __func__, fifos->server_path); (void) dm_prepare_selinux_context(NULL, 0); - stack; - return -orig_errno; + return 0; } (void) dm_prepare_selinux_context(NULL, 0); /* Warn about wrong permissions if applicable */ if ((!stat(fifos->client_path, &st)) && (st.st_mode & 0777) != 0600) - syslog(LOG_WARNING, "Fixing wrong permissions on %s", + syslog(LOG_WARNING, "Fixing wrong permissions on %s: %m.\n", fifos->client_path); if ((!stat(fifos->server_path, &st)) && (st.st_mode & 0777) != 0600) - syslog(LOG_WARNING, "Fixing wrong permissions on %s", + syslog(LOG_WARNING, "Fixing wrong permissions on %s: %m.\n", fifos->server_path); /* If they were already there, make sure permissions are ok. */ if (chmod(fifos->client_path, 0600)) { - syslog(LOG_ERR, "Unable to set correct file permissions on %s", + syslog(LOG_ERR, "Unable to set correct file permissions on %s: %m.\n", fifos->client_path); - return -errno; + return 0; } if (chmod(fifos->server_path, 0600)) { - syslog(LOG_ERR, "Unable to set correct file permissions on %s", + syslog(LOG_ERR, "Unable to set correct file permissions on %s: %m.\n", fifos->server_path); - return -errno; + return 0; } /* Need to open read+write or we will block or fail */ if ((fifos->server = open(fifos->server_path, O_RDWR)) < 0) { - stack; - return -errno; + syslog(LOG_ERR, "Failed to open fifo server %s: %m.\n", + fifos->server_path); + return 0; } /* Need to open read+write for select() to work. */ if ((fifos->client = open(fifos->client_path, O_RDWR)) < 0) { - stack; - close(fifos->server); - return -errno; + syslog(LOG_ERR, "Failed to open fifo client %s: %m", fifos->client_path); + if (close(fifos->server)) + syslog(LOG_ERR, "Failed to close fifo server %s: %m", fifos->server_path); + return 0; } - return 0; + return 1; } /* @@ -1973,7 +1972,7 @@ int main(int argc, char *argv[]) pthread_mutex_init(&_global_mutex, NULL); - if (!_systemd_activation && _open_fifos(&fifos)) + if (!_systemd_activation && !_open_fifos(&fifos)) exit(EXIT_FIFO_FAILURE); /* Signal parent, letting them know we are ready to go. */