From owner-svn-src-projects@FreeBSD.ORG Mon Oct 14 20:53:52 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 9B5F9E2C; Mon, 14 Oct 2013 20:53:52 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 884182753; Mon, 14 Oct 2013 20:53:52 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9EKrqS7051897; Mon, 14 Oct 2013 20:53:52 GMT (envelope-from asomers@svn.freebsd.org) Received: (from asomers@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9EKrpUf051894; Mon, 14 Oct 2013 20:53:52 GMT (envelope-from asomers@svn.freebsd.org) Message-Id: <201310142053.r9EKrpUf051894@svn.freebsd.org> From: Alan Somers Date: Mon, 14 Oct 2013 20:53:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r256452 - projects/zfsd/head/cddl/sbin/zfsd X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Oct 2013 20:53:52 -0000 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(), ""); 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) { }