Get rid of make_err_msg() and log_err_msg().
authorAndre Noll <maan@systemlinux.org>
Sat, 22 Mar 2008 11:09:40 +0000 (12:09 +0100)
committerAndre Noll <maan@systemlinux.org>
Sat, 22 Mar 2008 11:09:40 +0000 (12:09 +0100)
It's too error-prone to be useful.

dss.c
error.h
exec.c
fd.c
fd.h
signal.c
string.c
string.h

diff --git a/dss.c b/dss.c
index c3a0965..df4a7ee 100644 (file)
--- a/dss.c
+++ b/dss.c
@@ -270,22 +270,14 @@ int complete_name(int64_t start, int64_t end, char **result)
        time_t *end_seconds = (time_t *) (uint64_t *)&end; /* STFU, gcc */
        char start_str[200], end_str[200];
 
-       if (!localtime_r(start_seconds, &start_tm)) {
-               make_err_msg("%lli", (long long)start);
+       if (!localtime_r(start_seconds, &start_tm))
                return -E_LOCALTIME;
-       }
-       if (!localtime_r(end_seconds, &end_tm)) {
-               make_err_msg("%lli", (long long)end);
+       if (!localtime_r(end_seconds, &end_tm))
                return -E_LOCALTIME;
-       }
-       if (!strftime(start_str, sizeof(start_str), "%a_%b_%d_%Y_%H_%M_%S", &start_tm)) {
-               make_err_msg("%lli", (long long)start);
+       if (!strftime(start_str, sizeof(start_str), "%a_%b_%d_%Y_%H_%M_%S", &start_tm))
                return -E_STRFTIME;
-       }
-       if (!strftime(end_str, sizeof(end_str), "%a_%b_%d_%Y_%H_%M_%S", &end_tm)) {
-               make_err_msg("%lli", (long long)end);
+       if (!strftime(end_str, sizeof(end_str), "%a_%b_%d_%Y_%H_%M_%S", &end_tm))
                return -E_STRFTIME;
-       }
        *result = make_message("%lli-%lli.%s-%s", (long long) start, (long long) end,
                start_str, end_str);
        return 1;
@@ -429,7 +421,7 @@ int wait_for_process(pid_t pid, int *status)
                kill(pid, SIGTERM);
        }
        if (ret < 0)
-               make_err_msg("failed to wait for process %d", (int)pid);
+               DSS_ERROR_LOG("failed to wait for process %d\n", (int)pid);
        else
                log_termination_msg(pid, *status);
        return ret;
@@ -539,23 +531,12 @@ int remove_outdated_snapshot(struct snapshot_list *sl)
 
 int handle_rm_exit(int status)
 {
-       int es, ret;
-
-       if (!WIFEXITED(status)) {
-               make_err_msg("rm process %d died involuntary", (int)rm_pid);
-               ret = -E_INVOLUNTARY_EXIT;
-               goto out;
-       }
-       es = WEXITSTATUS(status);
-       if (es) {
-               make_err_msg("rm process %d returned %d", (int)rm_pid, es);
-               ret = -E_BAD_EXIT_CODE;
-               goto out;
-       }
-       ret = 1;
        rm_pid = 0;
-out:
-       return ret;
+       if (!WIFEXITED(status))
+               return -E_INVOLUNTARY_EXIT;
+       if (WEXITSTATUS(status))
+               return -E_BAD_EXIT_CODE;
+       return 1;
 }
 
 int wait_for_rm_process(void)
