We standardize on wording of the form 'failed to ...: ' followed by the
strerror() message, and where possible, we follow the bulk of the existing
code in using %m rather than %s with strerror(errno).

Signed-off-by: Chris Webb <[email protected]>
---
 lib/event.c     |   14 +++++++-------
 lib/logger.c    |   30 ++++++++++++++----------------
 lib/net.c       |   35 ++++++++++++++++-------------------
 sheep/group.c   |    2 +-
 sheep/journal.c |    6 +++---
 sheep/sdnet.c   |    2 +-
 sheep/store.c   |   32 +++++++++++++++++---------------
 sheep/work.c    |    6 +++---
 8 files changed, 62 insertions(+), 65 deletions(-)

diff --git a/lib/event.c b/lib/event.c
index fd9e866..89e8f2a 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -47,7 +47,7 @@ void add_timer(struct timer *t, unsigned int seconds)
 
        tfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
        if (tfd < 0) {
-               eprintf("timerfd_create, %m\n");
+               eprintf("timerfd_create: %m\n");
                return;
        }
 
@@ -55,7 +55,7 @@ void add_timer(struct timer *t, unsigned int seconds)
        it.it_value.tv_sec = seconds;
 
        if (timerfd_settime(tfd, 0, &it, NULL) < 0) {
-               eprintf("timerfd_settime, %m\n");
+               eprintf("timerfd_settime: %m\n");
                return;
        }
 
@@ -111,7 +111,7 @@ int register_event(int fd, event_handler_t h, void *data)
 
        ret = epoll_ctl(efd, EPOLL_CTL_ADD, fd, &ev);
        if (ret) {
-               eprintf("can't add epoll event, %m\n");
+               eprintf("failed to add epoll event: %m\n");
                free(ei);
        } else
                list_add(&ei->ei_list, &events_list);
@@ -126,13 +126,13 @@ void unregister_event(int fd)
 
        ei = lookup_event(fd);
        if (!ei) {
-               eprintf("can't find a event\n");
+               eprintf("event info for fd %d not found\n", fd);
                return;
        }
 
        ret = epoll_ctl(efd, EPOLL_CTL_DEL, fd, NULL);
        if (ret)
-               eprintf("can't del epoll event, %m\n");
+               eprintf("failed to delete epoll event for fd %d: %m\n", fd);
 
        list_del(&ei->ei_list);
        free(ei);
@@ -156,7 +156,7 @@ int modify_event(int fd, unsigned int events)
 
        ret = epoll_ctl(efd, EPOLL_CTL_MOD, fd, &ev);
        if (ret) {
-               eprintf("can't del epoll event, %m\n");
+               eprintf("failed to delete epoll event for fd %d: %m\n", fd);
                return 1;
        }
        return 0;
