kpatch-build: add exit status enum

Convert magic exit status values into a common enum for clarity.

Suggested-by: Artem Savkov <asavkov@redhat.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
This commit is contained in:
Joe Lawrence 2018-06-14 10:36:34 -04:00
parent 9f7c76b9c1
commit 1f4551a49e
3 changed files with 18 additions and 5 deletions

View File

@ -52,11 +52,12 @@
#include "kpatch-patch.h"
#include "kpatch-elf.h"
#include "kpatch-intermediate.h"
#include "kpatch.h"
#define DIFF_FATAL(format, ...) \
({ \
fprintf(stderr, "ERROR: %s: " format "\n", childobj, ##__VA_ARGS__); \
error(2, 0, "unreconcilable difference"); \
error(EXIT_STATUS_DIFF_FATAL, 0, "unreconcilable difference"); \
})
#ifdef __powerpc__
@ -3084,7 +3085,7 @@ int main(int argc, char *argv[])
}
if (!hint) {
log_normal("WARNING: FILE symbol not found in base. Stripped object file or assembly source?\n");
return 3; /* NO_CHANGE */
return EXIT_STATUS_NO_CHANGE;
}
/* create symbol lookup table */
@ -3132,7 +3133,7 @@ int main(int argc, char *argv[])
log_debug("no changed functions were found, but callbacks exist\n");
else {
log_debug("no changed functions were found\n");
return 3; /* 1 is ERROR, 2 is DIFF_FATAL */
return EXIT_STATUS_NO_CHANGE;
}
}
@ -3192,5 +3193,5 @@ int main(int argc, char *argv[])
kpatch_elf_teardown(kelf_out);
kpatch_elf_free(kelf_out);
return 0;
return EXIT_STATUS_SUCCESS;
}

11
kpatch-build/kpatch.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef _KPATCH_H_
#define _KPATCH_H_
enum exit_status {
EXIT_STATUS_SUCCESS = 0,
EXIT_STATUS_ERROR = 1,
EXIT_STATUS_DIFF_FATAL = 2,
EXIT_STATUS_NO_CHANGE = 3,
};
#endif /* _KPATCH_H_ */

View File

@ -2,13 +2,14 @@
#define _LOG_H_
#include <error.h>
#include "kpatch.h"
/* Files that include log.h must define loglevel and childobj */
extern enum loglevel loglevel;
extern char *childobj;
#define ERROR(format, ...) \
error(1, 0, "ERROR: %s: %s: %d: " format, childobj, __FUNCTION__, __LINE__, ##__VA_ARGS__)
error(EXIT_STATUS_ERROR, 0, "ERROR: %s: %s: %d: " format, childobj, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define log_debug(format, ...) log(DEBUG, format, ##__VA_ARGS__)
#define log_normal(format, ...) log(NORMAL, "%s: " format, childobj, ##__VA_ARGS__)