@@ -578,12 +559,12 @@ void kill_process(pid_t pid)
 int check_config(void)
 {
        if (conf.unit_interval_arg <= 0) {
-               make_err_msg("bad unit interval: %i", conf.unit_interval_arg);
+               DSS_ERROR_LOG("bad unit interval: %i\n", conf.unit_interval_arg);
                return -E_INVALID_NUMBER;
        }
        DSS_DEBUG_LOG("unit interval: %i day(s)\n", conf.unit_interval_arg);
        if (conf.num_intervals_arg <= 0) {
-               make_err_msg("bad number of intervals  %i", conf.num_intervals_arg);
+               DSS_ERROR_LOG("bad number of intervals  %i\n", conf.num_intervals_arg);
                return -E_INVALID_NUMBER;
        }
        DSS_DEBUG_LOG("number of intervals: %i\n", conf.num_intervals_arg);
@@ -615,7 +596,7 @@ void parse_config_file(int override)
        ret = stat(config_file, &statbuf);
        if (ret && conf.config_file_given) {
                ret = -ERRNO_TO_DSS_ERROR(errno);
-               make_err_msg("failed to stat config file %s", config_file);
+               DSS_ERROR_LOG("failed to stat config file %s\n", config_file);
                goto out;
        }
        if (!ret) {
@@ -653,7 +634,7 @@ out:
        free(config_file);
        if (ret >= 0)
                return;
-       log_err_msg(EMERG, -ret);
+       DSS_EMERG_LOG("%s\n", dss_strerror(-ret));
        exit(EXIT_FAILURE);
 }
 
@@ -729,7 +710,7 @@ int handle_rsync_exit(int status)
        int es, ret;
 
        if (!WIFEXITED(status)) {
-               make_err_msg("rsync process %d died involuntary", (int)rsync_pid);
+               DSS_ERROR_LOG("rsync process %d died involuntary\n", (int)rsync_pid);
                ret = -E_INVOLUNTARY_EXIT;
                snapshot_creation_status = SCS_READY;
                compute_next_snapshot_time();
@@ -737,7 +718,7 @@ int handle_rsync_exit(int status)
        }
        es = WEXITSTATUS(status);
        if (es != 0 && es != 23 && es != 24) {
-               make_err_msg("rsync process %d returned %d", (int)rsync_pid, es);
+               DSS_ERROR_LOG("rsync process %d returned %d\n", (int)rsync_pid, es);
                ret = -E_BAD_EXIT_CODE;
                snapshot_creation_status = SCS_READY;
                compute_next_snapshot_time();
@@ -883,8 +864,6 @@ int handle_pre_create_hook_exit(int status)
        int es, ret;
 
        if (!WIFEXITED(status)) {
-               make_err_msg("pre-create-hook %d died involuntary",
-                       (int)pre_create_hook_pid);
                snapshot_creation_status = SCS_READY;
                compute_next_snapshot_time();
                ret = -E_INVOLUNTARY_EXIT;
@@ -892,8 +871,6 @@ int handle_pre_create_hook_exit(int status)
        }
        es = WEXITSTATUS(status);
        if (es) {
-               make_err_msg("pre-create-hook %d returned %d",
-                       (int)pre_create_hook_pid, es);
                snapshot_creation_status = SCS_READY;
                compute_next_snapshot_time();
                ret = -E_BAD_EXIT_CODE;
@@ -952,7 +929,7 @@ void handle_signal(void)
        }
 out:
        if (ret < 0)
-               log_err_msg(ERROR, -ret);
+               DSS_ERROR_LOG("%s\n", dss_strerror(-ret));
 }
 
 int get_oldest(const char *dirname, void *private)
@@ -1027,7 +1004,7 @@ int try_to_free_disk_space(int low_disk_space)
        ret = remove_oldest_snapshot();
        if (ret)
                goto out;
-       make_err_msg("uhuhu: not enough disk space for a single snapshot");
+       DSS_CRIT_LOG("uhuhu: not enough disk space for a single snapshot\n");
        ret= -ENOSPC;
 out:
        free_snapshot_list(&sl);
@@ -1109,7 +1086,7 @@ int com_run(void)
        int ret;
 
        if (conf.dry_run_given) {
-               make_err_msg("dry_run not supported by this command");
+               DSS_ERROR_LOG("dry_run not supported by this command\n");
                return -E_SYNTAX;
        }
        ret = install_sighandler(SIGHUP);
@@ -1226,11 +1203,6 @@ int com_ls(void)
        return 1;
 }
 