@@ -171,7 +171,7 @@ void event_loop(int timeout)
        if (nr < 0) {
                if (errno == EINTR)
                        return;
-               eprintf("epoll_wait failed, %m\n");
+               eprintf("epoll_wait failed: %m\n");
                exit(1);
        } else if (nr) {
                for (i = 0; i < nr; i++) {
diff --git a/lib/logger.c b/lib/logger.c
index bf053f0..75147c0 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -58,13 +58,13 @@ static int logarea_init (int size)
 
        if ((shmid = shmget(IPC_PRIVATE, sizeof(struct logarea),
                            0644 | IPC_CREAT | IPC_EXCL)) == -1) {
-               syslog(LOG_ERR, "shmget logarea failed %d", errno);
+               syslog(LOG_ERR, "shmget logarea failed: %m");
                return 1;
        }
 
        la = shmat(shmid, NULL, 0);
        if (!la) {
-               syslog(LOG_ERR, "shmat logarea failed %d", errno);
+               syslog(LOG_ERR, "shmat logarea failed: %m");
                return 1;
        }
 
@@ -75,14 +75,14 @@ static int logarea_init (int size)
 
        if ((shmid = shmget(IPC_PRIVATE, size,
                            0644 | IPC_CREAT | IPC_EXCL)) == -1) {
-               syslog(LOG_ERR, "shmget msg failed %d", errno);
+               syslog(LOG_ERR, "shmget msg failed: %m");
                shmdt(la);
                return 1;
        }
 
        la->start = shmat(shmid, NULL, 0);
        if (!la->start) {
-               syslog(LOG_ERR, "shmat msg failed %d", errno);
+               syslog(LOG_ERR, "shmat msg failed: %m");
                shmdt(la);
                return 1;
        }
@@ -97,14 +97,14 @@ static int logarea_init (int size)
 
        if ((shmid = shmget(IPC_PRIVATE, MAX_MSG_SIZE + sizeof(struct logmsg),
                            0644 | IPC_CREAT | IPC_EXCL)) == -1) {
-               syslog(LOG_ERR, "shmget logmsg failed %d", errno);
+               syslog(LOG_ERR, "shmget logmsg failed: %m");
                shmdt(la->start);
                shmdt(la);
                return 1;
        }
        la->buff = shmat(shmid, NULL, 0);
        if (!la->buff) {
-               syslog(LOG_ERR, "shmat logmsgfailed %d", errno);
+               syslog(LOG_ERR, "shmat logmsg failed: %m");
                shmdt(la->start);
                shmdt(la);
                return 1;
@@ -113,7 +113,7 @@ static int logarea_init (int size)
        shmctl(shmid, IPC_RMID, NULL);
 
        if ((la->semid = semget(semkey, 1, 0666 | IPC_CREAT)) < 0) {
-               syslog(LOG_ERR, "semget failed %d", errno);
+               syslog(LOG_ERR, "semget failed: %m");
                shmdt(la->buff);
                shmdt(la->start);
                shmdt(la);
@@ -122,7 +122,7 @@ static int logarea_init (int size)
 
        la->semarg.val=1;
        if (semctl(la->semid, 0, SETVAL, la->semarg) < 0) {
-               syslog(LOG_ERR, "semctl failed %d", errno);
+               syslog(LOG_ERR, "semctl failed: %m");
                shmdt(la->buff);
                shmdt(la->start);
                shmdt(la);
@@ -291,7 +291,7 @@ static void dolog(int prio, const char *func, int line, 
const char *fmt, va_list
                ops.sem_flg = SEM_UNDO;
                ops.sem_op = -1;
                if (semop(la->semid, &ops, 1) < 0) {
-                       syslog(LOG_ERR, "semop up failed %m");
+                       syslog(LOG_ERR, "semop up failed: %m");
                        return;
                }
 
@@ -299,7 +299,7 @@ static void dolog(int prio, const char *func, int line, 
const char *fmt, va_list
 
                ops.sem_op = 1;
                if (semop(la->semid, &ops, 1) < 0) {
-                       syslog(LOG_ERR, "semop down failed");
+                       syslog(LOG_ERR, "semop down failed: %m");
                        return;
                }
        } else {
@@ -337,7 +337,7 @@ static void log_flush(void)
                ops.sem_flg = SEM_UNDO;
                ops.sem_op = -1;
                if (semop(la->semid, &ops, 1) < 0) {
-                       syslog(LOG_ERR, "semop up failed");
+                       syslog(LOG_ERR, "semop up failed: %m");
                        exit(1);
                }
 
@@ -345,7 +345,7 @@ static void log_flush(void)
 
                ops.sem_op = 1;
                if (semop(la->semid, &ops, 1) < 0) {
-                       syslog(LOG_ERR, "semop down failed");
+                       syslog(LOG_ERR, "semop down failed: %m");
                        exit(1);
                }
                log_syslog(la->buff);
@@ -406,8 +406,7 @@ int log_init(char *program_name, int size, int is_daemon, 
int level, char *outfi
 
                fd = open("/dev/null", O_RDWR);
                if (fd < 0) {
-                       syslog(LOG_ERR, "failed to open /dev/null: %s\n",
-                              strerror(errno));
+                       syslog(LOG_ERR, "failed to open /dev/null: %m\n");
                        exit(1);
                }
 
@@ -416,8 +415,7 @@ int log_init(char *program_name, int size, int is_daemon, 
int level, char *outfi
                dup2(fd, 2);
                setsid();
                if (chdir("/") < 0) {
-                       syslog(LOG_ERR, "failed to chdir to '/': %s\n",
-                              strerror(errno));
+                       syslog(LOG_ERR, "failed to chdir to /: %m\n");
                        exit(1);
                }
 
diff --git a/lib/net.c b/lib/net.c
index 60b1dd7..da11564 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -121,7 +121,7 @@ int create_listen_ports(int port, int (*callback)(int fd, 
void *), void *data)
 
        ret = getaddrinfo(NULL, servname, &hints, &res0);
        if (ret) {
-               eprintf("unable to get address info, %m\n");
+               eprintf("failed to get address info: %m\n");
                return 1;
        }
 
@@ -134,7 +134,7 @@ int create_listen_ports(int port, int (*callback)(int fd, 
void *), void *data)
                ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt,
                                 sizeof(opt));
                if (ret)
-                       eprintf("can't set SO_REUSEADDR, %m\n");
+                       eprintf("failed to set SO_REUSEADDR: %m\n");
 
                opt = 1;
                if (res->ai_family == AF_INET6) {
@@ -148,14 +148,14 @@ int create_listen_ports(int port, int (*callback)(int fd, 
void *), void *data)
 
                ret = bind(fd, res->ai_addr, res->ai_addrlen);
                if (ret) {
-                       fprintf(stderr, "can't bind server socket, %m\n");
+                       fprintf(stderr, "failed to bind server socket: %m\n");
                        close(fd);
                        continue;
                }
 
                ret = listen(fd, SOMAXCONN);
                if (ret) {
-                       eprintf("can't listen to server socket, %m\n");
+                       eprintf("failed to listen on server socket: %m\n");
                        close(fd);
                        continue;
                }
@@ -198,7 +198,7 @@ int connect_to(const char *name, int port)
 
        ret = getaddrinfo(name, buf, &hints, &res0);
        if (ret) {
-               fprintf(stderr, "unable to get address info, %m\n");
+               fprintf(stderr, "failed to get address info: %m\n");
                return -1;
        }
 
@@ -216,15 +216,15 @@ int connect_to(const char *name, int port)
                ret = setsockopt(fd, SOL_SOCKET, SO_LINGER, &linger_opt,
                                 sizeof(linger_opt));
                if (ret) {
-                       eprintf("can't set SO_LINGER, %m\n");
+                       eprintf("failed to set SO_LINGER: %m\n");
                        close(fd);
                        continue;
                }
 
                ret = connect(fd, res->ai_addr, res->ai_addrlen);
                if (ret)
-                       fprintf(stderr, "failed to connect to %s:%d, %s\n",
-                               name, port, strerror(errno));
+                       fprintf(stderr, "failed to connect to %s:%d: %m\n",
+                               name, port);
                else
                        goto success;
 
@@ -244,7 +244,7 @@ reread:
        if (ret < 0 || !ret) {
                if (errno == EINTR || errno == EAGAIN)
                        goto reread;
-               fprintf(stderr, "failed to send a req, %m\n");
+               fprintf(stderr, "failed to read from socket: %m\n");
                return 1;
        }
 
@@ -277,7 +277,7 @@ rewrite:
        if (ret < 0) {
                if (errno == EINTR || errno == EAGAIN)
                        goto rewrite;
-               fprintf(stderr, "failed to send a req, %m\n");
+               fprintf(stderr, "failed to write to socket: %m\n");
                return 1;
        }
 
@@ -312,7 +312,7 @@ int send_req(int sockfd, struct sd_req *hdr, void *data, 
unsigned int *wlen)
 
        ret = do_write(sockfd, &msg, sizeof(*hdr) + *wlen);
        if (ret) {
-               eprintf("failed to send a req, %x %d, %m\n", hdr->opcode,
+               eprintf("failed to send request %x, %d: %m\n", hdr->opcode,
                        *wlen);
                ret = -1;
        }
@@ -326,15 +326,12 @@ int exec_req(int sockfd, struct sd_req *hdr, void *data,
        int ret;
        struct sd_rsp *rsp = (struct sd_rsp *)hdr;
 
-       ret = send_req(sockfd, hdr, data, wlen);
-       if (ret) {
-               fprintf(stderr, "failed to send a req, %m\n");
+       if (send_req(sockfd, hdr, data, wlen))
                return 1;
-       }
 
        ret = do_read(sockfd, rsp, sizeof(*rsp));
        if (ret) {
-               fprintf(stderr, "failed to get a rsp, %m\n");
+               fprintf(stderr, "failed to read a response: %m\n");
                return 1;
        }
 
@@ -344,7 +341,7 @@ int exec_req(int sockfd, struct sd_req *hdr, void *data,
        if (*rlen) {
                ret = do_read(sockfd, data, *rlen);
                if (ret) {
-                       fprintf(stderr, "failed to get the data, %m\n");
+                       fprintf(stderr, "failed to read the response data: 
%m\n");
                        return 1;
                }
        }
@@ -381,12 +378,12 @@ int set_nonblocking(int fd)
 
        ret = fcntl(fd, F_GETFL);
        if (ret < 0) {
-               eprintf("can't fcntl (F_GETFL), %m\n");
+               eprintf("fcntl F_GETFL failed: %m\n");
                close(fd);
        } else {
                ret = fcntl(fd, F_SETFL, ret | O_NONBLOCK);
                if (ret < 0)
-                       eprintf("can't fcntl (O_NONBLOCK), %m\n");
+                       eprintf("fcntl O_NONBLOCK failed: %m\n");
        }
 
        return ret;
diff --git a/sheep/group.c b/sheep/group.c
index a17553f..3328550 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -463,7 +463,7 @@ static int get_vdi_bitmap_from(struct 
sheepdog_node_list_entry *node)
 
        fd = connect_to(host, node->port);
        if (fd < 0) {
-               vprintf(SDOG_ERR, "can't get the vdi bitmap %s, %m\n", host);
+               vprintf(SDOG_ERR, "unable to get the vdi bitmap from %s: %m\n", 
host);
                ret = -SD_RES_EIO;
                goto out;
        }
diff --git a/sheep/journal.c b/sheep/journal.c
index 19ac259..4368f1b 100644
--- a/sheep/journal.c
+++ b/sheep/journal.c
@@ -44,7 +44,7 @@ static int jrnl_open(struct jrnl_descriptor *jd, const char 
*path)
        jd->fd = open(path, O_RDONLY);
 
        if (jd->fd < 0) {
-               eprintf("failed to open %s, %s\n", jd->path, strerror(errno));
+               eprintf("failed to open %s: %m\n", jd->path);
                if (errno == ENOENT)
                        return SD_RES_NO_OBJ;
                else
@@ -68,7 +68,7 @@ static int jrnl_create(struct jrnl_descriptor *jd, const char 
*jrnl_dir)
        jd->fd = mkostemp(jd->path, O_SYNC);
 
        if (jd->fd < 0) {
-               eprintf("failed to create %s, %s\n", jd->path, strerror(errno));
+               eprintf("failed to create %s: %m\n", jd->path);
                return SD_RES_UNKNOWN;
        }
 
@@ -81,7 +81,7 @@ static int jrnl_remove(struct jrnl_descriptor *jd)
 
        ret = unlink(jd->path);
        if (ret) {
-               eprintf("failed to remove %s, %m\n", jd->path);
+               eprintf("failed to remove %s: %m\n", jd->path);
                ret = SD_RES_EIO;
        } else
                ret = SD_RES_SUCCESS;
diff --git a/sheep/sdnet.c b/sheep/sdnet.c
index 19357a6..e14cf0c 100644
--- a/sheep/sdnet.c
+++ b/sheep/sdnet.c
@@ -546,7 +546,7 @@ static void listen_handler(int listen_fd, int events, void 
*data)
        namesize = sizeof(from);
        fd = accept(listen_fd, (struct sockaddr *)&from, &namesize);
        if (fd < 0) {
-               eprintf("can't accept a new connection, %m\n");
+               eprintf("failed to accept a new connection: %m\n");
                return;
        }
 
diff --git a/sheep/store.c b/sheep/store.c
index d46668e..e2e24ec 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -404,7 +404,7 @@ again:
                        continue;
 
                if (do_read(pfds[i].fd, rsp, sizeof(*rsp))) {
-                       eprintf("failed to get a rsp, %m\n");
+                       eprintf("failed to read a response: %m\n");
                        ret = SD_RES_NETWORK_ERROR;
                        break;
                }
@@ -445,7 +445,7 @@ static int ob_open(uint32_t epoch, uint64_t oid, int 
aflags, int *ret)
 
        fd = open(path, flags, def_fmode);
        if (fd < 0) {
-               eprintf("failed to open %s, %s\n", path, strerror(errno));
+               eprintf("failed to open %s: %m\n", path);
                if (errno == ENOENT) {
                        struct stat s;
 
@@ -867,7 +867,7 @@ int epoch_log_read_remote(uint32_t epoch, char *buf, int 
len)
                addr_to_str(host, sizeof(host), nodes[i].addr, 0);
                fd = connect_to(host, nodes[i].port);
                if (fd < 0) {
-                       vprintf(SDOG_ERR, "can't connect to %s, %m\n", host);
+                       vprintf(SDOG_ERR, "failed to connect to %s: %m\n", 
host);
                        continue;
                }
 
@@ -928,7 +928,7 @@ int get_latest_epoch(void)
 
        dir = opendir(epoch_path);
        if (!dir) {
-               vprintf(SDOG_EMERG, "failed to get the latest epoch, %m\n");
+               vprintf(SDOG_EMERG, "failed to get the latest epoch: %m\n");
                abort();
        }
 
@@ -957,7 +957,7 @@ static int rmdir_r(char *dir_path)
        dir = opendir(dir_path);
        if (!dir) {
                if (errno != ENOENT)
-                       eprintf("failed, %s, %"PRIu32"\n", dir_path, errno);
+                       eprintf("failed to open %s: %m\n", dir_path);
                return -errno;
        }
 
@@ -968,7 +968,7 @@ static int rmdir_r(char *dir_path)
                snprintf(path, sizeof(path), "%s/%s", dir_path, d->d_name);
                ret = stat(path, &s);
                if (ret) {
-                       eprintf("cannot remove directory %s\n", path);
+                       eprintf("failed to stat %s: %m\n", path);
                        goto out;
                }
                if (S_ISDIR(s.st_mode))
@@ -977,7 +977,9 @@ static int rmdir_r(char *dir_path)
                        ret = unlink(path);
 
                if (ret != 0) {
-                       eprintf("failed, %s, %"PRIu32", %"PRIu32"\n", path, 
S_ISDIR(s.st_mode), errno);
+                       eprintf("failed to remove %s %s: %m\n",
+                               S_ISDIR(s.st_mode) ? "directory" : "file",
+                               path);
                        goto out;
                }
        }
@@ -997,21 +999,21 @@ int remove_epoch(int epoch)
        snprintf(path, sizeof(path), "%s%08u", epoch_path, epoch);
        ret = unlink(path);
        if (ret && ret != -ENOENT) {
-               eprintf("failed to remove %s, %s\n", path, strerror(-ret));
+               eprintf("failed to remove %s: %s\n", path, strerror(-ret));
                return SD_RES_EIO;
        }
 
        snprintf(path, sizeof(path), "%s%08u", obj_path, epoch);
        ret = rmdir_r(path);
        if (ret && ret != -ENOENT) {
-               eprintf("failed to remove %s, %s\n", path, strerror(-ret));
+               eprintf("failed to remove %s: %s\n", path, strerror(-ret));
                return SD_RES_EIO;
        }
 
        snprintf(path, sizeof(path), "%s%08u/", jrnl_path, epoch);
        ret = rmdir_r(path);
        if (ret && ret != -ENOENT) {
-               eprintf("failed to remove %s, %s\n", path, strerror(-ret));
+               eprintf("failed to remove %s: %s\n", path, strerror(-ret));
                return SD_RES_EIO;
        }
        return 0;
@@ -1332,7 +1334,7 @@ next:
 
                fd = open(tmp_path, flags, def_fmode);
                if (fd < 0) {
-                       eprintf("failed to open %s, %s\n", tmp_path, 
strerror(errno));
+                       eprintf("failed to open %s: %m\n", tmp_path);
                        goto err;
                }
 
@@ -1347,7 +1349,7 @@ next:
                dprintf("rename %s to %s\n", tmp_path, path);
                ret = rename(tmp_path, path);
                if (ret < 0) {
-                       eprintf("failed to rename %s to %s, %m\n", tmp_path, 
path);
+                       eprintf("failed to rename %s to %s: %m\n", tmp_path, 
path);
                        goto err;
                }
                dprintf("recovered oid %"PRIx64" to epoch %"PRIu32"\n", oid, 
epoch);
@@ -1842,13 +1844,13 @@ again:
        ret = stat(d, &s);
        if (ret) {
                if (retry || errno != ENOENT) {
-                       eprintf("can't handle the dir %s, %m\n", d);
+                       eprintf("cannot handle the directory %s: %m\n", d);
                        return 1;
                }
 
                ret = mkdir(d, def_dmode);
                if (ret) {
-                       eprintf("can't create the dir %s, %m\n", d);
+                       eprintf("cannot create the directory %s: %m\n", d);
                        return 1;
                } else {
                        *new = 1;
@@ -1914,7 +1916,7 @@ static int init_epoch_path(const char *base_path)
                        if (errno == ENOENT)
                                continue;
 
-                       vprintf(SDOG_ERR, "failed to open the epoch dir, %m\n");
+                       vprintf(SDOG_ERR, "failed to open the epoch directory: 
%m\n");
                        return SD_RES_EIO;
                }
 
diff --git a/sheep/work.c b/sheep/work.c
index a417107..f33b914 100644
--- a/sheep/work.c
+++ b/sheep/work.c
@@ -247,7 +247,7 @@ static int init_eventfd(void)
 
        efd = eventfd(0, EFD_NONBLOCK);
        if (efd < 0) {
-               eprintf("failed to create an event fd, %m\n");
+               eprintf("failed to create an event fd: %m\n");
                return 1;
        }
 
@@ -287,7 +287,7 @@ struct work_queue *init_work_queue(int nr)
                                     worker_routine, wi);
 
                if (ret) {
-                       eprintf("failed to create a worker thread, %d %s\n",
+                       eprintf("failed to create worker thread #%d: %s\n",
                                i, strerror(ret));
                        if (ret)
                                goto destroy_threads;
@@ -304,7 +304,7 @@ destroy_threads:
        pthread_mutex_unlock(&wi->startup_lock);
        for (; i > 0; i--) {
                pthread_join(wi->worker_thread[i - 1], NULL);
-               eprintf("stopped the worker thread %d\n", i - 1);
+               eprintf("stopped worker thread #%d\n", i - 1);
        }
 
 /* destroy_cond_mutex: */
-- 
1.7.5.4

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to