From owner-svn-src-all@FreeBSD.ORG Sun Dec 26 19:07:58 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 73463106564A; Sun, 26 Dec 2010 19:07:58 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 486D08FC08; Sun, 26 Dec 2010 19:07:58 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oBQJ7wUQ096780; Sun, 26 Dec 2010 19:07:58 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oBQJ7w4A096778; Sun, 26 Dec 2010 19:07:58 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201012261907.oBQJ7w4A096778@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Sun, 26 Dec 2010 19:07:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216721 - head/sbin/hastd X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Dec 2010 19:07:58 -0000 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");