All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pete Zaitcev <zaitcev@redhat.com>
To: Jeff Garzik <jeff@garzik.org>
Cc: Project Hail List <hail-devel@vger.kernel.org>
Subject: [Patch] libcldc,cldcli: Use humanized error messages
Date: Wed, 26 Aug 2009 20:06:25 -0600	[thread overview]
Message-ID: <20090826200625.4434935f@redhat.com> (raw)

Signed-off-by: Pete Zaitcev <zaitcev@redhat.com>

diff --git a/include/cld_msg.h b/include/cld_msg.h
index 01bda16..e4c8f28 100644
--- a/include/cld_msg.h
+++ b/include/cld_msg.h
@@ -257,5 +257,6 @@ struct cld_msg_event {
 
 extern unsigned long long cld_sid2llu(const uint8_t *sid);
 extern void __cld_rand64(void *p);
+extern const char *cld_errstr(enum cle_err_codes ecode);
 
 #endif /* __CLD_MSG_H__ */
diff --git a/lib/common.c b/lib/common.c
index fac652b..57f8696 100644
--- a/lib/common.c
+++ b/lib/common.c
@@ -19,3 +19,29 @@ void __cld_rand64(void *p)
 	v[1] = rand();
 }
 
+const char *cld_errstr(enum cle_err_codes ecode)
+{
+	switch (ecode) {
+	case CLE_OK:		return "Success";
+	case CLE_SESS_EXISTS:	return "Session exists";
+	case CLE_SESS_INVAL:	return "Invalid session";
+	case CLE_DB_ERR:	return "Database error";
+	case CLE_BAD_PKT:	return "Invalid/corrupted packet";
+	case CLE_INODE_INVAL:	return "Invalid inode number";
+	case CLE_NAME_INVAL:	return "Invalid file name";
+	case CLE_OOM:		return "Server out of memory";
+	case CLE_FH_INVAL:	return "Invalid file handle";
+	case CLE_DATA_INVAL:	return "Invalid data packet";
+	case CLE_LOCK_INVAL:	return "Invalid lock";
+	case CLE_LOCK_CONFLICT:	return "Conflicting lock held";
+	case CLE_LOCK_PENDING:	return "Lock waiting to be acquired";
+	case CLE_MODE_INVAL:	return "Operation incompatible with file mode";
+	case CLE_INODE_EXISTS:	return "File exists";
+	case CLE_DIR_NOTEMPTY:	return "Directory not empty";
+	case CLE_INTERNAL_ERR:	return "Internal error";
+	case CLE_TIMEOUT:	return "Session timed out";
+	case CLE_SIG_INVAL:	return "Bad HMAC signature";
+	default:		return "(unknown)";
+	}
+}
+
diff --git a/tools/cldcli.c b/tools/cldcli.c
index 635bc6e..eb4ebc4 100644
--- a/tools/cldcli.c
+++ b/tools/cldcli.c
@@ -66,9 +66,11 @@ struct creq {
 	struct cp_fc_info	*cfi;
 };
 
+enum { CRESP_MSGSZ = 64 };
+
 struct cresp {
 	enum thread_codes	tcode;
-	char			msg[64];
+	char			msg[CRESP_MSGSZ];
 	union {
 		size_t		file_len;
 		unsigned int	n_records;
@@ -117,31 +119,10 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state);
 
 static const struct argp argp = { options, parse_opt, NULL, doc };
 
-static const char *names_cle_err[] = {
-	[CLE_OK]		= "CLE_OK",
-	[CLE_SESS_EXISTS]	= "CLE_SESS_EXISTS",
-	[CLE_SESS_INVAL]	= "CLE_SESS_INVAL",
-	[CLE_DB_ERR]		= "CLE_DB_ERR",
-	[CLE_BAD_PKT]		= "CLE_BAD_PKT",
-	[CLE_INODE_INVAL]	= "CLE_INODE_INVAL",
-	[CLE_NAME_INVAL]	= "CLE_NAME_INVAL",
-	[CLE_OOM]		= "CLE_OOM",
-	[CLE_FH_INVAL]		= "CLE_FH_INVAL",
-	[CLE_DATA_INVAL]	= "CLE_DATA_INVAL",
-	[CLE_LOCK_INVAL]	= "CLE_LOCK_INVAL",
-	[CLE_LOCK_CONFLICT]	= "CLE_LOCK_CONFLICT",
-	[CLE_LOCK_PENDING]	= "CLE_LOCK_PENDING",
-	[CLE_MODE_INVAL]	= "CLE_MODE_INVAL",
-	[CLE_INODE_EXISTS]	= "CLE_INODE_EXISTS",
-	[CLE_DIR_NOTEMPTY]	= "CLE_DIR_NOTEMPTY",
-	[CLE_INTERNAL_ERR]	= "CLE_INTERNAL_ERR",
-	[CLE_TIMEOUT]		= "CLE_TIMEOUT",
-	[CLE_SIG_INVAL]		= "CLE_SIG_INVAL",
-};
-
 static void errc_msg(struct cresp *cresp, enum cle_err_codes errc)
 {
-	strcpy(cresp->msg, names_cle_err[errc]);
+	strncpy(cresp->msg, cld_errstr(errc), CRESP_MSGSZ);
+	cresp->msg[CRESP_MSGSZ-1] = 0;
 }
 
 static void applog(int prio, const char *fmt, ...)

             reply	other threads:[~2009-08-27  2:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-27  2:06 Pete Zaitcev [this message]
2009-08-27  2:26 ` [Patch] libcldc,cldcli: Use humanized error messages Jeff Garzik
2009-08-27  2:50   ` Pete Zaitcev
2009-08-27  3:04     ` Jeff Garzik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090826200625.4434935f@redhat.com \
    --to=zaitcev@redhat.com \
    --cc=hail-devel@vger.kernel.org \
    --cc=jeff@garzik.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.