alpm_logaction: implement documented return value
"return 0 on success, -1 on error (pm_errno is set accordingly)" Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
1545a04253
commit
9a9e0203de
1 changed files with 16 additions and 8 deletions
|
@ -34,6 +34,17 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static int _alpm_log_leader(FILE *f, const char *prefix)
|
||||||
|
{
|
||||||
|
time_t t = time(NULL);
|
||||||
|
struct tm *tm = localtime(&t);
|
||||||
|
|
||||||
|
/* Use ISO-8601 date format */
|
||||||
|
return fprintf(f, "[%04d-%02d-%02d %02d:%02d] [%s] ",
|
||||||
|
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
||||||
|
tm->tm_hour, tm->tm_min, prefix);
|
||||||
|
}
|
||||||
|
|
||||||
/** A printf-like function for logging.
|
/** A printf-like function for logging.
|
||||||
* @param handle the context handle
|
* @param handle the context handle
|
||||||
* @param prefix caller-specific prefix for the log
|
* @param prefix caller-specific prefix for the log
|
||||||
|
@ -84,14 +95,11 @@ int SYMEXPORT alpm_logaction(alpm_handle_t *handle, const char *prefix,
|
||||||
}
|
}
|
||||||
|
|
||||||
if(handle->logstream) {
|
if(handle->logstream) {
|
||||||
time_t t = time(NULL);
|
if(_alpm_log_leader(handle->logstream, prefix) < 0
|
||||||
struct tm *tm = localtime(&t);
|
|| vfprintf(handle->logstream, fmt, args) < 0) {
|
||||||
|
ret = -1;
|
||||||
/* Use ISO-8601 date format */
|
handle->pm_errno = ALPM_ERR_SYSTEM;
|
||||||
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, prefix);
|
|
||||||
ret = vfprintf(handle->logstream, fmt, args);
|
|
||||||
fflush(handle->logstream);
|
fflush(handle->logstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue