mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-12 03:10:08 +01:00
Move clogger to libcryptsetup_cli crypt_cli_logger.
This commit is contained in:
committed by
Milan Broz
parent
cf2e099087
commit
cfcc908cae
@@ -39,11 +39,6 @@
|
|||||||
#include "libcryptsetup_cli.h"
|
#include "libcryptsetup_cli.h"
|
||||||
#include "cli_internal.h"
|
#include "cli_internal.h"
|
||||||
|
|
||||||
#define log_dbg(x...) clogger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
|
|
||||||
#define log_std(x...) clogger(NULL, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
|
|
||||||
#define log_verbose(x...) clogger(NULL, CRYPT_LOG_VERBOSE, __FILE__, __LINE__, x)
|
|
||||||
#define log_err(x...) clogger(NULL, CRYPT_LOG_ERROR, __FILE__, __LINE__, x)
|
|
||||||
|
|
||||||
#define LOG_MAX_LEN 4096
|
#define LOG_MAX_LEN 4096
|
||||||
|
|
||||||
/* Password reading helpers */
|
/* Password reading helpers */
|
||||||
@@ -422,3 +417,24 @@ bool crypt_cli_arg_set(struct crypt_cli *ctx, const char *name)
|
|||||||
|
|
||||||
return arg->set;
|
return arg->set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((format(printf, 5, 6)))
|
||||||
|
void crypt_cli_logger(struct crypt_device *cd, int level, const char *file, int line,
|
||||||
|
const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list argp;
|
||||||
|
char target[LOG_MAX_LEN + 2];
|
||||||
|
|
||||||
|
va_start(argp, format);
|
||||||
|
|
||||||
|
if (vsnprintf(&target[0], LOG_MAX_LEN, format, argp) > 0) {
|
||||||
|
/* All verbose and error messages in tools end with EOL. */
|
||||||
|
if (level == CRYPT_LOG_VERBOSE || level == CRYPT_LOG_ERROR || level == CRYPT_LOG_DEBUG ||
|
||||||
|
level == CRYPT_LOG_DEBUG_JSON)
|
||||||
|
strncat(target, "\n", LOG_MAX_LEN);
|
||||||
|
|
||||||
|
crypt_log(cd, level, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(argp);
|
||||||
|
}
|
||||||
|
|||||||
@@ -56,6 +56,15 @@ int crypt_cli_arg_value(struct crypt_cli *ctx, const char *name, void *value);
|
|||||||
|
|
||||||
int crypt_cli_arg_type(struct crypt_cli *ctx, const char *name, crypt_arg_type_info *type);
|
int crypt_cli_arg_type(struct crypt_cli *ctx, const char *name, crypt_arg_type_info *type);
|
||||||
|
|
||||||
|
void crypt_cli_logger(struct crypt_device *cd, int level, const char *file, int line,
|
||||||
|
const char *format, ...);
|
||||||
|
|
||||||
|
/* Log */
|
||||||
|
#define log_dbg(x...) crypt_cli_logger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
|
||||||
|
#define log_std(x...) crypt_cli_logger(NULL, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
|
||||||
|
#define log_verbose(x...) crypt_cli_logger(NULL, CRYPT_LOG_VERBOSE, __FILE__, __LINE__, x)
|
||||||
|
#define log_err(x...) crypt_cli_logger(NULL, CRYPT_LOG_ERROR, __FILE__, __LINE__, x)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ CRYPTSETUP_CLI_1.0 {
|
|||||||
crypt_cli_arg_set;
|
crypt_cli_arg_set;
|
||||||
crypt_cli_arg_type;
|
crypt_cli_arg_type;
|
||||||
crypt_cli_arg_value;
|
crypt_cli_arg_value;
|
||||||
|
crypt_cli_logger;
|
||||||
local:
|
local:
|
||||||
*;
|
*;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -71,8 +71,6 @@ extern int opt_batch_mode;
|
|||||||
extern int opt_progress_frequency;
|
extern int opt_progress_frequency;
|
||||||
|
|
||||||
/* Common tools */
|
/* Common tools */
|
||||||
void clogger(struct crypt_device *cd, int level, const char *file, int line,
|
|
||||||
const char *format, ...) __attribute__ ((format (printf, 5, 6)));
|
|
||||||
void tool_log(int level, const char *msg, void *usrptr __attribute__((unused)));
|
void tool_log(int level, const char *msg, void *usrptr __attribute__((unused)));
|
||||||
void quiet_log(int level, const char *msg, void *usrptr);
|
void quiet_log(int level, const char *msg, void *usrptr);
|
||||||
|
|
||||||
@@ -129,10 +127,4 @@ void tools_cleanup(void);
|
|||||||
|
|
||||||
#define FREE_AND_NULL(x) do { free(x); x = NULL; } while (0)
|
#define FREE_AND_NULL(x) do { free(x); x = NULL; } while (0)
|
||||||
|
|
||||||
/* Log */
|
|
||||||
#define log_dbg(x...) clogger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
|
|
||||||
#define log_std(x...) clogger(NULL, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
|
|
||||||
#define log_verbose(x...) clogger(NULL, CRYPT_LOG_VERBOSE, __FILE__, __LINE__, x)
|
|
||||||
#define log_err(x...) clogger(NULL, CRYPT_LOG_ERROR, __FILE__, __LINE__, x)
|
|
||||||
|
|
||||||
#endif /* CRYPTSETUP_H */
|
#endif /* CRYPTSETUP_H */
|
||||||
|
|||||||
@@ -77,29 +77,6 @@ void check_signal(int *r)
|
|||||||
*r = -EINTR;
|
*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[LOG_MAX_LEN + 2];
|
|
||||||
|
|
||||||
va_start(argp, format);
|
|
||||||
|
|
||||||
if (vsnprintf(&target[0], LOG_MAX_LEN, format, argp) > 0) {
|
|
||||||
/* All verbose and error messages in tools end with EOL. */
|
|
||||||
if (level == CRYPT_LOG_VERBOSE || level == CRYPT_LOG_ERROR ||
|
|
||||||
level == CRYPT_LOG_DEBUG || level == CRYPT_LOG_DEBUG_JSON)
|
|
||||||
strncat(target, "\n", LOG_MAX_LEN);
|
|
||||||
|
|
||||||
crypt_log(cd, level, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
va_end(argp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tool_log(int level, const char *msg, void *usrptr __attribute__((unused)))
|
void tool_log(int level, const char *msg, void *usrptr __attribute__((unused)))
|
||||||
{
|
{
|
||||||
switch(level) {
|
switch(level) {
|
||||||
|
|||||||
Reference in New Issue
Block a user