-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add error return codes to libcare-ctl. #40
base: master
Are you sure you want to change the base?
Conversation
src/kpatch_user.c
Outdated
ret = -1; | ||
if (rv == -2) | ||
ret = rv; | ||
if (rv == -2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rv=-1
is used to indicate that we found what we have been looking for. Please rename that to some define or constant and restore the old behavior.
@@ -480,11 +484,11 @@ kpatch_apply_patches(kpatch_process_t *proc) | |||
* TODO(pboldin): close the holes so the state is the same | |||
* after unpatch | |||
*/ | |||
ret = object_unapply_patch(o, /* check_flag */ 1); | |||
if (ret < 0) { | |||
if (object_unapply_patch(o, /* check_flag */ 1) < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, don't hesitate to use more lines. There is no need to short it like this, let's keep the code a single statement a line and let compiler do its job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way value of 'ret' is not changed if object_unapply_patch was successful, and error code from object_apply_patch is returned. If object_unapply_patch returns error, ERROR_PATCH_UNPATCH will be returned to notify user.
src/kpatch_log.h
Outdated
@@ -3,6 +3,18 @@ | |||
|
|||
#include <stdio.h> | |||
|
|||
#define ERROR_SUCCESS 0 // exit code 0 | |||
#define ERROR_GENERAL -255 // exit code 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's introduce a macro named ERR_CODE(x) (x - 256)
.
and use it here. For instance:
#define ERROR_GENERAL ERR_CODE(1) /* general error */
src/kpatch_patch.c
Outdated
ret = kpatch_process_attach(o->proc); | ||
if (ret == ERROR_ACCESS) | ||
return ret; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't free retips
.
src/kpatch_log.h
Outdated
#define ERROR_NOPATCH -251 // exit code 5 | ||
#define ERROR_PATCH -250 // exit code 6 | ||
#define ERROR_UNPATCH -249 // exit code 7 | ||
#define ERROR_PATCH_UNPATCH -248 // exit code 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name is ambiguous. Please provide comments for all the error codes as shown above. We will later include these into man page.
src/kpatch_user.c
Outdated
@@ -960,7 +966,7 @@ int main(int argc, char *argv[]) | |||
log_level += 1; | |||
break; | |||
case 'h': | |||
return usage(NULL); | |||
return usage(ERROR_SUCCESS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The NULL here is the message usage
should print.
fb4cd74
to
52cd14b
Compare
No description provided.