svn commit: r216721 - head/sbin/hastd

Pawel Jakub Dawidek pjd at FreeBSD.org
Sun Dec 26 19:07:58 UTC 2010


Author: pjd
Date: Sun Dec 26 19:07:58 2010
New Revision: 216721
URL: http://svn.freebsd.org/changeset/base/216721

Log:
  When node-specific configuration is missing in resource section, provide
  more useful information. Instead of:
  
  	hastd: remote address not configured for resource foo
  
  Print the following:
  
  	No resource foo configuration for this node (acceptable node names: freefall, freefall.freebsd.org, 44333332-4c44-4e31-4a30-313920202020).
  
  MFC after:	3 days

Modified:
  head/sbin/hastd/parse.y

Modified: head/sbin/hastd/parse.y
==============================================================================
--- head/sbin/hastd/parse.y	Sun Dec 26 18:15:57 2010	(r216720)
+++ head/sbin/hastd/parse.y	Sun Dec 26 19:07:58 2010	(r216721)
@@ -55,7 +55,7 @@ extern char *yytext;
 
 static struct hastd_config *lconfig;
 static struct hast_resource *curres;
-static bool mynode;
+static bool mynode, hadmynode;
 
 static char depth0_control[HAST_ADDRSIZE];
 static char depth0_listen[HAST_ADDRSIZE];
@@ -109,6 +109,44 @@ isitme(const char *name)
 	return (0);
 }
 
+static int
+node_names(char **namesp)
+{
+	static char names[MAXHOSTNAMELEN * 3];
+	char buf[MAXHOSTNAMELEN];
+	char *pos;
+	size_t bufsize;
+
+	if (gethostname(buf, sizeof(buf)) < 0) {
+		pjdlog_errno(LOG_ERR, "gethostname() failed");
+		return (-1);
+	}
+
+	/* First component of the host name. */
+	pos = strchr(buf, '.');
+	if (pos != NULL && pos != buf) {
+		(void)strlcpy(names, buf, MIN((size_t)(pos - buf + 1),
+		    sizeof(names)));
+		(void)strlcat(names, ", ", sizeof(names));
+	}
+
+	/* Full host name. */
+	(void)strlcat(names, buf, sizeof(names));
+	(void)strlcat(names, ", ", sizeof(names));
+
+	/* Host UUID. */
+	bufsize = sizeof(buf);
+	if (sysctlbyname("kern.hostuuid", buf, &bufsize, NULL, 0) < 0) {
+		pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostuuid) failed");
+		return (-1);
+	}
+	(void)strlcat(names, buf, sizeof(names));
+
+	*namesp = names;
+
+	return (0);
+}
+
 void
 yyerror(const char *str)
 {
@@ -424,6 +462,20 @@ resource_statement:	RESOURCE resource_st
 	{
 		if (curres != NULL) {
 			/*
+			 * There must be section for this node, at least with
+			 * remote address configuration.
+			 */
+			if (!hadmynode) {
+				char *names;
+
+				if (node_names(&names) != 0)
+					return (1);
+				pjdlog_error("No resource %s configuration for this node (acceptable node names: %s).",
+				    curres->hr_name, names);
+				return (1);
+			}
+
+			/*
 			 * Let's see there are some resource-level settings
 			 * that we can use for node-level settings.
 			 */
@@ -489,6 +541,7 @@ resource_start:	STR
 		 */
 		depth1_provname[0] = '\0';
 		depth1_localpath[0] = '\0';
+		hadmynode = false;
 
 		curres = calloc(1, sizeof(*curres));
 		if (curres == NULL) {
@@ -614,7 +667,7 @@ resource_node_start:	STR
 			case 0:
 				break;
 			case 1:
-				mynode = true;
+				mynode = hadmynode = true;
 				break;
 			default:
 				assert(!"invalid isitme() return value");


More information about the svn-src-all mailing list