diff error.c @ 385:ad58806bf7e0

init: add a way to print session information The get_session op can use any thread local information to "inject" information about what was happening when the cmn_err call occured. Information that is include can be anything, but the idea is to print some form of session or connection identifying information. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Wed, 30 Aug 2017 14:53:46 +0300
parents 821b9ca00f0a
children d53c1436a171
line wrap: on
line diff
--- a/error.c	Tue Aug 29 21:30:42 2017 +0300
+++ b/error.c	Wed Aug 30 14:53:46 2017 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2016 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2013-2017 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -149,9 +149,18 @@
 	abort();
 }
 
+static const char *get_session(void)
+{
+	if (!libops.get_session)
+		return "";
+
+	return libops.get_session();
+}
+
 void cmn_verr(enum errlevel level, const char *fmt, va_list ap)
 {
 	const char *levelstr;
+	const char *session;
 	unsigned long tid;
 	int loglevel;
 	bool panic;
@@ -196,6 +205,11 @@
 	vsnprintf(buf, sizeof(buf), fmt, ap);
 
 	/*
+	 * Get the session string.
+	 */
+	session = get_session();
+
+	/*
 	 * We are printing the thread ID as a 4-digit number. This will
 	 * allow systems that use small integers (e.g., Illumos) to have
 	 * short IDs.  Systems that use large integers (e.g., Linux) will
@@ -203,8 +217,8 @@
 	 * clustered around some big integer, they will very likely always
 	 * print as the same number of digits.
 	 */
-	jeffpc_log(loglevel, "[%04lx] %-5s %s\n", tid, levelstr, buf);
-	jeffpc_print(level, "[%04lx] %-5s %s\n", tid, levelstr, buf);
+	jeffpc_log(loglevel, "[%04lx]%s %-5s %s\n", tid, session, levelstr, buf);
+	jeffpc_print(level, "[%04lx]%s %-5s %s\n", tid, session, levelstr, buf);
 
 	if (panic) {
 		print_stacktrace(CE_CRIT, NULL);