Blame SOURCES/autofs-5.1.2-log-functions-to-prefix-messages-with-attempt_id-if-available.patch

23b4c9
autofs-5.1.2 - log functions to prefix messages with attempt_id if available
23b4c9
23b4c9
From: Lars R. Damerow <lars@pixar.com>
23b4c9
23b4c9
Now that there should be a mount attempt id try and include it in log entries.
23b4c9
23b4c9
Signed-off-by: Lars R. Damerow <lars@pixar.com>
23b4c9
Signed-off-by: Ian Kent <raven@themaw.net>
23b4c9
---
23b4c9
 CHANGELOG |    1 
23b4c9
 lib/log.c |  164 +++++++++++++++++++++++++++++++++++++++++++++++++++-----------
23b4c9
 2 files changed, 137 insertions(+), 28 deletions(-)
23b4c9
23b4c9
--- autofs-5.0.7.orig/CHANGELOG
23b4c9
+++ autofs-5.0.7/CHANGELOG
23b4c9
@@ -237,6 +237,7 @@
23b4c9
 - delay submount exit for amd submounts.
23b4c9
 - add the mount requestor's pid to pending_args.
23b4c9
 - create thread-local ID for mount attempts.
23b4c9
+- log functions to prefix messages with attempt_id if available.
23b4c9
 
23b4c9
 25/07/2012 autofs-5.0.7
23b4c9
 =======================
23b4c9
--- autofs-5.0.7.orig/lib/log.c
23b4c9
+++ autofs-5.0.7/lib/log.c
23b4c9
@@ -32,6 +32,26 @@ static unsigned int logging_to_syslog =
23b4c9
 static unsigned int do_verbose = 0;		/* Verbose feedback option */
23b4c9
 static unsigned int do_debug = 0;		/* Full debug output */
23b4c9
 
23b4c9
+static char *prepare_attempt_prefix(const char *msg)
23b4c9
+{
23b4c9
+	unsigned long *attempt_id;
23b4c9
+	char buffer[ATTEMPT_ID_SIZE + 1];
23b4c9
+	char *prefixed_msg = NULL;
23b4c9
+
23b4c9
+	attempt_id = pthread_getspecific(key_thread_attempt_id);
23b4c9
+	if (attempt_id) {
23b4c9
+		int len = sizeof(buffer) + 1 + strlen(msg) + 1;
23b4c9
+
23b4c9
+		snprintf(buffer, ATTEMPT_ID_SIZE, "%02lx", *attempt_id);
23b4c9
+		prefixed_msg = (char *) calloc(len, sizeof(char));
23b4c9
+		strcpy(prefixed_msg, buffer);
23b4c9
+		strcat(prefixed_msg, "|");
23b4c9
+		strcat(prefixed_msg, msg);
23b4c9
+	}
23b4c9
+
23b4c9
+	return prefixed_msg;
23b4c9
+}
23b4c9
+
23b4c9
 void set_log_norm(void)
