summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/add.c36
-rw-r--r--lib/libalpm/alpm.h3
-rw-r--r--lib/libalpm/log.c17
-rw-r--r--lib/libalpm/log.h2
-rw-r--r--lib/libalpm/remove.c10
-rw-r--r--lib/libalpm/util.c13
-rw-r--r--lib/libalpm/util.h2
7 files changed, 46 insertions, 37 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 57c93004..9b678136 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -121,7 +121,8 @@ static int perform_extraction(alpm_handle_t *handle, struct archive *archive,
} else if(ret != ARCHIVE_OK) {
_alpm_log(handle, ALPM_LOG_ERROR, _("could not extract %s (%s)\n"),
origname, archive_error_string(archive));
- alpm_logaction(handle, "error: could not extract %s (%s)\n",
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "error: could not extract %s (%s)\n",
origname, archive_error_string(archive));
return 1;
}
@@ -133,8 +134,8 @@ static int try_rename(alpm_handle_t *handle, const char *src, const char *dest)
if(rename(src, dest)) {
_alpm_log(handle, ALPM_LOG_ERROR, _("could not rename %s to %s (%s)\n"),
src, dest, strerror(errno));
- alpm_logaction(handle, "error: could not rename %s to %s (%s)\n",
- src, dest, strerror(errno));
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "error: could not rename %s to %s (%s)\n", src, dest, strerror(errno));
return 1;
}
return 0;
@@ -184,8 +185,8 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
if(alpm_list_find(handle->noextract, entryname, _alpm_fnmatch)) {
_alpm_log(handle, ALPM_LOG_DEBUG, "%s is in NoExtract, skipping extraction\n",
entryname);
- alpm_logaction(handle, "note: %s is in NoExtract, skipping extraction\n",
- entryname);
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "note: %s is in NoExtract, skipping extraction\n", entryname);
archive_read_data_skip(archive);
return 0;
}
@@ -224,7 +225,8 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
_alpm_log(handle, ALPM_LOG_WARNING, _("directory permissions differ on %s\n"
"filesystem: %o package: %o\n"), entryname, lsbuf.st_mode & mask,
entrymode & mask);
- alpm_logaction(handle, "warning: directory permissions differ on %s\n"
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "warning: directory permissions differ on %s\n"
"filesystem: %o package: %o\n", entryname, lsbuf.st_mode & mask,
entrymode & mask);
}
@@ -348,7 +350,8 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
errors++;
} else {
_alpm_log(handle, ALPM_LOG_WARNING, _("%s saved as %s\n"), filename, newpath);
- alpm_logaction(handle, "warning: %s saved as %s\n", filename, newpath);
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "warning: %s saved as %s\n", filename, newpath);
}
}
free(newpath);
@@ -399,8 +402,8 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
} else {
_alpm_log(handle, ALPM_LOG_WARNING, _("%s installed as %s\n"),
filename, newpath);
- alpm_logaction(handle, "warning: %s installed as %s\n",
- filename, newpath);
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "warning: %s installed as %s\n", filename, newpath);
}
free(newpath);
}
@@ -416,7 +419,8 @@ needbackup_cleanup:
/* change the path to a .pacnew extension */
_alpm_log(handle, ALPM_LOG_DEBUG, "%s is in NoUpgrade -- skipping\n", filename);
_alpm_log(handle, ALPM_LOG_WARNING, _("extracting %s as %s.pacnew\n"), filename, filename);
- alpm_logaction(handle, "warning: extracting %s as %s.pacnew\n", filename, filename);
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "warning: extracting %s as %s.pacnew\n", filename, filename);
strncat(filename, ".pacnew", PATH_MAX - strlen(filename));
} else {
_alpm_log(handle, ALPM_LOG_DEBUG, "extracting %s\n", filename);
@@ -518,7 +522,8 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
/* prepare directory for database entries so permission are correct after
changelog/install script installation (FS#12263) */
if(_alpm_local_db_prepare(db, newpkg)) {
- alpm_logaction(handle, "error: could not create database entry %s-%s\n",
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "error: could not create database entry %s-%s\n",
newpkg->name, newpkg->version);
handle->pm_errno = ALPM_ERR_DB_WRITE;
ret = -1;
@@ -609,12 +614,14 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
if(is_upgrade) {
_alpm_log(handle, ALPM_LOG_ERROR, _("problem occurred while upgrading %s\n"),
newpkg->name);
- alpm_logaction(handle, "error: problem occurred while upgrading %s\n",
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "error: problem occurred while upgrading %s\n",
newpkg->name);
} else {
_alpm_log(handle, ALPM_LOG_ERROR, _("problem occurred while installing %s\n"),
newpkg->name);
- alpm_logaction(handle, "error: problem occurred while installing %s\n",
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "error: problem occurred while installing %s\n",
newpkg->name);
}
}
@@ -629,7 +636,8 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
if(_alpm_local_db_write(db, newpkg, INFRQ_ALL)) {
_alpm_log(handle, ALPM_LOG_ERROR, _("could not update database entry %s-%s\n"),
newpkg->name, newpkg->version);
- alpm_logaction(handle, "error: could not update database entry %s-%s\n",
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "error: could not update database entry %s-%s\n",
newpkg->name, newpkg->version);
handle->pm_errno = ALPM_ERR_DB_WRITE;
ret = -1;
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 6e8c93db..f524c190 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -268,7 +268,8 @@ typedef enum _alpm_loglevel_t {
} alpm_loglevel_t;
typedef void (*alpm_cb_log)(alpm_loglevel_t, const char *, va_list);
-int alpm_logaction(alpm_handle_t *handle, const char *fmt, ...);
+int alpm_logaction(alpm_handle_t *handle, const char *prefix,
+ const char *fmt, ...);
/**
* Events.
diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c
index 74143fdf..a8639b4c 100644
--- a/lib/libalpm/log.c
+++ b/lib/libalpm/log.c
@@ -35,10 +35,12 @@
/** A printf-like function for logging.
* @param handle the context handle
+ * @param prefix caller-specific prefix for the log
* @param fmt output format
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int SYMEXPORT alpm_logaction(alpm_handle_t *handle, const char *fmt, ...)
+int SYMEXPORT alpm_logaction(alpm_handle_t *handle, const char *prefix, const
+ char *fmt, ...)
{
int ret;
va_list args;
@@ -62,20 +64,9 @@ int SYMEXPORT alpm_logaction(alpm_handle_t *handle, const char *fmt, ...)
}
va_start(args, fmt);
- ret = _alpm_logaction(handle, fmt, args);
+ ret = _alpm_logaction(handle, prefix, fmt, args);
va_end(args);
- /* TODO We should add a prefix to log strings depending on who called us.
- * If logaction was called by the frontend:
- * USER: <the frontend log>
- * and if called internally:
- * ALPM: <the library log>
- * Moreover, the frontend should be able to choose its prefix
- * (USER by default?):
- * pacman: "PACMAN"
- * kpacman: "KPACMAN"
- * This would allow us to share the log file between several frontends
- * and know who does what */
return ret;
}
diff --git a/lib/libalpm/log.h b/lib/libalpm/log.h
index b44ea186..dd60c859 100644
--- a/lib/libalpm/log.h
+++ b/lib/libalpm/log.h
@@ -22,6 +22,8 @@
#include "alpm.h"
+#define ALPM_CALLER_PREFIX "ALPM"
+
void _alpm_log(alpm_handle_t *handle, alpm_loglevel_t flag,
const char *fmt, ...) __attribute__((format(printf,3,4)));
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index cdc572d9..50fc93ca 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -479,13 +479,15 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *oldpkg,
if(rename(file, newpath)) {
_alpm_log(handle, ALPM_LOG_ERROR, _("could not rename %s to %s (%s)\n"),
file, newpath, strerror(errno));
- alpm_logaction(handle, "error: could not rename %s to %s (%s)\n",
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "error: could not rename %s to %s (%s)\n",
file, newpath, strerror(errno));
free(newpath);
return -1;
}
_alpm_log(handle, ALPM_LOG_WARNING, _("%s saved as %s\n"), file, newpath);
- alpm_logaction(handle, "warning: %s saved as %s\n", file, newpath);
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "warning: %s saved as %s\n", file, newpath);
free(newpath);
return 0;
}
@@ -497,8 +499,8 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *oldpkg,
if(unlink(file) == -1) {
_alpm_log(handle, ALPM_LOG_ERROR, _("cannot remove %s (%s)\n"),
file, strerror(errno));
- alpm_logaction(handle, "error: cannot remove %s (%s)\n",
- file, strerror(errno));
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "error: cannot remove %s (%s)\n", file, strerror(errno));
return -1;
}
}
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);
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index 3a6b14af..93b65730 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -120,7 +120,7 @@ int _alpm_unpack(alpm_handle_t *handle, const char *archive, const char *prefix,
alpm_list_t *list, int breakfirst);
ssize_t _alpm_files_in_directory(alpm_handle_t *handle, const char *path, int full_count);
-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 _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[]);
int _alpm_ldconfig(alpm_handle_t *handle);
int _alpm_str_cmp(const void *s1, const void *s2);