-__noreturn void clean_exit(int status)
-{
-       free(dss_error_txt);
-       exit(status);
-}
 static void setup_signal_handling(void)
 {
        int ret;
@@ -1270,6 +1242,6 @@ int main(int argc, char **argv)
        setup_signal_handling();
        ret = call_command_handler();
        if (ret < 0)
-               log_err_msg(EMERG, -ret);
-       clean_exit(ret >= 0? EXIT_SUCCESS : EXIT_FAILURE);
+               DSS_EMERG_LOG("%s\n", dss_strerror(-ret));
+       exit(ret >= 0? EXIT_SUCCESS : EXIT_FAILURE);
 }
diff --git a/error.h b/error.h
index d54845d..af6c055 100644 (file)
--- a/error.h
+++ b/error.h
@@ -46,11 +46,6 @@ static inline char *dss_strerror(int num)
                return dss_errlist[num];
 }
 
-static inline void log_err_msg(int loglevel, int num)
-{
-       dss_log(loglevel, "%s (%s)\n", dss_error_txt, dss_strerror(num));
-}
-
 #define DSS_ERRORS \
        DSS_ERROR(SUCCESS, "success") \
        DSS_ERROR(SYNTAX, "syntax error") \
diff --git a/exec.c b/exec.c
index 4e7acd5..164feb2 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -11,6 +11,7 @@
 
 
 #include "gcc-compat.h"
+#include "log.h"
 #include "error.h"
 #include "string.h"
 
@@ -96,7 +97,7 @@ int dss_exec(pid_t *pid, const char *file, char *const *const args, int *fds)
                close(null);
        return 1;
 err_out:
-       make_err_msg("failed to exec %s", file);
+       DSS_ERROR_LOG("failed to exec %s\n", file);
        if (err[0] >= 0)
                close(err[0]);
        if (err[1] >= 0)
diff --git a/fd.c b/fd.c
index 4ac6170..4fbdfd0 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -35,11 +35,8 @@ int for_each_subdir(int (*func)(const char *, void *), void *private_data)
        int ret;
        DIR *dir = opendir(".");
 
-       if (!dir) {
-               ret = -ERRNO_TO_DSS_ERROR(errno);
-               make_err_msg("opendir(\".\") failed");
-               return ret;
-       }
+       if (!dir)
+               return -ERRNO_TO_DSS_ERROR(errno);
        while ((entry = readdir(dir))) {
                mode_t m;
                struct stat s;
@@ -51,7 +48,6 @@ int for_each_subdir(int (*func)(const char *, void *), void *private_data)
                ret = lstat(entry->d_name, &s) == -1;
                if (ret == -1) {
                        ret = -ERRNO_TO_DSS_ERROR(errno);
-                       make_err_msg("lstat(\"%s\") failed", entry->d_name);
                        goto out;
                }
                m = s.st_mode;
@@ -75,13 +71,9 @@ out:
  */
 int dss_chdir(const char *path)
 {
-       int ret = chdir(path);
-
-       if (ret >= 0)
+       if (chdir(path) >= 0)
                return 1;
-       ret = -ERRNO_TO_DSS_ERROR(errno);
-       make_err_msg("chdir to %s failed", path);
-       return ret;
+       return -ERRNO_TO_DSS_ERROR(errno);
 }
 
 /**
diff --git a/fd.h b/fd.h
index e24d446..d292db0 100644 (file)
--- a/fd.h
+++ b/fd.h
@@ -13,13 +13,9 @@ __must_check int mark_fd_nonblocking(int fd);
  */
 _static_inline_ int dss_rename(const char *old_path, const char *new_path)
 {
-       int ret;
-
        if (rename(old_path, new_path) >= 0)
                return 1;
-       ret = -ERRNO_TO_DSS_ERROR(errno);
-       make_err_msg("rename %s -> %s failed", old_path, new_path);
-       return ret;
+       return -ERRNO_TO_DSS_ERROR(errno);
 }
 
 int dss_select(int n, fd_set *readfds, fd_set *writefds,
index 03926a4..7594953 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -120,7 +120,6 @@ int install_sighandler(int sig)
        DSS_DEBUG_LOG("catching signal %d\n", sig);
        if (signal(sig, &generic_signal_handler) != SIG_ERR)
                return 1;
-       make_err_msg("signal %d", sig);
        return -E_SIGNAL_SIG_ERR;
 }
 
@@ -147,7 +146,7 @@ int next_signal(void)
        assert(r < 0);
        if (err == EAGAIN)
                return 0;
-       make_err_msg("failed to read from signal pipe");
+       DSS_ERROR_LOG("failed to read from signal pipe\n");
        return -ERRNO_TO_DSS_ERROR(err);
 }
 
