00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "config.h"
00021
00022 #include <stdio.h>
00023 #include <stdarg.h>
00024 #include <sys/types.h>
00025 #include <sys/stat.h>
00026 #include <errno.h>
00027 #include <time.h>
00028
00029
00030 #include "log.h"
00031 #include "handle.h"
00032 #include "util.h"
00033 #include "error.h"
00034 #include "alpm.h"
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 int SYMEXPORT alpm_logaction(char *fmt, ...)
00046 {
00047 int ret;
00048 va_list args;
00049
00050 ALPM_LOG_FUNC;
00051
00052
00053 ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
00054
00055
00056 if(handle->logstream == NULL) {
00057 handle->logstream = fopen(handle->logfile, "a");
00058
00059 if(handle->logstream == NULL) {
00060 if(errno == EACCES) {
00061 pm_errno = PM_ERR_BADPERMS;
00062 } else if(errno == ENOENT) {
00063 pm_errno = PM_ERR_NOT_A_DIR;
00064 } else {
00065 pm_errno = PM_ERR_SYSTEM;
00066 }
00067 return(-1);
00068 }
00069 }
00070
00071 va_start(args, fmt);
00072 ret = _alpm_logaction(handle->usesyslog, handle->logstream, fmt, args);
00073 va_end(args);
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 return(ret);
00087 }
00088
00089
00090
00091 void _alpm_log(pmloglevel_t flag, char *fmt, ...)
00092 {
00093 va_list args;
00094 alpm_cb_log logcb = alpm_option_get_logcb();
00095
00096 if(logcb == NULL) {
00097 return;
00098 }
00099
00100 va_start(args, fmt);
00101 logcb(flag, fmt, args);
00102 va_end(args);
00103 }
00104
00105