summaryrefslogtreecommitdiff
path: root/ninfod
diff options
context:
space:
mode:
authorYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>2012-11-25 03:16:28 +0900
committerYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>2012-11-25 15:19:10 +0900
commite74b9a2ef7a1714c6007c48ffeaffc8455ea9a9b (patch)
tree17ad1b01f220c995e1ca58f35da4fdf05921888d /ninfod
parent4b0813aa772b8d4495b5bc6c2ec26ac680551ed5 (diff)
downloadiputils-e74b9a2ef7a1714c6007c48ffeaffc8455ea9a9b.tar.gz
ninfod: Do not mix output from multiple threads.
- setbuf(stderr, NULL) - write a line at once (by vsnprintf + fputs); - No expcicit locks. Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Diffstat (limited to 'ninfod')
-rw-r--r--ninfod/config.h.in3
-rwxr-xr-xninfod/configure12
-rw-r--r--ninfod/configure.in1
-rw-r--r--ninfod/ninfod.c40
4 files changed, 54 insertions, 2 deletions
diff --git a/ninfod/config.h.in b/ninfod/config.h.in
index 4bdb50a..10ff9a2 100644
--- a/ninfod/config.h.in
+++ b/ninfod/config.h.in
@@ -24,6 +24,9 @@
/* Define to 1 if you have the `pthread' library (-lpthread). */
#undef HAVE_LIBPTHREAD
+/* Define to 1 if you have the <limits.h> header file. */
+#undef HAVE_LIMITS_H
+
/* Define to 1 if you have the <linux/rtnetlink.h> header file. */
#undef HAVE_LINUX_RTNETLINK_H
diff --git a/ninfod/configure b/ninfod/configure
index 4b69014..deba361 100755
--- a/ninfod/configure
+++ b/ninfod/configure
@@ -3535,6 +3535,18 @@ fi
done
+for ac_header in limits.h
+do :
+ ac_fn_c_check_header_mongrel "$LINENO" "limits.h" "ac_cv_header_limits_h" "$ac_includes_default"
+if test "x$ac_cv_header_limits_h" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_LIMITS_H 1
+_ACEOF
+
+fi
+
+done
+
for ac_header in openssl/md5.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "openssl/md5.h" "ac_cv_header_openssl_md5_h" "$ac_includes_default"
diff --git a/ninfod/configure.in b/ninfod/configure.in
index f33b77d..99f8da0 100644
--- a/ninfod/configure.in
+++ b/ninfod/configure.in
@@ -76,6 +76,7 @@ dnl Checks for libraries.
dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_TIME
+AC_CHECK_HEADERS(limits.h)
AC_CHECK_HEADERS(openssl/md5.h)
AC_CHECK_HEADERS(sys/uio.h)
AC_CHECK_HEADERS(sys/utsname.h arpa/inet.h netdb.h syslog.h)
diff --git a/ninfod/ninfod.c b/ninfod/ninfod.c
index bc4a23e..c8a581d 100644
--- a/ninfod/ninfod.c
+++ b/ninfod/ninfod.c
@@ -66,6 +66,9 @@
# include <stdint.h>
# endif
#endif
+#if HAVE_LIMITS_H
+# include <limits.h>
+#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
@@ -149,9 +152,40 @@ static const __inline__ char * log_level(int priority) {
void stderrlog(int pri, char *fmt, ...)
{
va_list ap;
+ char *buf = NULL;
+ size_t buflen = 1;
+
va_start(ap, fmt);
- fprintf(stderr, "[%s] ", log_level(pri));
- vfprintf(stderr, fmt, ap);
+
+ for (buf = NULL, buflen = 1024;
+ buflen < SIZE_MAX / 2;
+ free(buf), buf = NULL, buflen *= 2) {
+ size_t rem;
+ size_t res;
+
+ buf = malloc(buflen);
+ if (!buf)
+ break; /*XXX*/
+
+ rem = buflen;
+
+ res = snprintf(buf, rem, "[%s] ", log_level(pri));
+ if (res >= rem)
+ continue;
+ rem -= res;
+
+ res = vsnprintf(buf + res, rem, fmt, ap);
+
+ if (res >= rem)
+ continue;
+ break;
+ }
+
+ if (buf) {
+ fputs(buf, stderr);
+ free(buf);
+ }
+
va_end(ap);
}
#endif
@@ -613,6 +647,8 @@ int main (int argc, char **argv)
exit(1);
}
+ setbuf(stderr, NULL);
+
if (!opt_d)
do_daemonize();