Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rashchupkinr
Copy link
Collaborator

No description provided.

ret = -1;
if (rv == -2)
ret = rv;
if (rv == -2) {
Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Collaborator Author

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
Copy link
Contributor

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 */

ret = kpatch_process_attach(o->proc);
if (ret == ERROR_ACCESS)
return ret;
Copy link
Contributor

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
Copy link
Contributor

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.

@@ -960,7 +966,7 @@ int main(int argc, char *argv[])
log_level += 1;
break;
case 'h':
return usage(NULL);
return usage(ERROR_SUCCESS);
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants