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

logrotate: update the logdir path whenever it changes #501

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

Conversation

lxbsz
Copy link
Collaborator

@lxbsz lxbsz commented Nov 21, 2018

Fixes: #500

Signed-off-by: Xiubo Li [email protected]

@lxbsz
Copy link
Collaborator Author

lxbsz commented Nov 21, 2018

@mikechristie @pkalever
Please review, Thanks.

Copy link
Contributor

@pkalever pkalever left a 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;
}
Copy link
Contributor

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 ?

Copy link
Collaborator Author

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.

Copy link
Contributor

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

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

Copy link
Collaborator Author

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

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 ?

Copy link
Collaborator Author

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.

Copy link
Contributor

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

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.

Copy link
Collaborator Author

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

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

Copy link
Collaborator Author

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix it.

Copy link
Contributor

@pkalever pkalever left a 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"
Copy link
Contributor

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

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.

@@ -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);
Copy link
Collaborator

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.

@lxbsz lxbsz changed the base branch from master to main August 10, 2022 00:23
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.

3 participants