summaryrefslogtreecommitdiffstats
path: root/sbin/hastd
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2010-12-26 19:07:58 +0000
committerpjd <pjd@FreeBSD.org>2010-12-26 19:07:58 +0000
commitc40ee32d16532996eeac9ee6756807329bc8b2ce (patch)
treeecb3542cc5e8919392bbd34ed7b8a61806480123 /sbin/hastd
parent928e7e990548a9d91cec2429992b1942ad02124b (diff)
downloadFreeBSD-src-c40ee32d16532996eeac9ee6756807329bc8b2ce.zip
FreeBSD-src-c40ee32d16532996eeac9ee6756807329bc8b2ce.tar.gz
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
Diffstat (limited to 'sbin/hastd')
-rw-r--r--sbin/hastd/parse.y57
1 files changed, 55 insertions, 2 deletions
diff --git a/sbin/hastd/parse.y b/sbin/hastd/parse.y
index d37e6db..c5b8b24 100644
--- a/sbin/hastd/parse.y
+++ b/sbin/hastd/parse.y
@@ -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_start OB resource_entries CB
{
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");
OpenPOWER on IntegriCloud