svn commit: r256452 - projects/zfsd/head/cddl/sbin/zfsd

Alan Somers asomers at FreeBSD.org
Mon Oct 14 20:53:52 UTC 2013


Author: asomers
Date: Mon Oct 14 20:53:51 2013
New Revision: 256452
URL: http://svnweb.freebsd.org/changeset/base/256452

Log:
  Modify ParseException so that it records the parse buffer upon construction.
  This allows it to be caught at any level in the program and logged with full
  fidelity.
  
  	cddl/sbin/zfsd/dev_ctl_event.cc:
  	cddl/sbin/zfsd/dev_ctl_event.h:
  		Update ParseException implementation: take the parse buffer
  		string on construction and don't require the parse buffer
  		string when logging or converting the exception to a string.
  
  	cddl/sbin/zfsd/dev_ctl_event.cc:
  	cddl/sbin/zfsd/case_file.cc:
  		Adjust to Log() and ToString() taking no arguments.
  
  Submitted by:	gibbs
  Approved by:	ken (mentor)
  Sponsored By:	Spectra Logic

Modified:
  projects/zfsd/head/cddl/sbin/zfsd/case_file.cc
  projects/zfsd/head/cddl/sbin/zfsd/dev_ctl_event.cc
  projects/zfsd/head/cddl/sbin/zfsd/dev_ctl_event.h

