[SSSD] [PATCH] sss_log: fix handling of variable argument lists
Sumit Bose
sbose at redhat.com
Wed Aug 27 12:44:44 UTC 2014
On Wed, Aug 27, 2014 at 12:06:54PM +0200, Lukas Slebodnik wrote:
> On (26/08/14 17:44), Sumit Bose wrote:
> >Hi,
> >
> >this patch fixes a issue with sss_log() which was introduced recently
> >and I think is only in master. So far I only tested it with syslog, if
> >would be nice if someone can test the journald code path as well.
> >
> >bye,
> >Sumit
>
> Nice catch.
> It needn't be noticed if message does not contain format strings.
>
> >From cb4a1788cc8d4fd4251de2ee83ff760b740a68d6 Mon Sep 17 00:00:00 2001
> >From: Sumit Bose <sbose at redhat.com>
> >Date: Tue, 26 Aug 2014 17:29:08 +0200
> >Subject: [PATCH] sss_log: fix handling of variable argument lists
> >
> >SSSD has two public calls to send messages to syslog sss_log() and
> >sss_log_ext() which both expect besides other arguments a printf format
> >string and a variable list of arguments depending on the format.
> >Currently sss_log() calls sss_log_ext() internally after calling
> >va_start(ap, format) and hands over ap as the last argument. This does
> >not work because there is a difference between a varying number of
> >arguments and a va_list type.
> >
> >To fix this I added a new private call which expects a va_list as the
> >last argument and is called by sss_log() and sss_log_ext() after calling
> >va_start().
> >---
> > src/util/sss_log.c | 28 +++++++++++++++++++---------
> > 1 file changed, 19 insertions(+), 9 deletions(-)
> >
> >diff --git a/src/util/sss_log.c b/src/util/sss_log.c
> >index 7a2dce6..b0c3f99 100644
> >--- a/src/util/sss_log.c
> >+++ b/src/util/sss_log.c
> >@@ -57,28 +57,40 @@ static int sss_to_syslog(int priority)
> > }
> > }
> >
> >+static void sss_log_ext_int(int priority, int facility, const char *format,
> >+ va_list ap);
> >+
> just one nitpick.
>
> Could you rename this static function to sss_log_internal. (or choose better name)
> In my opinion, it is better than sss_log_ext_int and we don't have
> two versions of internal function. "_ext" is redundant.
Thank you, I wasn't happy with the name either, but couldn't think of
anything better. New version with your suggestion attached.
bye,
Sumit
>
> LS
> _______________________________________________
> sssd-devel mailing list
> sssd-devel at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/sssd-devel
-------------- next part --------------
From b416be1d9070b1f90f88d9db55c8184adadc3808 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Tue, 26 Aug 2014 17:29:08 +0200
Subject: [PATCH] sss_log: fix handling of variable argument lists
SSSD has two public calls to send messages to syslog sss_log() and
sss_log_ext() which both expect besides other arguments a printf format
string and a variable list of arguments depending on the format.
Currently sss_log() calls sss_log_ext() internally after calling
va_start(ap, format) and hands over ap as the last argument. This does
not work because there is a difference between a varying number of
arguments and a va_list type.
To fix this I added a new private call which expects a va_list as the
last argument and is called by sss_log() and sss_log_ext() after calling
va_start().
---
src/util/sss_log.c | 28 +++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/src/util/sss_log.c b/src/util/sss_log.c
index 7a2dce6..48e73db 100644
--- a/src/util/sss_log.c
+++ b/src/util/sss_log.c
@@ -57,28 +57,40 @@ static int sss_to_syslog(int priority)
}
}
+static void sss_log_internal(int priority, int facility, const char *format,
+ va_list ap);
+
void sss_log(int priority, const char *format, ...)
{
va_list ap;
va_start(ap, format);
- sss_log_ext(priority, LOG_DAEMON, format, ap);
+ sss_log_internal(priority, LOG_DAEMON, format, ap);
va_end(ap);
}
-#ifdef WITH_JOURNALD
-
void sss_log_ext(int priority, int facility, const char *format, ...)
{
va_list ap;
+
+ va_start(ap, format);
+ sss_log_internal(priority, facility, format, ap);
+ va_end(ap);
+}
+
+
+
+#ifdef WITH_JOURNALD
+
+static void sss_log_internal(int priority, int facility, const char *format,
+ va_list ap)
+{
int syslog_priority;
int ret;
char *message;
const char *domain;
- va_start(ap, format);
ret = vasprintf(&message, format, ap);
- va_end(ap);
if (ret == -1) {
/* ENOMEM */
@@ -103,18 +115,16 @@ void sss_log_ext(int priority, int facility, const char *format, ...)
#else /* WITH_JOURNALD */
-void sss_log_ext(int priority, int facility, const char *format, ...)
+static void sss_log_internal(int priority, int facility, const char *format,
+ va_list ap)
{
- va_list ap;
int syslog_priority;
syslog_priority = sss_to_syslog(priority);
openlog(debug_prg_name, 0, facility);
- va_start(ap, format);
vsyslog(syslog_priority, format, ap);
- va_end(ap);
closelog();
}
--
1.8.3.1
More information about the sssd-devel
mailing list