mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-16 21:29:59 +01:00
Use fixed buffer in log function.
And unify EOL for error and verbose messages.
This commit is contained in:
@@ -76,17 +76,23 @@ void check_signal(int *r)
|
||||
*r = -EINTR;
|
||||
}
|
||||
|
||||
#define LOG_MAX_LEN 4096
|
||||
|
||||
__attribute__((format(printf, 5, 6)))
|
||||
void clogger(struct crypt_device *cd, int level, const char *file, int line,
|
||||
const char *format, ...)
|
||||
{
|
||||
va_list argp;
|
||||
char *target = NULL;
|
||||
char target[LOG_MAX_LEN + 2];
|
||||
|
||||
va_start(argp, format);
|
||||
|
||||
if (vasprintf(&target, format, argp) > 0) {
|
||||
if (vsnprintf(&target[0], LOG_MAX_LEN, format, argp) > 0) {
|
||||
if (level >= 0) {
|
||||
/* All verbose and error messages in tools end with EOL. */
|
||||
if (level == CRYPT_LOG_VERBOSE || level == CRYPT_LOG_ERROR)
|
||||
strncat(target, "\n", LOG_MAX_LEN);
|
||||
|
||||
crypt_log(cd, level, target);
|
||||
#ifdef CRYPT_DEBUG
|
||||
} else if (opt_debug)
|
||||
@@ -98,11 +104,6 @@ void clogger(struct crypt_device *cd, int level, const char *file, int line,
|
||||
}
|
||||
|
||||
va_end(argp);
|
||||
free(target);
|
||||
|
||||
/* All verbose and error messages in tools end with EOL. */
|
||||
if (level == CRYPT_LOG_VERBOSE || level == CRYPT_LOG_ERROR)
|
||||
crypt_log(cd, level, "\n");
|
||||
}
|
||||
|
||||
void tool_log(int level, const char *msg, void *usrptr __attribute__((unused)))
|
||||
|
||||
Reference in New Issue
Block a user