-
Notifications
You must be signed in to change notification settings - Fork 148
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
logrotate: update the logdir path whenever it changes #501
base: main
Are you sure you want to change the base?
Conversation
83b39e9
to
a10f8a6
Compare
@mikechristie @pkalever |
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.
@lxbsz please take a look. Thanks!
} | ||
|
||
p += m; | ||
} |
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.
did you miss to free(line) in the loop ?
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.
No needed to free it every time:
If *lineptr is NULL, then getline() will allocate a buffer for storing the line, which should be freed by the user program. (In this case, the value in *n is
ignored.)
Alternatively, before calling getline(), *lineptr can contain a pointer to a malloc(3)-allocated buffer *n bytes in size. If the buffer is not large enough to
hold the line, getline() resizes it with realloc(3), updating *lineptr and *n as necessary.
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.
Yeah, I read the manpage now. Thanks for adding the clarity.
libtcmu_log.c
Outdated
return -errno; | ||
} | ||
|
||
ret = fseek(fp,0L,SEEK_END); |
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.
coding style: space after comma
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.
Will fix it.
@@ -524,6 +525,75 @@ static bool tcmu_log_dir_check(const char *path) | |||
return true; | |||
} | |||
|
|||
#define TCMU_LOGROTATE_PATH "/etc/logrotate.d/tcmu-runner" |
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.
Should this be part of a header file ?
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.
Currently, only used here. IMO, both will be okay.
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.
Oh yes, this is perfectly okay.
My intention was, considering declaration of potentially common macros (such as this) in headers will reduce rework.
libtcmu_log.c
Outdated
fp = fopen(TCMU_LOGROTATE_PATH, "r+"); | ||
if (fp == NULL) { | ||
tcmu_err("Failed to open file '%s', %m\n", TCMU_LOGROTATE_PATH); | ||
return -errno; |
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 need to save errno before line 539 and then return it.
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.
Will fix it.
ret = fseek(fp,0L,SEEK_END); | ||
if (ret == -1) { | ||
tcmu_err("Failed to seek file '%s', %m\n", TCMU_LOGROTATE_PATH); | ||
ret = -errno; |
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 should be moved before line 545
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.
Yeah. Will fix it
len = ftell(fp); | ||
if (len == -1) { | ||
tcmu_err("Failed to get the length of file '%s', %m\n", TCMU_LOGROTATE_PATH); | ||
ret = -errno; |
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.
same here
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.
Will fix it.
a10f8a6
to
363d0aa
Compare
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.
Looks good to me. Thanks Xiubo!
@@ -524,6 +525,75 @@ static bool tcmu_log_dir_check(const char *path) | |||
return true; | |||
} | |||
|
|||
#define TCMU_LOGROTATE_PATH "/etc/logrotate.d/tcmu-runner" |
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.
Oh yes, this is perfectly okay.
My intention was, considering declaration of potentially common macros (such as this) in headers will reduce rework.
} | ||
|
||
p += m; | ||
} |
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.
Yeah, I read the manpage now. Thanks for adding the clarity.
Signed-off-by: Xiubo Li <xiubli@redhat.com>
363d0aa
to
5e6b5e0
Compare
@@ -536,7 +609,8 @@ static int tcmu_log_dir_set(const char *log_dir) | |||
|
|||
tcmu_log_dir_free(); | |||
tcmu_log_dir = new_dir; | |||
return 0; | |||
|
|||
return tcmu_logrotate_conf_set(tcmu_log_dir); |
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.
I think you need to put this call before we free the old and set the new tcmu_log_dir in case the call to tcmu_logrotate_conf_set fails. We then do not have to worry about unraveling what was done here.
Fixes: #500
Signed-off-by: Xiubo Li xiubli@redhat.com