diff options
author | Drew DeVault <sir@cmpwn.com> | 2021-02-14 10:01:02 -0500 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2021-03-19 12:26:15 +0000 |
commit | 646c834492a419a96b4032c230e842d27f87e997 (patch) | |
tree | f3b78584924624dc73c8ec909f7dc8d685a84db0 /src/context.c | |
parent | 4fe5ac83287678a5f870def74ed28f45ab22815f (diff) | |
download | apk-tools-646c834492a419a96b4032c230e842d27f87e997.tar.gz apk-tools-646c834492a419a96b4032c230e842d27f87e997.tar.bz2 apk-tools-646c834492a419a96b4032c230e842d27f87e997.tar.xz apk-tools-646c834492a419a96b4032c230e842d27f87e997.zip |
Log to /var/log/apk.log
This adds a log file at /var/log/apk.log. On each run, apk's version
information and the current date & time are written to this file,
followed by any normal apk output.
Diffstat (limited to 'src/context.c')
-rw-r--r-- | src/context.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/context.c b/src/context.c index a6d7e5d..32a284e 100644 --- a/src/context.c +++ b/src/context.c @@ -29,6 +29,7 @@ void apk_ctx_free(struct apk_ctx *ac) apk_trust_free(&ac->trust); apk_string_array_free(&ac->repository_list); apk_string_array_free(&ac->private_keys); + if (ac->out.log) fclose(ac->out.log); } int apk_ctx_prepare(struct apk_ctx *ac) @@ -53,6 +54,21 @@ int apk_ctx_prepare(struct apk_ctx *ac) apk_err(&ac->out, "Unable to open root: %s", apk_error_str(errno)); return -errno; } + + if (ac->open_flags & APK_OPENF_WRITE) { + const char *log_path = "var/log/apk.log", *log_dir = "var/log"; + const int lflags = O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC; + int fd = openat(ac->root_fd, log_path, lflags, 0644); + if (fd < 0 && (ac->open_flags & APK_OPENF_CREATE)) { + mkdirat(ac->root_fd, log_dir, 0755); + fd = openat(ac->root_fd, log_path, lflags, 0644); + } + if (fd < 0) { + apk_err(&ac->out, "Unable to open log: %s", apk_error_str(errno)); + return -errno; + } + ac->out.log = fdopen(fd, "a"); + } return 0; } |