Skip to content

Commit a6b9e9d

Browse files
author
Roman Rashchupkin
committed
Add return error codes to libcare-ctl.
1 parent fb0f8af commit a6b9e9d

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/kpatch_log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void kpfatal(const char *fmt, ...)
7070
if (parent_pid >= 0)
7171
stress_test_notify_parent();
7272
#endif
73-
exit(1);
73+
exit(ERROR_FATAL);
7474
}
7575

7676
extern int elf_errno(void) __attribute__((weak));
@@ -116,7 +116,7 @@ void _kpfatalerror(const char *file, int line, const char *fmt, ...)
116116
__valogerror(file, line, fmt, va);
117117
va_end(va);
118118

119-
exit(EXIT_FAILURE);
119+
exit(ERROR_FATAL);
120120
}
121121

122122
int log_file_init(char *fname)

src/kpatch_log.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33

44
#include <stdio.h>
55

6+
#define ERROR_SUCCESS 0 // exit code 0
7+
#define ERROR_FATAL -128 // exit code 128
8+
#define ERROR_GENERAL -10
9+
#define ERROR_PATCH -11 // exit code 246
10+
#define ERROR_UNPATCH -12 // exit code 245
11+
#define ERROR_ARGUMENTS -13 // exit code 244
12+
#define ERROR_NOPATCH -14 // exit code 243
13+
#define ERROR_ACCESS -15 // exit code 242
14+
#define ERROR_BUSY -16 // exit code 241
15+
616
extern int log_level, log_indent;
717

818
void kplog(int level, const char *fmt, ...) __attribute__((format(printf, 2, 3)));

src/kpatch_user.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ patch_user(const char *storage_path, int pid,
8181

8282
ret = storage_init(&storage, storage_path);
8383
if (ret < 0)
84-
return ret;
84+
return ERROR_NOPATCH;
8585

8686
ret = processes_patch(&storage, pid, is_just_started, send_fd);
8787

@@ -981,9 +981,11 @@ processes_do(int pid, callback_t callback, void *data)
981981

982982
rv = callback(pid, data);
983983
if (rv < 0)
984-
ret = -1;
985-
if (rv == -2)
984+
ret = rv;
985+
if (rv == -2) {
986+
ret = ERROR_GENERAL;
986987
break;
988+
}
987989
}
988990

989991
closedir(dir);

0 commit comments

Comments
 (0)