From a6b9e9d7688cc901dab6f8d375e55c5d79e3e0f3 Mon Sep 17 00:00:00 2001 From: Roman Rashchupkin Date: Fri, 16 Feb 2018 14:32:04 +0300 Subject: [PATCH] Add return error codes to libcare-ctl. --- src/kpatch_log.c | 4 ++-- src/kpatch_log.h | 10 ++++++++++ src/kpatch_user.c | 8 +++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/kpatch_log.c b/src/kpatch_log.c index f1a593a..b181a44 100644 --- a/src/kpatch_log.c +++ b/src/kpatch_log.c @@ -70,7 +70,7 @@ void kpfatal(const char *fmt, ...) if (parent_pid >= 0) stress_test_notify_parent(); #endif - exit(1); + exit(ERROR_FATAL); } extern int elf_errno(void) __attribute__((weak)); @@ -116,7 +116,7 @@ void _kpfatalerror(const char *file, int line, const char *fmt, ...) __valogerror(file, line, fmt, va); va_end(va); - exit(EXIT_FAILURE); + exit(ERROR_FATAL); } int log_file_init(char *fname) diff --git a/src/kpatch_log.h b/src/kpatch_log.h index ff9d268..24a1bba 100644 --- a/src/kpatch_log.h +++ b/src/kpatch_log.h @@ -3,6 +3,16 @@ #include +#define ERROR_SUCCESS 0 // exit code 0 +#define ERROR_FATAL -128 // exit code 128 +#define ERROR_GENERAL -10 +#define ERROR_PATCH -11 // exit code 246 +#define ERROR_UNPATCH -12 // exit code 245 +#define ERROR_ARGUMENTS -13 // exit code 244 +#define ERROR_NOPATCH -14 // exit code 243 +#define ERROR_ACCESS -15 // exit code 242 +#define ERROR_BUSY -16 // exit code 241 + extern int log_level, log_indent; void kplog(int level, const char *fmt, ...) __attribute__((format(printf, 2, 3))); diff --git a/src/kpatch_user.c b/src/kpatch_user.c index 6698ed4..cfe5d02 100644 --- a/src/kpatch_user.c +++ b/src/kpatch_user.c @@ -81,7 +81,7 @@ patch_user(const char *storage_path, int pid, ret = storage_init(&storage, storage_path); if (ret < 0) - return ret; + return ERROR_NOPATCH; ret = processes_patch(&storage, pid, is_just_started, send_fd); @@ -981,9 +981,11 @@ processes_do(int pid, callback_t callback, void *data) rv = callback(pid, data); if (rv < 0) - ret = -1; - if (rv == -2) + ret = rv; + if (rv == -2) { + ret = ERROR_GENERAL; break; + } } closedir(dir);