From 66a9b5314123b3632cb90a4d37fd422a0f898568 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 18 Jan 2013 20:42:21 -0500 Subject: add caller prefix to alpm_logaction prefix defaults to "UNKOWN" if null or an empty string is provided. Signed-off-by: Andrew Gregory Signed-off-by: Allan McRae --- lib/libalpm/util.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib/libalpm/util.c') diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 7d9ee635..5960be6a 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -453,10 +453,15 @@ ssize_t _alpm_files_in_directory(alpm_handle_t *handle, const char *path, * @return 0 or number of characters written on success, vfprintf return value * on error */ -int _alpm_logaction(alpm_handle_t *handle, const char *fmt, va_list args) +int _alpm_logaction(alpm_handle_t *handle, const char *prefix, + const char *fmt, va_list args) { int ret = 0; + if(!(prefix && *prefix)) { + prefix = "UNKNOWN"; + } + if(handle->usesyslog) { /* we can't use a va_list more than once, so we need to copy it * so we can use the original when calling vfprintf below. */ @@ -474,9 +479,9 @@ int _alpm_logaction(alpm_handle_t *handle, const char *fmt, va_list args) tm = localtime(&t); /* Use ISO-8601 date format */ - fprintf(handle->logstream, "[%04d-%02d-%02d %02d:%02d] ", + fprintf(handle->logstream, "[%04d-%02d-%02d %02d:%02d] [%s] ", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, - tm->tm_hour, tm->tm_min); + tm->tm_hour, tm->tm_min, prefix); ret = vfprintf(handle->logstream, fmt, args); fflush(handle->logstream); } @@ -568,7 +573,7 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[]) char line[PATH_MAX]; if(fgets(line, PATH_MAX, pipe_file) == NULL) break; - alpm_logaction(handle, "%s", line); + alpm_logaction(handle, "ALPM-SCRIPTLET", "%s", line); EVENT(handle, ALPM_EVENT_SCRIPTLET_INFO, line, NULL); } fclose(pipe_file); -- cgit v1.2.3-24-g4f1b