2014-03-02 00:06:35 +01:00
|
|
|
/* log.c
|
2014-02-26 07:51:06 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Toxic All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This file is part of Toxic.
|
|
|
|
*
|
|
|
|
* Toxic is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Toxic is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Toxic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-09-22 10:29:28 +02:00
|
|
|
#include <sys/stat.h>
|
2020-04-18 02:00:00 +02:00
|
|
|
#include <time.h>
|
2014-02-26 07:51:06 +01:00
|
|
|
|
|
|
|
#include "configdir.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "line_info.h"
|
2014-03-25 13:25:10 +01:00
|
|
|
#include "log.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "misc_tools.h"
|
2014-04-07 10:42:10 +02:00
|
|
|
#include "settings.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "toxic.h"
|
|
|
|
#include "windows.h"
|
2014-04-07 10:42:10 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
extern struct user_settings *user_settings;
|
2014-02-26 07:51:06 +01:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
/* Creates a log path and puts it in `dest.
|
|
|
|
*
|
|
|
|
* There are two types of logs: chat logs and prompt logs (see LOG_TYPE in log.h)
|
|
|
|
* A prompt log is in the format: LOGDIR/selfkey-home.log
|
|
|
|
* A chat log is in the format: LOGDIR/selfkey-name-otherkey.log
|
|
|
|
*
|
|
|
|
* For friend chats `otherkey` is the first 6 bytes of the friend's Tox ID.
|
|
|
|
* For Conferences/groups `otherkey` is the first 6 bytes of the group's unique ID.
|
|
|
|
*
|
|
|
|
* Return path length on success.
|
|
|
|
* Return -1 if the path is too long.
|
|
|
|
*/
|
|
|
|
static int get_log_path(char *dest, int destsize, const char *name, const char *selfkey, const char *otherkey)
|
2014-09-27 08:28:11 +02:00
|
|
|
{
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!valid_nick(name)) {
|
2014-04-12 09:39:15 +02:00
|
|
|
name = UNKNOWN_NAME;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-04-12 09:39:15 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
const char *namedash = otherkey ? "-" : "";
|
2014-09-23 03:24:45 +02:00
|
|
|
const char *set_path = user_settings->chatlogs_path;
|
2014-08-27 05:21:32 +02:00
|
|
|
|
2014-02-26 07:51:06 +01:00
|
|
|
char *user_config_dir = get_user_config_dir();
|
2014-09-22 23:09:39 +02:00
|
|
|
int path_len = strlen(name) + strlen(".log") + strlen("-") + strlen(namedash);
|
|
|
|
path_len += strlen(set_path) ? *set_path : strlen(user_config_dir) + strlen(LOGDIR);
|
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
/* first 6 bytes of selfkey */
|
|
|
|
char self_id[32] = {0};
|
2014-09-23 00:38:46 +02:00
|
|
|
path_len += KEY_IDENT_DIGITS * 2;
|
2014-09-22 23:09:39 +02:00
|
|
|
sprintf(&self_id[0], "%02X", selfkey[0] & 0xff);
|
|
|
|
sprintf(&self_id[2], "%02X", selfkey[1] & 0xff);
|
2014-09-22 23:34:30 +02:00
|
|
|
sprintf(&self_id[4], "%02X", selfkey[2] & 0xff);
|
2014-09-23 00:38:46 +02:00
|
|
|
self_id[KEY_IDENT_DIGITS * 2] = '\0';
|
2014-09-22 23:09:39 +02:00
|
|
|
|
|
|
|
char other_id[32] = {0};
|
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
if (otherkey) {
|
|
|
|
/* first 6 bytes of otherkey */
|
|
|
|
path_len += KEY_IDENT_DIGITS * 2;
|
|
|
|
sprintf(&other_id[0], "%02X", otherkey[0] & 0xff);
|
|
|
|
sprintf(&other_id[2], "%02X", otherkey[1] & 0xff);
|
|
|
|
sprintf(&other_id[4], "%02X", otherkey[2] & 0xff);
|
|
|
|
other_id[KEY_IDENT_DIGITS * 2] = '\0';
|
2014-02-26 23:15:34 +01:00
|
|
|
}
|
2014-02-26 07:51:06 +01:00
|
|
|
|
2014-09-27 08:28:11 +02:00
|
|
|
if (path_len >= destsize) {
|
2014-04-06 11:20:46 +02:00
|
|
|
free(user_config_dir);
|
2014-09-22 23:09:39 +02:00
|
|
|
return -1;
|
2014-02-26 23:15:34 +01:00
|
|
|
}
|
2014-02-26 07:51:06 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!string_is_empty(set_path)) {
|
2014-09-27 08:28:11 +02:00
|
|
|
snprintf(dest, destsize, "%s%s-%s%s%s.log", set_path, self_id, name, namedash, other_id);
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2014-09-27 08:28:11 +02:00
|
|
|
snprintf(dest, destsize, "%s%s%s-%s%s%s.log", user_config_dir, LOGDIR, self_id, name, namedash, other_id);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-02-26 07:51:06 +01:00
|
|
|
|
2014-04-06 11:20:46 +02:00
|
|
|
free(user_config_dir);
|
2014-09-27 08:28:11 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
return path_len;
|
2014-09-27 08:28:11 +02:00
|
|
|
}
|
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
/* Initializes log path for `log`.
|
|
|
|
*
|
|
|
|
* Return 0 on success.
|
|
|
|
* Return -1 on failure.
|
|
|
|
*/
|
|
|
|
static int init_logging_session(const char *name, const char *selfkey, const char *otherkey, struct chatlog *log,
|
|
|
|
LOG_TYPE type)
|
2014-09-27 08:28:11 +02:00
|
|
|
{
|
2020-11-17 22:05:20 +01:00
|
|
|
if (log == NULL) {
|
2014-09-27 08:28:11 +02:00
|
|
|
return -1;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-27 08:28:11 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
if (selfkey == NULL || (type == LOG_TYPE_CHAT && otherkey == NULL)) {
|
2014-09-27 08:28:11 +02:00
|
|
|
return -1;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-27 08:28:11 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
char log_path[MAX_STR_SIZE];
|
2014-02-26 07:51:06 +01:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
int path_len = get_log_path(log_path, sizeof(log_path), name, selfkey, otherkey);
|
|
|
|
|
|
|
|
if (path_len == -1 || path_len >= sizeof(log->path)) {
|
2014-09-22 23:09:39 +02:00
|
|
|
return -1;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-22 23:09:39 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
memcpy(log->path, log_path, path_len);
|
|
|
|
log->path[path_len] = 0;
|
|
|
|
|
2014-09-22 23:09:39 +02:00
|
|
|
return 0;
|
2014-02-26 07:51:06 +01:00
|
|
|
}
|
|
|
|
|
2014-09-11 07:36:33 +02:00
|
|
|
#define LOG_FLUSH_LIMIT 1 /* limits calls to fflush to a max of one per LOG_FLUSH_LIMIT seconds */
|
2014-09-10 22:18:37 +02:00
|
|
|
|
2014-07-29 20:54:34 +02:00
|
|
|
void write_to_log(const char *msg, const char *name, struct chatlog *log, bool event)
|
2014-02-26 07:51:06 +01:00
|
|
|
{
|
2020-11-17 22:05:20 +01:00
|
|
|
if (log == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!log->log_on) {
|
2014-02-26 07:51:06 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-02-26 07:51:06 +01:00
|
|
|
|
2014-03-04 01:21:52 +01:00
|
|
|
if (log->file == NULL) {
|
2014-03-01 13:10:44 +01:00
|
|
|
log->log_on = false;
|
2014-02-26 07:51:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char name_frmt[TOXIC_MAX_NAME_LENGTH + 3];
|
2014-02-26 12:35:19 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (event) {
|
2014-02-26 12:35:19 +01:00
|
|
|
snprintf(name_frmt, sizeof(name_frmt), "* %s", name);
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2014-02-26 12:35:19 +01:00
|
|
|
snprintf(name_frmt, sizeof(name_frmt), "%s:", name);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-02-26 12:35:19 +01:00
|
|
|
|
2015-02-20 00:20:38 +01:00
|
|
|
const char *t = user_settings->log_timestamp_format;
|
2014-07-07 04:15:35 +02:00
|
|
|
char s[MAX_STR_SIZE];
|
2014-04-07 10:42:10 +02:00
|
|
|
strftime(s, MAX_STR_SIZE, t, get_time());
|
2014-04-19 23:58:13 +02:00
|
|
|
fprintf(log->file, "%s %s %s\n", s, name_frmt, msg);
|
2014-03-04 01:21:52 +01:00
|
|
|
|
2015-08-18 07:46:22 +02:00
|
|
|
if (timed_out(log->lastwrite, LOG_FLUSH_LIMIT)) {
|
2014-03-04 01:21:52 +01:00
|
|
|
fflush(log->file);
|
2015-08-18 07:46:22 +02:00
|
|
|
log->lastwrite = get_unix_time();
|
2014-03-05 09:31:12 +01:00
|
|
|
}
|
2014-03-01 13:10:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void log_disable(struct chatlog *log)
|
|
|
|
{
|
2020-11-17 22:05:20 +01:00
|
|
|
if (log == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (log->file != NULL) {
|
2014-03-04 01:21:52 +01:00
|
|
|
fclose(log->file);
|
2020-11-17 22:05:20 +01:00
|
|
|
log->file = NULL;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-27 08:28:11 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
log->lastwrite = 0;
|
|
|
|
log->log_on = false;
|
2014-02-26 07:51:06 +01:00
|
|
|
}
|
2014-09-22 10:29:28 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
int log_enable(struct chatlog *log)
|
2014-09-22 23:09:39 +02:00
|
|
|
{
|
2020-11-17 22:05:20 +01:00
|
|
|
if (log == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
2014-09-22 23:09:39 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
if (log->log_on) {
|
2015-08-19 06:42:28 +02:00
|
|
|
return 0;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-27 08:28:11 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
if (*log->path == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log->file != NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
log->file = fopen(log->path, "a+");
|
|
|
|
|
|
|
|
if (log->file == NULL) {
|
2015-08-19 06:42:28 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
log->log_on = true;
|
|
|
|
|
2015-08-19 06:42:28 +02:00
|
|
|
return 0;
|
2014-09-22 23:09:39 +02:00
|
|
|
}
|
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
/* Initializes a log. This function must be called before any other logging operations.
|
|
|
|
*
|
|
|
|
* Return 0 on success.
|
|
|
|
* Return -1 on failure.
|
|
|
|
*/
|
|
|
|
int log_init(struct chatlog *log, const char *name, const char *selfkey, const char *otherkey, LOG_TYPE type)
|
2014-09-22 10:29:28 +02:00
|
|
|
{
|
2020-11-17 22:05:20 +01:00
|
|
|
if (log == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log->file != NULL || log->log_on) {
|
|
|
|
fprintf(stderr, "Warning: Called log_init() on an already initialized log\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (init_logging_session(name, selfkey, otherkey, log, type) == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
log_disable(log);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loads chat log history and prints it to `self` window.
|
|
|
|
*
|
|
|
|
* Return 0 on success or if log file doesn't exist.
|
|
|
|
* Return -1 on failure.
|
|
|
|
*/
|
|
|
|
int load_chat_history(ToxWindow *self, struct chatlog *log)
|
|
|
|
{
|
|
|
|
if (log == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*log->path == 0) {
|
|
|
|
return -1;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-22 10:29:28 +02:00
|
|
|
|
2014-09-24 20:23:08 +02:00
|
|
|
off_t sz = file_size(log->path);
|
2014-09-22 10:29:28 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (sz <= 0) {
|
2020-11-17 22:05:20 +01:00
|
|
|
return 0;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-22 10:29:28 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
FILE *fp = fopen(log->path, "r");
|
2014-09-22 10:29:28 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
if (fp == NULL) {
|
|
|
|
return -1;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-22 10:29:28 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
char *buf = malloc(sz + 1);
|
|
|
|
|
|
|
|
if (buf == NULL) {
|
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
2014-09-24 03:32:05 +02:00
|
|
|
}
|
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
if (fseek(fp, 0L, SEEK_SET) == -1) {
|
|
|
|
free(buf);
|
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
2014-09-22 10:29:28 +02:00
|
|
|
}
|
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
if (fread(buf, sz, 1, fp) != 1) {
|
|
|
|
free(buf);
|
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
buf[sz] = 0;
|
2015-08-27 09:38:08 +02:00
|
|
|
|
2014-09-22 10:29:28 +02:00
|
|
|
/* Number of history lines to load: must not be larger than MAX_LINE_INFO_QUEUE - 2 */
|
2014-09-23 03:24:45 +02:00
|
|
|
int L = MIN(MAX_LINE_INFO_QUEUE - 2, user_settings->history_size);
|
2020-11-17 22:05:20 +01:00
|
|
|
|
|
|
|
int start = 0;
|
|
|
|
int count = 0;
|
2014-09-22 10:29:28 +02:00
|
|
|
|
|
|
|
/* start at end and backtrace L lines or to the beginning of buffer */
|
|
|
|
for (start = sz - 1; start >= 0 && count < L; --start) {
|
2020-11-17 22:05:20 +01:00
|
|
|
if (buf[start] == '\n') {
|
2014-09-22 10:29:28 +02:00
|
|
|
++count;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-22 10:29:28 +02:00
|
|
|
}
|
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
char *tmp = NULL;
|
|
|
|
const char *line = strtok_r(&buf[start + 1], "\n", &tmp);
|
2014-09-22 10:29:28 +02:00
|
|
|
|
|
|
|
if (line == NULL) {
|
2020-11-17 22:05:20 +01:00
|
|
|
free(buf);
|
|
|
|
return -1;
|
2014-09-22 10:29:28 +02:00
|
|
|
}
|
|
|
|
|
2014-09-24 21:15:07 +02:00
|
|
|
while (line != NULL && count--) {
|
2014-09-22 19:49:09 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", line);
|
2020-11-17 22:05:20 +01:00
|
|
|
line = strtok_r(NULL, "\n", &tmp);
|
2014-09-22 10:29:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "");
|
2020-11-17 22:05:20 +01:00
|
|
|
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
return 0;
|
2014-09-22 10:29:28 +02:00
|
|
|
}
|
2014-09-27 08:28:11 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
/* Renames chatlog file `src` to `dest`.
|
|
|
|
*
|
|
|
|
* Return 0 on success or if no log exists.
|
|
|
|
* Return -1 on failure.
|
|
|
|
*/
|
|
|
|
int rename_logfile(const char *src, const char *dest, const char *selfkey, const char *otherkey, int winnum)
|
2014-09-27 08:28:11 +02:00
|
|
|
{
|
|
|
|
ToxWindow *toxwin = get_window_ptr(winnum);
|
|
|
|
struct chatlog *log = NULL;
|
|
|
|
bool log_on = false;
|
|
|
|
|
|
|
|
/* disable log if necessary and save its state */
|
|
|
|
if (toxwin != NULL) {
|
|
|
|
log = toxwin->chatwin->log;
|
2020-11-17 22:05:20 +01:00
|
|
|
|
|
|
|
if (log == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-09-27 08:28:11 +02:00
|
|
|
log_on = log->log_on;
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (log_on) {
|
2014-09-27 08:28:11 +02:00
|
|
|
log_disable(log);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-27 08:28:11 +02:00
|
|
|
|
|
|
|
char newpath[MAX_STR_SIZE];
|
|
|
|
char oldpath[MAX_STR_SIZE];
|
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
if (get_log_path(oldpath, sizeof(oldpath), src, selfkey, otherkey) == -1) {
|
2014-09-27 08:28:11 +02:00
|
|
|
goto on_error;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-27 08:28:11 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!file_exists(oldpath)) {
|
2020-11-17 22:05:20 +01:00
|
|
|
init_logging_session(dest, selfkey, otherkey, log, LOG_TYPE_CHAT); // still need to rename path
|
2014-09-27 08:28:11 +02:00
|
|
|
return 0;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-27 08:28:11 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
int new_path_len = get_log_path(newpath, sizeof(newpath), dest, selfkey, otherkey);
|
|
|
|
|
|
|
|
if (new_path_len == -1 || new_path_len >= MAX_STR_SIZE) {
|
2014-09-27 08:28:11 +02:00
|
|
|
goto on_error;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-27 08:28:11 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
if (file_exists(newpath)) {
|
2020-11-18 23:19:08 +01:00
|
|
|
char new_backup[MAX_STR_SIZE + 4];
|
|
|
|
snprintf(new_backup, sizeof(new_backup), "%s.old", newpath);
|
|
|
|
|
|
|
|
if (file_exists(new_backup)) {
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rename(newpath, new_backup) != 0) {
|
|
|
|
goto on_error;
|
2020-11-17 22:05:20 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (rename(oldpath, newpath) != 0) {
|
|
|
|
goto on_error;
|
|
|
|
}
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-27 08:28:11 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
if (log != NULL) {
|
|
|
|
memcpy(log->path, newpath, new_path_len);
|
|
|
|
log->path[new_path_len] = 0;
|
|
|
|
|
|
|
|
if (log_on) {
|
|
|
|
log_enable(log);
|
|
|
|
}
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-27 08:28:11 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
on_error:
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (log_on) {
|
2020-11-17 22:05:20 +01:00
|
|
|
log_enable(log);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-27 08:28:11 +02:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|