Skip to content

Commit

Permalink
Add return error codes to libcare-ctl.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Rashchupkin committed Feb 16, 2018
1 parent fb0f8af commit a6b9e9d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/kpatch_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/kpatch_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

#include <stdio.h>

#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)));
Expand Down
8 changes: 5 additions & 3 deletions src/kpatch_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a6b9e9d

Please sign in to comment.