Modified: projects/zfsd/head/cddl/sbin/zfsd/case_file.cc
==============================================================================
--- projects/zfsd/head/cddl/sbin/zfsd/case_file.cc	Mon Oct 14 20:51:51 2013	(r256451)
+++ projects/zfsd/head/cddl/sbin/zfsd/case_file.cc	Mon Oct 14 20:53:51 2013	(r256452)
@@ -649,7 +649,7 @@ CaseFile::DeSerializeFile(const char *fi
 		}
 	} catch (const ParseException &exp) {
 
-		exp.Log(evString);
+		exp.Log();
 		if (caseFile != existingCaseFile)
 			delete caseFile;
 

Modified: projects/zfsd/head/cddl/sbin/zfsd/dev_ctl_event.cc
==============================================================================
--- projects/zfsd/head/cddl/sbin/zfsd/dev_ctl_event.cc	Mon Oct 14 20:51:51 2013	(r256451)
+++ projects/zfsd/head/cddl/sbin/zfsd/dev_ctl_event.cc	Mon Oct 14 20:53:51 2013	(r256452)
@@ -61,7 +61,7 @@ using std::stringstream;
 /*------------------------------ ParseException ------------------------------*/
 //- ParseException Public Methods ----------------------------------------------
 string
-ParseException::ToString(const string &parsedBuffer) const
+ParseException::ToString() const
 {
 	stringstream result;
 
@@ -82,9 +82,9 @@ ParseException::ToString(const string &p
 	}
 	result << "exception on buffer: \'";
 	if (GetOffset() == 0) {
-		result << parsedBuffer << '\'' << endl;
+		result << m_parsedBuffer << '\'' << endl;
 	} else {
-		string markedBuffer(parsedBuffer);
+		string markedBuffer(m_parsedBuffer);
 
 		markedBuffer.insert(GetOffset(), "<HERE-->");
 		result << markedBuffer << '\'' << endl;
@@ -94,14 +94,14 @@ ParseException::ToString(const string &p
 }
 
 void
-ParseException::Log(const string &parsedBuffer) const
+ParseException::Log() const
 {
 	int priority(LOG_ERR);
 
 	if (Type() == DISCARDED_EVENT_TYPE)
 		priority = LOG_INFO;
 
-	syslog(priority, "%s", ToString(parsedBuffer).c_str());
+	syslog(priority, "%s", ToString().c_str());
 }
 
 /*-------------------------------- DevCtlEvent -------------------------------*/
@@ -149,7 +149,7 @@ DevCtlEvent::CreateEvent(const string &e
 		ParseEventString(type, eventString, nvpairs);
 	} catch (const ParseException &exp) {
 		if (exp.GetType() == ParseException::INVALID_FORMAT)
-			exp.Log(eventString);
+			exp.Log();
 		return (NULL);
 	}
 
@@ -312,14 +312,14 @@ DevCtlEvent::ParseEventString(DevCtlEven
 		end = eventString.find_first_of(" \t\n", start);
 		if (end == string::npos)
 			throw ParseException(ParseException::INVALID_FORMAT,
-					     start);
+					     eventString, start);
 
 		nvpairs["device-name"] = eventString.substr(start, end - start);
 
 		start = eventString.find(" on ", end);
 		if (end == string::npos)
 			throw ParseException(ParseException::INVALID_FORMAT,
-					     start);
+					     eventString, start);
 		start += 4;
 		end = eventString.find_first_of(" \t\n", start);
 		nvpairs["parent"] = eventString.substr(start, end);
@@ -327,9 +327,11 @@ DevCtlEvent::ParseEventString(DevCtlEven
 	case NOTIFY:
 		break;
 	case NOMATCH:
-		throw ParseException(ParseException::DISCARDED_EVENT_TYPE);
+		throw ParseException(ParseException::DISCARDED_EVENT_TYPE,
+				     eventString);
 	default:
-		throw ParseException(ParseException::UNKNOWN_EVENT_TYPE);
+		throw ParseException(ParseException::UNKNOWN_EVENT_TYPE,
+				     eventString);
 	}
 
 	/* Process common "key=value" format. */
@@ -349,7 +351,7 @@ DevCtlEvent::ParseEventString(DevCtlEven
 		start = eventString.find_last_of("! \t\n", end);
 		if (start == string::npos)
 			throw ParseException(ParseException::INVALID_FORMAT,
-					     end);
+					     eventString, end);
 		start++;
 		string key(eventString.substr(start, end - start));
 
@@ -360,7 +362,7 @@ DevCtlEvent::ParseEventString(DevCtlEven
 		start = end + 1;
 		if (start >= eventString.length())
 			throw ParseException(ParseException::INVALID_FORMAT,
-					     end);
+					     eventString, end);
 		end = eventString.find_first_of(" \t\n", start);
 		if (end == string::npos)
 			end = eventString.length() - 1;

Modified: projects/zfsd/head/cddl/sbin/zfsd/dev_ctl_event.h
==============================================================================
--- projects/zfsd/head/cddl/sbin/zfsd/dev_ctl_event.h	Mon Oct 14 20:51:51 2013	(r256451)
+++ projects/zfsd/head/cddl/sbin/zfsd/dev_ctl_event.h	Mon Oct 14 20:53:51 2013	(r256452)
@@ -80,18 +80,21 @@ public:
 	/**
 	 * Constructor
 	 *
-	 * \param type    The type of this exception.
-	 * \param offset  The location in the parse buffer where this
-	 *                exception occurred.
+	 * \param type          The type of this exception.
+	 * \param parsedBuffer  The parsing buffer active at the time of
+	 *                      the exception.
+	 * \param offset        The location in the parse buffer where this
+	 *                      exception occurred.
 	 */
-	ParseException(Type type, size_t offset = 0);
+	ParseException(Type type, const string &parsedBuffer,
+		       size_t offset = 0);
 
 	/**
 	 * Accessor
 	 *
 	 * \return  The classification for this exception.
 	 */
-	Type   GetType()			    const;
+	Type   GetType()   const;
 
 	/**
 	 * Accessor
@@ -99,37 +102,42 @@ public:
 	 * \return  The offset into the event string where this exception
 	 *          occurred.
 	 */
-	size_t GetOffset()			    const;
+	size_t GetOffset() const;
 
 	/**
 	 * Convert an exception into a human readable string.
 	 *
 	 * \param parsedBuffer  The event buffer that caused the failure.
 	 */
-	string ToString(const string &parsedBuffer) const;
+	string ToString()  const;
 
 	/**
 	 * Log exception data to syslog.
 	 *
 	 * \param parsedBuffer  The event buffer that caused the failure.
 	 */
-	void   Log(const string &parsedBuffer)      const;
+	void   Log()	   const;
 
 private:
 	/** The type of this exception. */
-	Type   m_type;
+	Type         m_type;
+
+	/** The parsing buffer that was active at the time of the exception. */
+	const string m_parsedBuffer;
 
 	/**
 	 * The offset into the event string buffer from where this
 	 * exception was triggered.
 	 */
-	size_t m_offset;
+	size_t       m_offset;
 };
 
 //- ParseException Inline Public Methods ---------------------------------------
 inline
-ParseException::ParseException(Type type, size_t offset)
+ParseException::ParseException(Type type, const string &parsedBuffer,
+			       size_t offset)
  : m_type(type),
+   m_parsedBuffer(parsedBuffer),
    m_offset(offset)
 {
 }


More information about the svn-src-projects mailing list