# HG changeset patch # User Olaf Wintermann # Date 1689880579 -7200 # Node ID 3cfe65695a8c6c8ad13e3594d4568fa1cb775dd4 # Parent 08d887af39714e14a5380db7d6f08d6d2732f0f7 open logfile in relevant dav-sync commands diff -r 08d887af3971 -r 3cfe65695a8c dav/sync.c --- a/dav/sync.c Wed Jul 19 20:48:20 2023 +0200 +++ b/dav/sync.c Thu Jul 20 21:16:19 2023 +0200 @@ -105,6 +105,43 @@ va_end(ap); } +void log_error(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + cxmutstr str = cx_vasprintf(fmt, ap); + + fprintf(stderr, "%s", str.ptr); + if(synclog) { + fprintf(synclog, "%s", str.ptr); + } + free(str.ptr); + + va_end(ap); +} + + +int logfile_open(SyncDirectory *dir) { + int ret = 0; + if(dir && dir->logfile) { + char *lf_path = dir->logfile; + char *lf_path_fr = NULL; + if(dir->logfile[0] != '/') { + lf_path = config_file_path(dir->logfile); + lf_path_fr = lf_path; + } + + synclog = fopen(lf_path, "a"); + if(!synclog) { + fprintf(stderr, "Cannot open logfile %s: %s\n", lf_path, strerror(errno)); + ret = 1; + } + if(lf_path_fr) { + free(lf_path_fr); + } + } + return ret; +} + /* * strcmp version that works with NULL pointers */ @@ -625,6 +662,9 @@ if(scfg_check_dir(dir)) { return -1; } + if(logfile_open(dir)) { + return -1; + } if((dir->allow_cmd & SYNC_CMD_PULL) != SYNC_CMD_PULL) { fprintf(stderr, "Command 'pull' is not allowed for this sync dir\n"); @@ -1952,6 +1992,9 @@ if(scfg_check_dir(dir)) { return -1; } + if(logfile_open(dir)) { + return -1; + } if(cmd_getoption(a, "snapshot")) { if(dir->versioning) { dir->versioning->always = TRUE; @@ -2541,6 +2584,9 @@ if(syncdir) { dir = scfg_get_dir(syncdir); } + if(logfile_open(dir)) { + return -1; + } LocalResource nres; if(a->argc > 0) { @@ -4757,6 +4803,9 @@ if(scfg_check_dir(dir)) { return -1; } + if(logfile_open(dir)) { + return -1; + } SyncDatabase *db = load_db(dir->database); if(!db) { @@ -4806,6 +4855,9 @@ if(scfg_check_dir(dir)) { return -1; } + if(logfile_open(dir)) { + return -1; + } SyncDatabase *db = load_db(dir->database); if(!db) { @@ -5178,6 +5230,9 @@ fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]); return -1; } + if(logfile_open(syncdir)) { + return -1; + } if(!syncdir->trash) { fprintf(stderr, "trash not configured for %s\n", syncdir->name);