23b4c9
 {
23b4c9
 	do_verbose = 0;
23b4c9
@@ -72,124 +92,212 @@ void set_log_debug_ap(struct autofs_poin
23b4c9
 void log_info(unsigned int logopt, const char *msg, ...)
23b4c9
 {
23b4c9
 	unsigned int opt_log = logopt & (LOGOPT_DEBUG | LOGOPT_VERBOSE);
23b4c9
+	char *prefixed_msg;
23b4c9
 	va_list ap;
23b4c9
 
23b4c9
 	if (!do_debug && !do_verbose && !opt_log)
23b4c9
 		return;
23b4c9
 
23b4c9
+	prefixed_msg = prepare_attempt_prefix(msg);
23b4c9
+
23b4c9
 	va_start(ap, msg);
23b4c9
-	if (logging_to_syslog)
23b4c9
-		vsyslog(LOG_INFO, msg, ap);
23b4c9
-	else {
23b4c9
-		vfprintf(stderr, msg, ap);
23b4c9
+	if (logging_to_syslog) {
23b4c9
+		if (prefixed_msg)
23b4c9
+			vsyslog(LOG_INFO, prefixed_msg, ap);
23b4c9
+		else
23b4c9
+			vsyslog(LOG_INFO, msg, ap);
23b4c9
+	} else {
23b4c9
+		if (prefixed_msg)
23b4c9
+			vfprintf(stderr, prefixed_msg, ap);
23b4c9
+		else
23b4c9
+			vfprintf(stderr, msg, ap);
23b4c9
 		fputc('\n', stderr);
23b4c9
 	}
23b4c9
 	va_end(ap);
23b4c9
 
23b4c9
+	if (prefixed_msg)
23b4c9
+		free(prefixed_msg);
23b4c9
+
23b4c9
 	return;
23b4c9
 }
23b4c9
 
23b4c9
 void log_notice(unsigned int logopt, const char *msg, ...)
23b4c9
 {
23b4c9
 	unsigned int opt_log = logopt & (LOGOPT_DEBUG | LOGOPT_VERBOSE);
23b4c9
+	char *prefixed_msg;
23b4c9
 	va_list ap;
23b4c9
 
23b4c9
 	if (!do_debug && !do_verbose && !opt_log)
23b4c9
 		return;
23b4c9
 
23b4c9
+	prefixed_msg = prepare_attempt_prefix(msg);
23b4c9
+
23b4c9
 	va_start(ap, msg);
23b4c9
-	if (logging_to_syslog)
23b4c9
-		vsyslog(LOG_NOTICE, msg, ap);
23b4c9
-	else {
23b4c9
-		vfprintf(stderr, msg, ap);
23b4c9
+	if (logging_to_syslog) {
23b4c9
+		if (prefixed_msg)
23b4c9
+			vsyslog(LOG_NOTICE, prefixed_msg, ap);
23b4c9
+		else
23b4c9
+			vsyslog(LOG_INFO, msg, ap);
23b4c9
+	} else {
23b4c9
+		if (prefixed_msg)
23b4c9
+			vfprintf(stderr, prefixed_msg, ap);
23b4c9
+		else
23b4c9
+			vfprintf(stderr, msg, ap);
23b4c9
 		fputc('\n', stderr);
23b4c9
 	}
23b4c9
 	va_end(ap);
23b4c9
 
23b4c9
+	if (prefixed_msg)
23b4c9
+		free(prefixed_msg);
23b4c9
+
23b4c9
 	return;
23b4c9
 }
23b4c9
 
23b4c9
 void log_warn(unsigned int logopt, const char *msg, ...)
23b4c9
 {
23b4c9
 	unsigned int opt_log = logopt & (LOGOPT_DEBUG | LOGOPT_VERBOSE);
23b4c9
+	char *prefixed_msg;
23b4c9
 	va_list ap;
23b4c9
 
23b4c9
 	if (!do_debug && !do_verbose && !opt_log)
23b4c9
 		return;
23b4c9
 
23b4c9
+	prefixed_msg = prepare_attempt_prefix(msg);
23b4c9
+
23b4c9
 	va_start(ap, msg);
23b4c9
-	if (logging_to_syslog)
23b4c9
-		vsyslog(LOG_WARNING, msg, ap);
23b4c9
-	else {
23b4c9
-		vfprintf(stderr, msg, ap);
23b4c9
+	if (logging_to_syslog) {
23b4c9
+		if (prefixed_msg)
23b4c9
+			vsyslog(LOG_WARNING, prefixed_msg, ap);
23b4c9
+		else
23b4c9
+			vsyslog(LOG_INFO, msg, ap);
23b4c9
+	} else {
23b4c9
+		if (prefixed_msg)
23b4c9
+			vfprintf(stderr, prefixed_msg, ap);
23b4c9
+		else
23b4c9
+			vfprintf(stderr, msg, ap);
23b4c9
 		fputc('\n', stderr);
23b4c9
 	}
23b4c9
 	va_end(ap);
23b4c9
 
23b4c9
+	if (prefixed_msg)
23b4c9
+		free(prefixed_msg);
23b4c9
+
23b4c9
 	return;
23b4c9
 }
23b4c9
 
23b4c9
 void log_error(unsigned logopt, const char *msg, ...)
23b4c9
 {
23b4c9
+	char *prefixed_msg;
23b4c9
 	va_list ap;
23b4c9
 
23b4c9
+	prefixed_msg = prepare_attempt_prefix(msg);
23b4c9
+
23b4c9
 	va_start(ap, msg);
23b4c9
-	if (logging_to_syslog)
23b4c9
-		vsyslog(LOG_ERR, msg, ap);
23b4c9
-	else {
23b4c9
-		vfprintf(stderr, msg, ap);
23b4c9
+	if (logging_to_syslog) {
23b4c9
+		if (prefixed_msg)
23b4c9
+			vsyslog(LOG_ERR, prefixed_msg, ap);
23b4c9
+		else
23b4c9
+			vsyslog(LOG_INFO, msg, ap);
23b4c9
+	} else {
23b4c9
+		if (prefixed_msg)
23b4c9
+			vfprintf(stderr, prefixed_msg, ap);
23b4c9
+		else
23b4c9
+			vfprintf(stderr, msg, ap);
23b4c9
 		fputc('\n', stderr);
23b4c9
 	}
23b4c9
 	va_end(ap);
23b4c9
+
23b4c9
+	if (prefixed_msg)
23b4c9
+		free(prefixed_msg);
23b4c9
+
23b4c9
 	return;
23b4c9
 }
23b4c9
 
23b4c9
 void log_crit(unsigned logopt, const char *msg, ...)
23b4c9
 {
23b4c9
+	char *prefixed_msg;
23b4c9
 	va_list ap;
23b4c9
 
23b4c9
+	prefixed_msg = prepare_attempt_prefix(msg);
23b4c9
+
23b4c9
 	va_start(ap, msg);
23b4c9
-	if (logging_to_syslog)
23b4c9
-		vsyslog(LOG_CRIT, msg, ap);
23b4c9
-	else {
23b4c9
-		vfprintf(stderr, msg, ap);
23b4c9
+	if (logging_to_syslog) {
23b4c9
+		if (prefixed_msg)
23b4c9
+			vsyslog(LOG_CRIT, prefixed_msg, ap);
23b4c9
+		else
23b4c9
+			vsyslog(LOG_INFO, msg, ap);
23b4c9
+	} else {
23b4c9
+		if (prefixed_msg)
23b4c9
+			vfprintf(stderr, prefixed_msg, ap);
23b4c9
+		else
23b4c9
+			vfprintf(stderr, msg, ap);
23b4c9
 		fputc('\n', stderr);
23b4c9
 	}
23b4c9
 	va_end(ap);
23b4c9
+
23b4c9
+	if (prefixed_msg)
23b4c9
+		free(prefixed_msg);
23b4c9
+
23b4c9
 	return;
23b4c9
 }
23b4c9
 
23b4c9
 void log_debug(unsigned int logopt, const char *msg, ...)
23b4c9
 {
23b4c9
 	unsigned int opt_log = logopt & LOGOPT_DEBUG;
23b4c9
+	char *prefixed_msg;
23b4c9
 	va_list ap;
23b4c9
 
23b4c9
 	if (!do_debug && !opt_log)
23b4c9
 		return;
23b4c9
 
23b4c9
+	prefixed_msg = prepare_attempt_prefix(msg);
23b4c9
+
23b4c9
 	va_start(ap, msg);
23b4c9
-	if (logging_to_syslog)
23b4c9
-		vsyslog(LOG_WARNING, msg, ap);
23b4c9
-	else {
23b4c9
-		vfprintf(stderr, msg, ap);
23b4c9
+	if (logging_to_syslog) {
23b4c9
+		if (prefixed_msg)
23b4c9
+			vsyslog(LOG_WARNING, prefixed_msg, ap);
23b4c9
+		else
23b4c9
+			vsyslog(LOG_INFO, msg, ap);
23b4c9
+	} else {
23b4c9
+		if (prefixed_msg)
23b4c9
+			vfprintf(stderr, prefixed_msg, ap);
23b4c9
+		else
23b4c9
+			vfprintf(stderr, msg, ap);
23b4c9
 		fputc('\n', stderr);
23b4c9
 	}
23b4c9
 	va_end(ap);
23b4c9
 
23b4c9
+	if (prefixed_msg)
23b4c9
+		free(prefixed_msg);
23b4c9
+
23b4c9
 	return;
23b4c9
 }
23b4c9
 
23b4c9
 void logmsg(const char *msg, ...)
23b4c9
 {
23b4c9
+	char *prefixed_msg;
23b4c9
 	va_list ap;
23b4c9
+
23b4c9
+	prefixed_msg = prepare_attempt_prefix(msg);
23b4c9
+
23b4c9
 	va_start(ap, msg);
23b4c9
-	if (logging_to_syslog)
23b4c9
-		vsyslog(LOG_CRIT, msg, ap);
23b4c9
-	else {
23b4c9
-		vfprintf(stderr, msg, ap);
23b4c9
+	if (logging_to_syslog) {
23b4c9
+		if (prefixed_msg)
23b4c9
+			vsyslog(LOG_CRIT, prefixed_msg, ap);
23b4c9
+		else
23b4c9
+			vsyslog(LOG_INFO, msg, ap);
23b4c9
+	} else {
23b4c9
+		if (prefixed_msg)
23b4c9
+			vfprintf(stderr, prefixed_msg, ap);
23b4c9
+		else
23b4c9
+			vfprintf(stderr, msg, ap);
23b4c9
 		fputc('\n', stderr);
23b4c9
 	}
23b4c9
 	va_end(ap);
23b4c9
+
23b4c9
+	if (prefixed_msg)
23b4c9
+		free(prefixed_msg);
23b4c9
+
23b4c9
 	return;
23b4c9
 }
23b4c9