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, log_name_by_id(buf_id));
syslog_critical_failure(err_message);
- write_to_log = __write_to_log_null;
- return;
+ goto failure;
}
log_fds[buf_id] = open(buffer_name, O_WRONLY);
}
- log_config_free(&conf);
-
if (log_fds[LOG_ID_MAIN] < 0) {
syslog_critical_failure("COULD NOT OPEN MAIN LOG");
- write_to_log = __write_to_log_null;
- return;
+ goto failure;
}
for (buf_id = 0; buf_id < LOG_ID_MAX; ++buf_id)
log_fds[buf_id] = log_fds[LOG_ID_MAIN];
write_to_log = __write_to_log_android;
+ goto cleanup;
+
+failure:
+ for (; buf_id >= 0; buf_id--) {
+ if (log_fds[buf_id] >= 0)
+ close(log_fds[buf_id]);
+ }
+ write_to_log = __write_to_log_null;
+
+cleanup:
+ log_config_free(&conf);
+ return;
}
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, log_name_by_id(buf_id));
syslog_critical_failure(err_message);
- write_to_log = __write_to_log_null;
- return;
+ goto failure;
}
log_fds[buf_id] = open(buffer_name, O_WRONLY);
}
- log_config_free(&conf);
-
if (log_fds[LOG_ID_MAIN] < 0) {
syslog_critical_failure("COULD NOT OPEN MAIN LOG");
- write_to_log = __write_to_log_null;
- return;
+ goto failure;
}
for (buf_id = 0; buf_id < LOG_ID_MAX; ++buf_id)
log_fds[buf_id] = log_fds[LOG_ID_MAIN];
write_to_log = __write_to_log_kmsg;
+ goto cleanup;
+
+failure:
+ for (; buf_id >= 0; buf_id--) {
+ if (log_fds[buf_id] >= 0)
+ close(log_fds[buf_id]);
+ }
+ write_to_log = __write_to_log_null;
+
+cleanup:
+ log_config_free(&conf);
+ return;
}
if (!conf_val) {
syslog_critical_failure("DLog config lacks the \"%s\" entry!");
write_to_log = __write_to_log_null;
+ log_config_free(&conf);
return;
}
snprintf(log_pipe_path[i], PATH_MAX, "%s", conf_val);
backend = log_config_get(&conf_etc, "backend");
if (!backend) {
printf("Error: there is no backend information\n");
- return 1;
+ goto cleanup;
}
if (opt.help) {
print_extended_help(backend);
- return 1;
+ goto cleanup;
}
conf = &conf_etc;
if (!strncmp(backend, "kmsg", sizeof("kmsg") + 1)) {
if (log_config_read_file(&conf_run, KMSG_CONFIG_PATH) < 0) {
printf("Error: cannot open the config file!\n");
- return 1;
+ goto cleanup;
}
/* keys existing only in the conf_run will be stored in the /run */
goto err_save;
} else {
printf("Error: invalid options\n");
- return 1;
+ goto cleanup;
}
+ log_config_free(&conf_run);
+ log_config_free(&conf_etc);
return 0;
err_save:
printf("Cannot save file\n");
- return 1;
+ goto cleanup;
err_entry:
printf("Entry not found\n");
+
+cleanup:
+ log_config_free(&conf_run);
+ log_config_free(&conf_etc);
return 1;
}
logs.data = (struct logger_entry**)calloc(sort_buffer_size, sizeof(struct logger_entry*));
if (!(logs.data)) {
printf("Failed to allocate sort buffer\n");
+ log_config_free(&conf);
return 1;
}
free(buffer_names[i]);
for (i = 0; i < files_cnt; ++i)
free(file_input_names[i]);
+ log_config_free(&conf);
return ret;
}
conf_value = log_config_get(&conf, "backend");
if (!conf_value) {
printf("Error: backend not defined\n");
+ log_config_free(&conf);
return 1;
}
l_file.fd = open(l_file.path, O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR);
if (l_file.fd < 0) {
printf("Failed to open %s", l_file.path);
+ log_config_free(&conf);
return 1;
}