if (!buffer_name) {
char err_message[MAX_CONF_VAL_LEN + 64];
- snprintf(err_message, MAX_CONF_VAL_LEN + 64, "LOG BUFFER #%d %s HAS NO PATH SET IN CONFIG", buf_id, buffer_name);
+ snprintf(err_message, MAX_CONF_VAL_LEN + 64, "LOG BUFFER #%d %s HAS NO PATH SET IN CONFIG", buf_id, log_name_by_id(buf_id));
syslog_critical_failure(err_message);
write_to_log = __write_to_log_null;
return;
if (!buffer_name) {
char err_message[MAX_CONF_VAL_LEN + 64];
- snprintf(err_message, MAX_CONF_VAL_LEN + 64, "LOG BUFFER #%d %s HAS NO PATH SET IN CONFIG", buf_id, buffer_name);
+ snprintf(err_message, MAX_CONF_VAL_LEN + 64, "LOG BUFFER #%d %s HAS NO PATH SET IN CONFIG", buf_id, log_name_by_id(buf_id));
syslog_critical_failure(err_message);
write_to_log = __write_to_log_null;
return;
static int parse_command_line(const char* cmdl, struct logger* server, struct writer* wr)
{
char cmdline[512];
- int option, argc;
+ int option, argc = 0;
char *argv[ARG_MAX];
char *tok;
char *tok_sv;
struct reader * reader;
char const * conf_val;
- struct log_config conf;
+ struct log_config conf = {NULL, NULL};
if (!server || !cmdl) return EINVAL;
if (!reader) return ENOMEM;
tok = strtok_r(cmdline, DELIMITER, &tok_sv);
- if (!tok || strcmp(tok, "dlogutil")) return -1;
+ if (!tok || strcmp(tok, "dlogutil")) {
+ retval = -1;
+ goto cleanup;
+ }
- argc = 0;
while (tok && (argc < ARG_MAX)) {
argv[argc++] = strdup(tok);
tok = strtok_r(NULL, DELIMITER, &tok_sv);
reader->dumpcount = 0;
reader->partial_log_size = 0;
- log_config_read(&conf);
+ if (!log_config_read(&conf)) {
+ retval = -1;
+ goto cleanup;
+ }
+
conf_val = log_config_get(&conf, "backend");
+ if (!conf_val) {
+ retval = -1;
+ goto cleanup;
+ }
while ((option = getopt(argc, argv, "cdt:gsf:r:n:v:b:k")) != -1) {
switch (option) {
retval = -1;
goto cleanup;
}
- if ((conf_val && !strcmp(conf_val, "pipe")) || (optarg && !strcmp(optarg, "kmsg"))) {
+ if (!strcmp(conf_val, "pipe") || (optarg && !strcmp(optarg, "kmsg"))) {
reader->type = READER_BUFFER;
reader->buf_id = log_id_by_name(optarg);
} else {
- if (conf_val && !strcmp(conf_val, "logger"))
+ if (!strcmp(conf_val, "logger"))
reader->type = READER_LOGGER;
else
reader->type = READER_KMSG;
*/
static int logger_init(struct logger** server, struct log_config* config)
{
- int r = 0;
-
if (*server)
logger_free(*server);
- log_config_read(config);
+ if (!log_config_read(config))
+ return EINVAL;
*server = logger_create(config);
if (!(*server))
- r = EINVAL;
+ return EINVAL;
- return r;
+ return 0;
}
/**
struct log_config conf_out;
log_config_read(&conf_in);
+
memset(&conf_out, 0, sizeof(struct log_config));
kmsg_fd = open(DEV_KMSG, O_RDWR);
if (0 > create_kmsg_devs(kmsg_fd, &conf_in))
goto error;
+ log_config_free(&conf_in);
+
for (i = 0; i < LOG_ID_MAX; ++i) {
char key[MAX_CONF_KEY_LEN];
char val[MAX_CONF_VAL_LEN];
log_config_push(&conf_out, log_name_by_id(i), val);
}
- log_config_write(&conf_out, KMSG_CONFIG_PATH);
-
- return 0;
+ return !log_config_write(&conf_out, KMSG_CONFIG_PATH);
error:
remove_kmsg_devs(kmsg_fd);
{
const int size = sizeof(struct dlog_control_msg);
struct dlog_control_msg * const msg = calloc(1, size);
+ int ret = 1;
msg->length = size;
msg->request = DLOG_REQ_CLEAR;
msg->flags = 0;
if (write(sock_fd, msg, size) < 0) {
printf("Error: could not send a CLEAR request to logger; socket write failed\n");
- return 0;
+ ret = 0;
}
- return 1;
+ free(msg);
+ return ret;
}
char logger_request[MAX_LOGGER_REQUEST_LEN];
int logger_request_len = snprintf(logger_request, MAX_LOGGER_REQUEST_LEN, "dlogutil");
struct dlog_control_msg * msg;
- int i;
+ int i, ret = 1;
for (i = 1; i < argc; ++i)
logger_request_len += snprintf(logger_request + logger_request_len, MAX_LOGGER_REQUEST_LEN - logger_request_len, " %s", argv[i]);
memcpy(msg->data, logger_request, logger_request_len - sizeof(struct dlog_control_msg));
if (write(sock_fd, msg, logger_request_len) < 0) {
printf("Error: could not send a logger request; socket write failed\n");
- return 0;
+ ret = 0;
}
free(msg);
- return 1;
+ return ret;
}
/**
return 0;
backend = log_config_get(config, "backend");
- if (!backend)
+ if (!backend) {
+ log_config_free(config);
return 0;
+ }
if (!strncmp(backend, "kmsg", sizeof("kmsg") + 1))
log_config_read_file(config, KMSG_CONFIG_PATH);