summaryrefslogtreecommitdiff
path: root/lib/libalpm/log.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-11-04 16:38:59 -0600
committerDan McGee <dan@archlinux.org>2007-11-04 16:38:59 -0600
commit99f42d6bd2116b0bd8f75394fe92255ca1f4c80b (patch)
tree806ee6eed7631f8f31ee8dcba1848617307d0955 /lib/libalpm/log.c
parent86ca39d15e02dff47b5b0f5bcd0494cf101ce0c1 (diff)
downloadpacman-99f42d6bd2116b0bd8f75394fe92255ca1f4c80b.tar.xz
libalpm: open the logstream on demand
Don't open a stream to the logfile until necessary. This will allow us to catch any errors in opening the logfile instead of ignorning them. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/log.c')
-rw-r--r--lib/libalpm/log.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c
index f4564fc9..dd9540ed 100644
--- a/lib/libalpm/log.c
+++ b/lib/libalpm/log.c
@@ -23,6 +23,9 @@
#include <stdio.h>
#include <stdarg.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
#include <time.h>
/* libalpm */
@@ -51,6 +54,22 @@ int SYMEXPORT alpm_logaction(char *fmt, ...)
/* Sanity checks */
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ /* check if the logstream is open already, opening it if needed */
+ if(handle->logstream == NULL) {
+ handle->logstream = fopen(handle->logfile, "a");
+ /* if we couldn't open it, we have an issue */
+ if(handle->logstream == NULL) {
+ if(errno == EACCES) {
+ pm_errno = PM_ERR_BADPERMS;
+ } else if(errno == ENOENT) {
+ pm_errno = PM_ERR_NOT_A_DIR;
+ } else {
+ pm_errno = PM_ERR_SYSTEM;
+ }
+ return(-1);
+ }
+ }
+
va_start(args, fmt);
ret = _alpm_logaction(handle->usesyslog, handle->logstream, fmt, args);
va_end(args);