It's too error-prone to be useful.
time_t *end_seconds = (time_t *) (uint64_t *)&end; /* STFU, gcc */
char start_str[200], end_str[200];
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))
- }
- if (!localtime_r(end_seconds, &end_tm)) {
- make_err_msg("%lli", (long long)end);
+ if (!localtime_r(end_seconds, &end_tm))
- }
- 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))
- }
- 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))
*result = make_message("%lli-%lli.%s-%s", (long long) start, (long long) end,
start_str, end_str);
return 1;
*result = make_message("%lli-%lli.%s-%s", (long long) start, (long long) end,
start_str, end_str);
return 1;
kill(pid, SIGTERM);
}
if (ret < 0)
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;
else
log_termination_msg(pid, *status);
return ret;
int handle_rm_exit(int status)
{
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;
+ if (!WIFEXITED(status))
+ return -E_INVOLUNTARY_EXIT;
+ if (WEXITSTATUS(status))
+ return -E_BAD_EXIT_CODE;
+ return 1;
}
int wait_for_rm_process(void)
}
int wait_for_rm_process(void)
int check_config(void)
{
if (conf.unit_interval_arg <= 0) {
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) {
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);
return -E_INVALID_NUMBER;
}
DSS_DEBUG_LOG("number of intervals: %i\n", conf.num_intervals_arg);
ret = stat(config_file, &statbuf);
if (ret && conf.config_file_given) {
ret = -ERRNO_TO_DSS_ERROR(errno);
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);
free(config_file);
if (ret >= 0)
return;
free(config_file);
if (ret >= 0)
return;
- log_err_msg(EMERG, -ret);
+ DSS_EMERG_LOG("%s\n", dss_strerror(-ret));
int es, ret;
if (!WIFEXITED(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();
ret = -E_INVOLUNTARY_EXIT;
snapshot_creation_status = SCS_READY;
compute_next_snapshot_time();
}
es = WEXITSTATUS(status);
if (es != 0 && es != 23 && es != 24) {
}
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();
ret = -E_BAD_EXIT_CODE;
snapshot_creation_status = SCS_READY;
compute_next_snapshot_time();
int es, ret;
if (!WIFEXITED(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;
snapshot_creation_status = SCS_READY;
compute_next_snapshot_time();
ret = -E_INVOLUNTARY_EXIT;
}
es = WEXITSTATUS(status);
if (es) {
}
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;
snapshot_creation_status = SCS_READY;
compute_next_snapshot_time();
ret = -E_BAD_EXIT_CODE;
- log_err_msg(ERROR, -ret);
+ DSS_ERROR_LOG("%s\n", dss_strerror(-ret));
}
int get_oldest(const char *dirname, void *private)
}
int get_oldest(const char *dirname, void *private)
ret = remove_oldest_snapshot();
if (ret)
goto out;
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);
ret= -ENOSPC;
out:
free_snapshot_list(&sl);
int ret;
if (conf.dry_run_given) {
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);
return -E_SYNTAX;
}
ret = install_sighandler(SIGHUP);
-__noreturn void clean_exit(int status)
-{
- free(dss_error_txt);
- exit(status);
-}
static void setup_signal_handling(void)
{
int ret;
static void setup_signal_handling(void)
{
int ret;
setup_signal_handling();
ret = call_command_handler();
if (ret < 0)
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);
return dss_errlist[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") \
#define DSS_ERRORS \
DSS_ERROR(SUCCESS, "success") \
DSS_ERROR(SYNTAX, "syntax error") \
#include "error.h"
#include "string.h"
#include "error.h"
#include "string.h"
close(null);
return 1;
err_out:
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)
if (err[0] >= 0)
close(err[0]);
if (err[1] >= 0)
int ret;
DIR *dir = opendir(".");
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;
while ((entry = readdir(dir))) {
mode_t m;
struct stat s;
ret = lstat(entry->d_name, &s) == -1;
if (ret == -1) {
ret = -ERRNO_TO_DSS_ERROR(errno);
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;
goto out;
}
m = s.st_mode;
*/
int dss_chdir(const char *path)
{
*/
int dss_chdir(const char *path)
{
- int ret = chdir(path);
-
- if (ret >= 0)
- ret = -ERRNO_TO_DSS_ERROR(errno);
- make_err_msg("chdir to %s failed", path);
- return ret;
+ return -ERRNO_TO_DSS_ERROR(errno);
*/
_static_inline_ int dss_rename(const char *old_path, const char *new_path)
{
*/
_static_inline_ int dss_rename(const char *old_path, const char *new_path)
{
if (rename(old_path, new_path) >= 0)
return 1;
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,
}
int dss_select(int n, fd_set *readfds, fd_set *writefds,
DSS_DEBUG_LOG("catching signal %d\n", sig);
if (signal(sig, &generic_signal_handler) != SIG_ERR)
return 1;
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;
}
return -E_SIGNAL_SIG_ERR;
}
assert(r < 0);
if (err == EAGAIN)
return 0;
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);
}
return -ERRNO_TO_DSS_ERROR(err);
}
#include "error.h"
#include "string.h"
#include "error.h"
#include "string.h"
-__noreturn void clean_exit(int status);
-
/**
* Write a message to a dynamically allocated string.
*
/**
* Write a message to a dynamically allocated string.
*
if (!(p = realloc(p, size))) {
DSS_EMERG_LOG("realloc failed (size = %zu), aborting\n",
size);
if (!(p = realloc(p, size))) {
DSS_EMERG_LOG("realloc failed (size = %zu), aborting\n",
size);
- clean_exit(EXIT_FAILURE);
if (!p) {
DSS_EMERG_LOG("malloc failed (size = %zu), aborting\n",
size);
if (!p) {
DSS_EMERG_LOG("malloc failed (size = %zu), aborting\n",
size);
- clean_exit(EXIT_FAILURE);
if ((ret = strdup(s? s: "")))
return ret;
DSS_EMERG_LOG("strdup failed, aborting\n");
if ((ret = strdup(s? s: "")))
return ret;
DSS_EMERG_LOG("strdup failed, aborting\n");
- clean_exit(EXIT_FAILURE);
-__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.
*
/**
* Get the home directory of the current user.
*
errno = 0; /* To distinguish success/failure after call */
tmp = strtoll(str, &endptr, 10);
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))
- }
- if (errno != 0 && tmp == 0) { /* other error */
- make_err_msg("%s", str);
+ if (errno != 0 && tmp == 0) /* other error */
- }
- if (endptr == str) {
- make_err_msg("%s", str);
return -E_ATOI_NO_DIGITS;
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;
return -E_ATOI_JUNK_AT_END;
*value = tmp;
return 1;
}
*value = tmp;
return 1;
}
__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);
__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);
__must_check __malloc char *get_homedir(void);
int dss_atoi64(const char *str, int64_t *value);
__must_check __malloc char *dss_logname(void);