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
This commit is contained in:
Pawel Jakub Dawidek 2010-12-26 19:07:58 +00:00
parent b60d416b6b
commit 66db33a13b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=216721

View File

@ -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)
{
@ -423,6 +461,20 @@ node_entry:
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");