index 38fb1ee..afac002 100644 (file)
--- a/string.c
+++ b/string.c
@@ -15,8 +15,6 @@
 #include "error.h"
 #include "string.h"
 
-__noreturn void clean_exit(int status);
-
 /**
  * Write a message to a dynamically allocated string.
  *
@@ -71,7 +69,7 @@ __must_check __malloc void *dss_realloc(void *p, size_t size)
        if (!(p = realloc(p, size))) {
                DSS_EMERG_LOG("realloc failed (size = %zu), aborting\n",
                        size);
-               clean_exit(EXIT_FAILURE);
+               exit(EXIT_FAILURE);
        }
        return p;
 }
@@ -96,7 +94,7 @@ __must_check __malloc void *dss_malloc(size_t size)
        if (!p) {
                DSS_EMERG_LOG("malloc failed (size = %zu),  aborting\n",
                        size);
-               clean_exit(EXIT_FAILURE);
+               exit(EXIT_FAILURE);
        }
        return p;
 }
@@ -142,7 +140,7 @@ __must_check __malloc char *dss_strdup(const char *s)
        if ((ret = strdup(s? s: "")))
                return ret;
        DSS_EMERG_LOG("strdup failed, aborting\n");
-       clean_exit(EXIT_FAILURE);
+       exit(EXIT_FAILURE);
 }
 
 /**
@@ -166,12 +164,6 @@ __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...)
        return msg;
 }
 
-__printf_1_2 void make_err_msg(const char* fmt,...)
-{
-       free(dss_error_txt);
-       VSPRINTF(fmt, dss_error_txt);
-}
-
 /**
  * Get the home directory of the current user.
  *
@@ -201,22 +193,14 @@ int dss_atoi64(const char *str, int64_t *value)
 
        errno = 0; /* To distinguish success/failure after call */
        tmp = strtoll(str, &endptr, 10);
-       if (errno == ERANGE && (tmp == LLONG_MAX || tmp == LLONG_MIN)) {
-               make_err_msg("%s", str);
+       if (errno == ERANGE && (tmp == LLONG_MAX || tmp == LLONG_MIN))
                return -E_ATOI_OVERFLOW;
-       }
-       if (errno != 0 && tmp == 0) { /* other error */
-               make_err_msg("%s", str);
+       if (errno != 0 && tmp == 0) /* other error */
                return -E_STRTOLL;
-       }
-       if (endptr == str) {
-               make_err_msg("%s", str);
+       if (endptr == str)
                return -E_ATOI_NO_DIGITS;
-       }
-       if (*endptr != '\0') { /* Further characters after number */
-               make_err_msg("%s", str);
+       if (*endptr != '\0') /* Further characters after number */
                return -E_ATOI_JUNK_AT_END;
-       }
        *value = tmp;
        return 1;
 }
index 6c0ab61..a4cbdbe 100644 (file)
--- a/string.h
+++ b/string.h
@@ -3,7 +3,6 @@ __must_check __malloc void *dss_malloc(size_t size);
 __must_check __malloc void *dss_calloc(size_t size);
 __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...);
 __must_check __malloc char *dss_strdup(const char *s);
-__printf_1_2 void make_err_msg(const char* fmt,...);
 __must_check __malloc char *get_homedir(void);
 int dss_atoi64(const char *str, int64_t *value);
 __must_check __malloc char *dss_logname(void);