[rtems commit] syslog: Use self-contained recursive mutex

Sebastian Huber sebh at rtems.org
Thu Feb 8 08:18:31 UTC 2018


Module:    rtems
Branch:    master
Commit:    2aa5b98c321f0926e9b4e1ee50eb986400423f65
Changeset: http://git.rtems.org/rtems/commit/?id=2aa5b98c321f0926e9b4e1ee50eb986400423f65

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Jan  3 16:20:57 2018 +0100

syslog: Use self-contained recursive mutex

Update #2843.

---

 cpukit/libnetworking/lib/syslog.c | 30 ++++++------------------------
 1 file changed, 6 insertions(+), 24 deletions(-)

diff --git a/cpukit/libnetworking/lib/syslog.c b/cpukit/libnetworking/lib/syslog.c
index 066d7ab..8f0cbc8 100644
--- a/cpukit/libnetworking/lib/syslog.c
+++ b/cpukit/libnetworking/lib/syslog.c
@@ -7,6 +7,7 @@
 #endif
 
 #include <rtems.h>
+#include <rtems/thread.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <errno.h>
@@ -24,7 +25,8 @@ static int LogFacility = LOG_USER;
 static int LogMask = 0xff;
 
 static int LogFd = -1;
-static rtems_id LogSemaphore;
+static rtems_recursive_mutex LogSemaphore =
+  RTEMS_RECURSIVE_MUTEX_INITIALIZER("syslog");
 extern struct in_addr rtems_bsdnet_log_host_address;
 
 #define SYSLOG_PORT	514
@@ -89,8 +91,7 @@ vsyslog (int pri, const char *fmt, va_list ap)
 	 */
 	sent = 0;
 	if ((rtems_bsdnet_log_host_address.s_addr != INADDR_ANY)
-	 && (LogFd >= 0)
-	 && (rtems_semaphore_obtain (LogSemaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT) == RTEMS_SUCCESSFUL)) {
+	 && (LogFd >= 0)) {
 		/*
 		 * Set the destination address/port
 		 */
@@ -100,12 +101,13 @@ vsyslog (int pri, const char *fmt, va_list ap)
 		farAddress.sin_addr = rtems_bsdnet_log_host_address;
 		memset (farAddress.sin_zero, '\0', sizeof farAddress.sin_zero);
 
+		rtems_recursive_mutex_lock (&LogSemaphore);
 		/*
 		 * Send the message
 		 */
 		if (sendto (LogFd, cbuf, cnt, 0, (struct sockaddr *)&farAddress, sizeof farAddress) >= 0)
 			sent = 1;
-		rtems_semaphore_release (LogSemaphore);
+		rtems_recursive_mutex_unlock (&LogSemaphore);
 	}
 	if (!sent && (LogStatus & LOG_CONS) && !(LogStatus & LOG_PERROR))
 		printf ("%s\n", msgp);
@@ -114,7 +116,6 @@ vsyslog (int pri, const char *fmt, va_list ap)
 void
 openlog (const char *ident, int logstat, int logfac)
 {
-	rtems_status_code sc;
 	struct sockaddr_in myAddress;
 
 	if (ident != NULL)
@@ -144,24 +145,6 @@ openlog (const char *ident, int logstat, int logfac)
 		printf ("Can't bind syslog socket: %d\n", errno);
 		return;
 	}
-
-	/*
-	 * Create the mutex
-	 */
-	sc = rtems_semaphore_create (rtems_build_name('s', 'L', 'o', 'g'),
-					1,
-					RTEMS_PRIORITY |
-						RTEMS_BINARY_SEMAPHORE |
-						RTEMS_INHERIT_PRIORITY |
-						RTEMS_NO_PRIORITY_CEILING |
-						RTEMS_LOCAL,
-					0,
-					&LogSemaphore);
-	if (sc != RTEMS_SUCCESSFUL) {
-		printf ("Can't create syslog semaphore: %d\n", sc);
-		close (LogFd);
-		LogFd = -1;
-	}
 }
 
 void
@@ -170,7 +153,6 @@ closelog(void)
 	if (LogFd >= 0) {
 		close (LogFd);
 		LogFd = -1;
-		rtems_semaphore_delete (LogSemaphore);
 	}
 }
 



More information about the vc mailing list