2010-02-19 00:16:19 +01:00
|
|
|
%{
|
|
|
|
/*-
|
2023-05-10 17:40:58 +02:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2017-11-27 16:37:16 +01:00
|
|
|
*
|
2010-02-19 00:16:19 +01:00
|
|
|
* Copyright (c) 2009-2010 The FreeBSD Foundation
|
2011-03-06 23:56:14 +01:00
|
|
|
* Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net>
|
2010-02-19 00:16:19 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by Pawel Jakub Dawidek under sponsorship from
|
|
|
|
* the FreeBSD Foundation.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h> /* MAXHOSTNAMELEN */
|
|
|
|
#include <sys/queue.h>
|
2011-05-20 01:18:42 +02:00
|
|
|
#include <sys/socket.h>
|
2010-02-19 00:16:19 +01:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
2011-05-20 01:18:42 +02:00
|
|
|
#include <errno.h>
|
2010-02-19 00:16:19 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sysexits.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2010-08-05 21:08:54 +02:00
|
|
|
#include <pjdlog.h>
|
|
|
|
|
2010-02-19 00:16:19 +01:00
|
|
|
#include "hast.h"
|
|
|
|
|
|
|
|
extern int depth;
|
|
|
|
extern int lineno;
|
|
|
|
|
|
|
|
extern FILE *yyin;
|
|
|
|
extern char *yytext;
|
|
|
|
|
2010-08-05 21:08:54 +02:00
|
|
|
static struct hastd_config *lconfig;
|
2010-02-19 00:16:19 +01:00
|
|
|
static struct hast_resource *curres;
|
2010-12-26 20:07:58 +01:00
|
|
|
static bool mynode, hadmynode;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
|
|
|
static char depth0_control[HAST_ADDRSIZE];
|
2011-10-17 14:22:09 +02:00
|
|
|
static char depth0_pidfile[PATH_MAX];
|
2011-05-20 13:15:27 +02:00
|
|
|
static char depth0_listen_tcp4[HAST_ADDRSIZE];
|
|
|
|
static char depth0_listen_tcp6[HAST_ADDRSIZE];
|
2011-05-20 01:18:42 +02:00
|
|
|
static TAILQ_HEAD(, hastd_listen) depth0_listen;
|
2010-02-19 00:16:19 +01:00
|
|
|
static int depth0_replication;
|
2011-03-06 23:56:14 +01:00
|
|
|
static int depth0_checksum;
|
2011-03-07 00:09:33 +01:00
|
|
|
static int depth0_compression;
|
2010-04-29 17:36:32 +02:00
|
|
|
static int depth0_timeout;
|
2010-08-27 17:16:52 +02:00
|
|
|
static char depth0_exec[PATH_MAX];
|
2011-09-28 15:08:51 +02:00
|
|
|
static int depth0_metaflush;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
|
|
|
static char depth1_provname[PATH_MAX];
|
|
|
|
static char depth1_localpath[PATH_MAX];
|
2011-09-28 15:08:51 +02:00
|
|
|
static int depth1_metaflush;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2013-05-22 19:47:45 +02:00
|
|
|
extern void yyerror(const char *);
|
|
|
|
extern int yylex(void);
|
2010-08-05 21:08:54 +02:00
|
|
|
extern void yyrestart(FILE *);
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
static int isitme(const char *name);
|
|
|
|
static bool family_supported(int family);
|
|
|
|
static int node_names(char **namesp);
|
|
|
|
%}
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
%token CONTROL PIDFILE LISTEN REPLICATION CHECKSUM COMPRESSION METAFLUSH
|
|
|
|
%token TIMEOUT EXEC RESOURCE NAME LOCAL REMOTE SOURCE ON OFF
|
|
|
|
%token FULLSYNC MEMSYNC ASYNC NONE CRC32 SHA256 HOLE LZF
|
|
|
|
%token NUM STR OB CB
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
%type <str> remote_str
|
|
|
|
%type <num> replication_type
|
|
|
|
%type <num> checksum_type
|
|
|
|
%type <num> compression_type
|
|
|
|
%type <num> boolean
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
%union
|
|
|
|
{
|
|
|
|
int num;
|
|
|
|
char *str;
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
%token <num> NUM
|
|
|
|
%token <str> STR
|
2011-05-20 01:18:42 +02:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
%%
|
2011-05-20 01:18:42 +02:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
statements:
|
|
|
|
|
|
|
|
|
statements statement
|
|
|
|
;
|
2010-12-26 20:07:58 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
statement:
|
|
|
|
control_statement
|
|
|
|
|
|
|
|
|
pidfile_statement
|
|
|
|
|
|
|
|
|
listen_statement
|
|
|
|
|
|
|
|
|
replication_statement
|
|
|
|
|
|
|
|
|
checksum_statement
|
|
|
|
|
|
|
|
|
compression_statement
|
|
|
|
|
|
|
|
|
timeout_statement
|
|
|
|
|
|
|
|
|
exec_statement
|
|
|
|
|
|
|
|
|
metaflush_statement
|
|
|
|
|
|
|
|
|
node_statement
|
|
|
|
|
|
|
|
|
resource_statement
|
|
|
|
;
|
|
|
|
|
|
|
|
control_statement: CONTROL STR
|
|
|
|
{
|
|
|
|
switch (depth) {
|
|
|
|
case 0:
|
|
|
|
if (strlcpy(depth0_control, $2,
|
|
|
|
sizeof(depth0_control)) >=
|
|
|
|
sizeof(depth0_control)) {
|
|
|
|
pjdlog_error("control argument is too long.");
|
|
|
|
free($2);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (!mynode)
|
|
|
|
break;
|
|
|
|
if (strlcpy(lconfig->hc_controladdr, $2,
|
|
|
|
sizeof(lconfig->hc_controladdr)) >=
|
|
|
|
sizeof(lconfig->hc_controladdr)) {
|
|
|
|
pjdlog_error("control argument is too long.");
|
|
|
|
free($2);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PJDLOG_ABORT("control at wrong depth level");
|
|
|
|
}
|
|
|
|
free($2);
|
2010-12-26 20:07:58 +01:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
;
|
2010-12-26 20:07:58 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
pidfile_statement: PIDFILE STR
|
|
|
|
{
|
|
|
|
switch (depth) {
|
|
|
|
case 0:
|
|
|
|
if (strlcpy(depth0_pidfile, $2,
|
|
|
|
sizeof(depth0_pidfile)) >=
|
|
|
|
sizeof(depth0_pidfile)) {
|
|
|
|
pjdlog_error("pidfile argument is too long.");
|
|
|
|
free($2);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (!mynode)
|
|
|
|
break;
|
|
|
|
if (strlcpy(lconfig->hc_pidfile, $2,
|
|
|
|
sizeof(lconfig->hc_pidfile)) >=
|
|
|
|
sizeof(lconfig->hc_pidfile)) {
|
|
|
|
pjdlog_error("pidfile argument is too long.");
|
|
|
|
free($2);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PJDLOG_ABORT("pidfile at wrong depth level");
|
|
|
|
}
|
|
|
|
free($2);
|
2010-12-26 20:07:58 +01:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
;
|
2010-12-26 20:07:58 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
listen_statement: LISTEN STR
|
|
|
|
{
|
|
|
|
struct hastd_listen *lst;
|
2010-12-26 20:07:58 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
lst = calloc(1, sizeof(*lst));
|
|
|
|
if (lst == NULL) {
|
|
|
|
pjdlog_error("Unable to allocate memory for listen address.");
|
|
|
|
free($2);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (strlcpy(lst->hl_addr, $2, sizeof(lst->hl_addr)) >=
|
|
|
|
sizeof(lst->hl_addr)) {
|
|
|
|
pjdlog_error("listen argument is too long.");
|
|
|
|
free($2);
|
|
|
|
free(lst);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
switch (depth) {
|
|
|
|
case 0:
|
|
|
|
TAILQ_INSERT_TAIL(&depth0_listen, lst, hl_next);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (mynode)
|
|
|
|
TAILQ_INSERT_TAIL(&depth0_listen, lst, hl_next);
|
|
|
|
else
|
|
|
|
free(lst);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PJDLOG_ABORT("listen at wrong depth level");
|
|
|
|
}
|
|
|
|
free($2);
|
2010-12-26 20:07:58 +01:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
;
|
2010-12-26 20:07:58 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
replication_statement: REPLICATION replication_type
|
|
|
|
{
|
|
|
|
switch (depth) {
|
|
|
|
case 0:
|
|
|
|
depth0_replication = $2;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
PJDLOG_ASSERT(curres != NULL);
|
|
|
|
curres->hr_replication = $2;
|
2013-02-17 22:12:34 +01:00
|
|
|
curres->hr_original_replication = $2;
|
2012-05-22 18:33:10 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PJDLOG_ABORT("replication at wrong depth level");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
2010-12-26 20:07:58 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
replication_type:
|
|
|
|
FULLSYNC { $$ = HAST_REPLICATION_FULLSYNC; }
|
|
|
|
|
|
|
|
|
MEMSYNC { $$ = HAST_REPLICATION_MEMSYNC; }
|
|
|
|
|
|
|
|
|
ASYNC { $$ = HAST_REPLICATION_ASYNC; }
|
|
|
|
;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
checksum_statement: CHECKSUM checksum_type
|
|
|
|
{
|
|
|
|
switch (depth) {
|
|
|
|
case 0:
|
|
|
|
depth0_checksum = $2;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
PJDLOG_ASSERT(curres != NULL);
|
|
|
|
curres->hr_checksum = $2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PJDLOG_ABORT("checksum at wrong depth level");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
checksum_type:
|
|
|
|
NONE { $$ = HAST_CHECKSUM_NONE; }
|
|
|
|
|
|
|
|
|
CRC32 { $$ = HAST_CHECKSUM_CRC32; }
|
|
|
|
|
|
|
|
|
SHA256 { $$ = HAST_CHECKSUM_SHA256; }
|
|
|
|
;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
compression_statement: COMPRESSION compression_type
|
|
|
|
{
|
|
|
|
switch (depth) {
|
|
|
|
case 0:
|
|
|
|
depth0_compression = $2;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
PJDLOG_ASSERT(curres != NULL);
|
|
|
|
curres->hr_compression = $2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PJDLOG_ABORT("compression at wrong depth level");
|
|
|
|
}
|
2010-08-05 21:08:54 +02:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
;
|
2010-08-05 21:08:54 +02:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
compression_type:
|
|
|
|
NONE { $$ = HAST_COMPRESSION_NONE; }
|
|
|
|
|
|
|
|
|
HOLE { $$ = HAST_COMPRESSION_HOLE; }
|
|
|
|
|
|
|
|
|
LZF { $$ = HAST_COMPRESSION_LZF; }
|
|
|
|
;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
timeout_statement: TIMEOUT NUM
|
|
|
|
{
|
|
|
|
if ($2 <= 0) {
|
|
|
|
pjdlog_error("Negative or zero timeout.");
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
switch (depth) {
|
|
|
|
case 0:
|
|
|
|
depth0_timeout = $2;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
PJDLOG_ASSERT(curres != NULL);
|
|
|
|
curres->hr_timeout = $2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PJDLOG_ABORT("timeout at wrong depth level");
|
|
|
|
}
|
2011-10-17 14:22:09 +02:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
;
|
2011-05-20 01:18:42 +02:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
exec_statement: EXEC STR
|
|
|
|
{
|
|
|
|
switch (depth) {
|
|
|
|
case 0:
|
|
|
|
if (strlcpy(depth0_exec, $2, sizeof(depth0_exec)) >=
|
|
|
|
sizeof(depth0_exec)) {
|
|
|
|
pjdlog_error("Exec path is too long.");
|
|
|
|
free($2);
|
|
|
|
return (1);
|
2011-05-20 01:18:42 +02:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
PJDLOG_ASSERT(curres != NULL);
|
|
|
|
if (strlcpy(curres->hr_exec, $2,
|
|
|
|
sizeof(curres->hr_exec)) >=
|
|
|
|
sizeof(curres->hr_exec)) {
|
|
|
|
pjdlog_error("Exec path is too long.");
|
|
|
|
free($2);
|
|
|
|
return (1);
|
2011-05-20 01:18:42 +02:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PJDLOG_ABORT("exec at wrong depth level");
|
2011-05-20 01:18:42 +02:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
free($2);
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
metaflush_statement: METAFLUSH boolean
|
|
|
|
{
|
|
|
|
switch (depth) {
|
|
|
|
case 0:
|
|
|
|
depth0_metaflush = $2;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
PJDLOG_ASSERT(curres != NULL);
|
|
|
|
depth1_metaflush = $2;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (!mynode)
|
|
|
|
break;
|
|
|
|
PJDLOG_ASSERT(curres != NULL);
|
|
|
|
curres->hr_metaflush = $2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PJDLOG_ABORT("metaflush at wrong depth level");
|
2011-09-28 15:08:51 +02:00
|
|
|
}
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
boolean:
|
|
|
|
ON { $$ = 1; }
|
|
|
|
|
|
|
|
|
OFF { $$ = 0; }
|
|
|
|
;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
node_statement: ON node_start OB node_entries CB
|
|
|
|
{
|
|
|
|
mynode = false;
|
2011-05-20 01:18:42 +02:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
node_start: STR
|
|
|
|
{
|
|
|
|
switch (isitme($1)) {
|
|
|
|
case -1:
|
|
|
|
free($1);
|
|
|
|
return (1);
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
mynode = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PJDLOG_ABORT("invalid isitme() return value");
|
|
|
|
}
|
|
|
|
free($1);
|
|
|
|
}
|
|
|
|
;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
node_entries:
|
2010-02-19 00:16:19 +01:00
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
node_entries node_entry
|
2010-02-19 00:16:19 +01:00
|
|
|
;
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
node_entry:
|
2010-02-19 00:16:19 +01:00
|
|
|
control_statement
|
|
|
|
|
|
2011-10-17 14:22:09 +02:00
|
|
|
pidfile_statement
|
|
|
|
|
|
2010-02-19 00:16:19 +01:00
|
|
|
listen_statement
|
2012-05-22 18:33:10 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
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 if there are some resource-level settings
|
|
|
|
* that we can use for node-level settings.
|
|
|
|
*/
|
|
|
|
if (curres->hr_provname[0] == '\0' &&
|
|
|
|
depth1_provname[0] != '\0') {
|
|
|
|
/*
|
|
|
|
* Provider name is not set at node-level,
|
|
|
|
* but is set at resource-level, use it.
|
|
|
|
*/
|
|
|
|
strlcpy(curres->hr_provname, depth1_provname,
|
|
|
|
sizeof(curres->hr_provname));
|
|
|
|
}
|
|
|
|
if (curres->hr_localpath[0] == '\0' &&
|
|
|
|
depth1_localpath[0] != '\0') {
|
|
|
|
/*
|
|
|
|
* Path to local provider is not set at
|
|
|
|
* node-level, but is set at resource-level,
|
|
|
|
* use it.
|
|
|
|
*/
|
|
|
|
strlcpy(curres->hr_localpath, depth1_localpath,
|
|
|
|
sizeof(curres->hr_localpath));
|
|
|
|
}
|
|
|
|
if (curres->hr_metaflush == -1 && depth1_metaflush != -1) {
|
|
|
|
/*
|
|
|
|
* Metaflush is not set at node-level,
|
|
|
|
* but is set at resource-level, use it.
|
|
|
|
*/
|
|
|
|
curres->hr_metaflush = depth1_metaflush;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If provider name is not given, use resource name
|
|
|
|
* as provider name.
|
|
|
|
*/
|
|
|
|
if (curres->hr_provname[0] == '\0') {
|
|
|
|
strlcpy(curres->hr_provname, curres->hr_name,
|
|
|
|
sizeof(curres->hr_provname));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remote address has to be configured at this point.
|
|
|
|
*/
|
|
|
|
if (curres->hr_remoteaddr[0] == '\0') {
|
|
|
|
pjdlog_error("Remote address not configured for resource %s.",
|
|
|
|
curres->hr_name);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Path to local provider has to be configured at this
|
|
|
|
* point.
|
|
|
|
*/
|
|
|
|
if (curres->hr_localpath[0] == '\0') {
|
|
|
|
pjdlog_error("Path to local component not configured for resource %s.",
|
|
|
|
curres->hr_name);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Put it onto resource list. */
|
|
|
|
TAILQ_INSERT_TAIL(&lconfig->hc_resources, curres, hr_next);
|
|
|
|
curres = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
resource_start: STR
|
|
|
|
{
|
|
|
|
/* Check if there is no duplicate entry. */
|
|
|
|
TAILQ_FOREACH(curres, &lconfig->hc_resources, hr_next) {
|
|
|
|
if (strcmp(curres->hr_name, $1) == 0) {
|
|
|
|
pjdlog_error("Resource %s configured more than once.",
|
|
|
|
curres->hr_name);
|
|
|
|
free($1);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear those, so we can tell if they were set at
|
|
|
|
* resource-level or not.
|
|
|
|
*/
|
|
|
|
depth1_provname[0] = '\0';
|
|
|
|
depth1_localpath[0] = '\0';
|
|
|
|
depth1_metaflush = -1;
|
|
|
|
hadmynode = false;
|
|
|
|
|
|
|
|
curres = calloc(1, sizeof(*curres));
|
|
|
|
if (curres == NULL) {
|
|
|
|
pjdlog_error("Unable to allocate memory for resource.");
|
|
|
|
free($1);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (strlcpy(curres->hr_name, $1,
|
|
|
|
sizeof(curres->hr_name)) >=
|
|
|
|
sizeof(curres->hr_name)) {
|
|
|
|
pjdlog_error("Resource name is too long.");
|
|
|
|
free(curres);
|
|
|
|
free($1);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
free($1);
|
|
|
|
curres->hr_role = HAST_ROLE_INIT;
|
|
|
|
curres->hr_previous_role = HAST_ROLE_INIT;
|
|
|
|
curres->hr_replication = -1;
|
2013-02-17 22:12:34 +01:00
|
|
|
curres->hr_original_replication = -1;
|
2012-05-22 18:33:10 +02:00
|
|
|
curres->hr_checksum = -1;
|
|
|
|
curres->hr_compression = -1;
|
2013-02-17 22:12:34 +01:00
|
|
|
curres->hr_version = 1;
|
2012-05-22 18:33:10 +02:00
|
|
|
curres->hr_timeout = -1;
|
|
|
|
curres->hr_exec[0] = '\0';
|
|
|
|
curres->hr_provname[0] = '\0';
|
|
|
|
curres->hr_localpath[0] = '\0';
|
|
|
|
curres->hr_localfd = -1;
|
|
|
|
curres->hr_localflush = true;
|
|
|
|
curres->hr_metaflush = -1;
|
|
|
|
curres->hr_remoteaddr[0] = '\0';
|
|
|
|
curres->hr_sourceaddr[0] = '\0';
|
|
|
|
curres->hr_ggateunit = -1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
resource_entries:
|
2010-02-19 00:16:19 +01:00
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
resource_entries resource_entry
|
|
|
|
;
|
|
|
|
|
|
|
|
resource_entry:
|
2010-02-19 00:16:19 +01:00
|
|
|
replication_statement
|
|
|
|
|
|
2011-03-06 23:56:14 +01:00
|
|
|
checksum_statement
|
|
|
|
|
|
2011-03-07 00:09:33 +01:00
|
|
|
compression_statement
|
|
|
|
|
|
2010-04-29 17:36:32 +02:00
|
|
|
timeout_statement
|
|
|
|
|
|
2010-08-27 17:16:52 +02:00
|
|
|
exec_statement
|
|
|
|
|
|
2011-09-28 15:08:51 +02:00
|
|
|
metaflush_statement
|
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
name_statement
|
2010-02-19 00:16:19 +01:00
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
local_statement
|
|
|
|
|
|
|
|
|
resource_node_statement
|
2010-02-19 00:16:19 +01:00
|
|
|
;
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
name_statement: NAME STR
|
2010-02-19 00:16:19 +01:00
|
|
|
{
|
|
|
|
switch (depth) {
|
2012-05-22 18:33:10 +02:00
|
|
|
case 1:
|
|
|
|
if (strlcpy(depth1_provname, $2,
|
|
|
|
sizeof(depth1_provname)) >=
|
|
|
|
sizeof(depth1_provname)) {
|
|
|
|
pjdlog_error("name argument is too long.");
|
2010-10-24 17:41:23 +02:00
|
|
|
free($2);
|
2010-08-05 21:08:54 +02:00
|
|
|
return (1);
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
|
|
|
break;
|
2012-05-22 18:33:10 +02:00
|
|
|
case 2:
|
2010-08-27 16:28:39 +02:00
|
|
|
if (!mynode)
|
|
|
|
break;
|
2012-05-22 18:33:10 +02:00
|
|
|
PJDLOG_ASSERT(curres != NULL);
|
|
|
|
if (strlcpy(curres->hr_provname, $2,
|
|
|
|
sizeof(curres->hr_provname)) >=
|
|
|
|
sizeof(curres->hr_provname)) {
|
|
|
|
pjdlog_error("name argument is too long.");
|
2010-10-24 17:41:23 +02:00
|
|
|
free($2);
|
2010-08-27 16:28:39 +02:00
|
|
|
return (1);
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2012-05-22 18:33:10 +02:00
|
|
|
PJDLOG_ABORT("name at wrong depth level");
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
2010-10-24 17:41:23 +02:00
|
|
|
free($2);
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
local_statement: LOCAL STR
|
2011-10-17 14:22:09 +02:00
|
|
|
{
|
|
|
|
switch (depth) {
|
2012-05-22 18:33:10 +02:00
|
|
|
case 1:
|
|
|
|
if (strlcpy(depth1_localpath, $2,
|
|
|
|
sizeof(depth1_localpath)) >=
|
|
|
|
sizeof(depth1_localpath)) {
|
|
|
|
pjdlog_error("local argument is too long.");
|
2011-10-17 14:22:09 +02:00
|
|
|
free($2);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
break;
|
2012-05-22 18:33:10 +02:00
|
|
|
case 2:
|
2011-10-17 14:22:09 +02:00
|
|
|
if (!mynode)
|
|
|
|
break;
|
2012-05-22 18:33:10 +02:00
|
|
|
PJDLOG_ASSERT(curres != NULL);
|
|
|
|
if (strlcpy(curres->hr_localpath, $2,
|
|
|
|
sizeof(curres->hr_localpath)) >=
|
|
|
|
sizeof(curres->hr_localpath)) {
|
|
|
|
pjdlog_error("local argument is too long.");
|
2011-10-17 14:22:09 +02:00
|
|
|
free($2);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2012-05-22 18:33:10 +02:00
|
|
|
PJDLOG_ABORT("local at wrong depth level");
|
2011-10-17 14:22:09 +02:00
|
|
|
}
|
|
|
|
free($2);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
resource_node_statement:ON resource_node_start OB resource_node_entries CB
|
2010-02-19 00:16:19 +01:00
|
|
|
{
|
2012-05-22 18:33:10 +02:00
|
|
|
mynode = false;
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
resource_node_start: STR
|
2010-02-19 00:16:19 +01:00
|
|
|
{
|
2012-05-22 18:33:10 +02:00
|
|
|
if (curres != NULL) {
|
|
|
|
switch (isitme($1)) {
|
|
|
|
case -1:
|
|
|
|
free($1);
|
|
|
|
return (1);
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
mynode = hadmynode = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PJDLOG_ABORT("invalid isitme() return value");
|
|
|
|
}
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
free($1);
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
resource_node_entries:
|
2010-02-19 00:16:19 +01:00
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
resource_node_entries resource_node_entry
|
2011-03-06 23:56:14 +01:00
|
|
|
;
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
resource_node_entry:
|
|
|
|
name_statement
|
2011-03-06 23:56:14 +01:00
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
local_statement
|
2011-03-06 23:56:14 +01:00
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
remote_statement
|
|
|
|
|
|
|
|
|
source_statement
|
|
|
|
|
|
|
|
|
metaflush_statement
|
2011-03-06 23:56:14 +01:00
|
|
|
;
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
remote_statement: REMOTE remote_str
|
2011-03-07 00:09:33 +01:00
|
|
|
{
|
2012-05-22 18:33:10 +02:00
|
|
|
PJDLOG_ASSERT(depth == 2);
|
|
|
|
if (mynode) {
|
2011-09-27 10:04:01 +02:00
|
|
|
PJDLOG_ASSERT(curres != NULL);
|
2012-05-22 18:33:10 +02:00
|
|
|
if (strlcpy(curres->hr_remoteaddr, $2,
|
|
|
|
sizeof(curres->hr_remoteaddr)) >=
|
|
|
|
sizeof(curres->hr_remoteaddr)) {
|
|
|
|
pjdlog_error("remote argument is too long.");
|
|
|
|
free($2);
|
|
|
|
return (1);
|
|
|
|
}
|
2011-03-07 00:09:33 +01:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
free($2);
|
2011-03-07 00:09:33 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
remote_str:
|
|
|
|
NONE { $$ = strdup("none"); }
|
2011-03-07 00:09:33 +01:00
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
STR { }
|
2010-04-29 17:36:32 +02:00
|
|
|
;
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
source_statement: SOURCE STR
|
2010-08-27 17:16:52 +02:00
|
|
|
{
|
2012-05-22 18:33:10 +02:00
|
|
|
PJDLOG_ASSERT(depth == 2);
|
|
|
|
if (mynode) {
|
2011-09-27 10:04:01 +02:00
|
|
|
PJDLOG_ASSERT(curres != NULL);
|
2012-05-22 18:33:10 +02:00
|
|
|
if (strlcpy(curres->hr_sourceaddr, $2,
|
|
|
|
sizeof(curres->hr_sourceaddr)) >=
|
|
|
|
sizeof(curres->hr_sourceaddr)) {
|
|
|
|
pjdlog_error("source argument is too long.");
|
2010-10-24 17:41:23 +02:00
|
|
|
free($2);
|
2010-08-27 17:16:52 +02:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
2010-10-24 17:41:23 +02:00
|
|
|
free($2);
|
2010-08-27 17:16:52 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
%%
|
2011-09-28 15:08:51 +02:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
static int
|
|
|
|
isitme(const char *name)
|
|
|
|
{
|
|
|
|
char buf[MAXHOSTNAMELEN];
|
2013-02-17 22:12:34 +01:00
|
|
|
unsigned long hostid;
|
2012-05-22 18:33:10 +02:00
|
|
|
char *pos;
|
|
|
|
size_t bufsize;
|
2011-09-28 15:08:51 +02:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
/*
|
|
|
|
* First check if the given name matches our full hostname.
|
|
|
|
*/
|
|
|
|
if (gethostname(buf, sizeof(buf)) < 0) {
|
|
|
|
pjdlog_errno(LOG_ERR, "gethostname() failed");
|
|
|
|
return (-1);
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
if (strcmp(buf, name) == 0)
|
|
|
|
return (1);
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
/*
|
2013-02-17 22:12:34 +01:00
|
|
|
* Check if it matches first part of the host name.
|
2012-05-22 18:33:10 +02:00
|
|
|
*/
|
|
|
|
pos = strchr(buf, '.');
|
|
|
|
if (pos != NULL && (size_t)(pos - buf) == strlen(name) &&
|
|
|
|
strncmp(buf, name, pos - buf) == 0) {
|
|
|
|
return (1);
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
/*
|
2013-02-17 22:12:34 +01:00
|
|
|
* Check if it matches host UUID.
|
2012-05-22 18:33:10 +02:00
|
|
|
*/
|
|
|
|
bufsize = sizeof(buf);
|
|
|
|
if (sysctlbyname("kern.hostuuid", buf, &bufsize, NULL, 0) < 0) {
|
|
|
|
pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostuuid) failed");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (strcasecmp(buf, name) == 0)
|
|
|
|
return (1);
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2013-02-17 22:12:34 +01:00
|
|
|
/*
|
|
|
|
* Check if it matches hostid.
|
|
|
|
*/
|
|
|
|
bufsize = sizeof(hostid);
|
|
|
|
if (sysctlbyname("kern.hostid", &hostid, &bufsize, NULL, 0) < 0) {
|
|
|
|
pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostid) failed");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
(void)snprintf(buf, sizeof(buf), "hostid%lu", hostid);
|
|
|
|
if (strcmp(buf, name) == 0)
|
|
|
|
return (1);
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
/*
|
|
|
|
* Looks like this isn't about us.
|
|
|
|
*/
|
|
|
|
return (0);
|
|
|
|
}
|
2010-12-26 20:07:58 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
static bool
|
|
|
|
family_supported(int family)
|
|
|
|
{
|
|
|
|
int sock;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
sock = socket(family, SOCK_STREAM, 0);
|
2013-02-17 22:12:34 +01:00
|
|
|
if (sock == -1 && errno == EPROTONOSUPPORT)
|
2012-05-22 18:33:10 +02:00
|
|
|
return (false);
|
|
|
|
if (sock >= 0)
|
|
|
|
(void)close(sock);
|
|
|
|
return (true);
|
|
|
|
}
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
static int
|
|
|
|
node_names(char **namesp)
|
|
|
|
{
|
|
|
|
static char names[MAXHOSTNAMELEN * 3];
|
|
|
|
char buf[MAXHOSTNAMELEN];
|
2013-02-17 22:12:34 +01:00
|
|
|
unsigned long hostid;
|
2012-05-22 18:33:10 +02:00
|
|
|
char *pos;
|
|
|
|
size_t bufsize;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
if (gethostname(buf, sizeof(buf)) < 0) {
|
|
|
|
pjdlog_errno(LOG_ERR, "gethostname() failed");
|
|
|
|
return (-1);
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
/* 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));
|
|
|
|
}
|
2010-12-26 20:08:41 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
/* Full host name. */
|
|
|
|
(void)strlcat(names, buf, sizeof(names));
|
|
|
|
(void)strlcat(names, ", ", sizeof(names));
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
/* Host UUID. */
|
|
|
|
bufsize = sizeof(buf);
|
|
|
|
if (sysctlbyname("kern.hostuuid", buf, &bufsize, NULL, 0) < 0) {
|
|
|
|
pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostuuid) failed");
|
|
|
|
return (-1);
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
(void)strlcat(names, buf, sizeof(names));
|
2013-02-17 22:12:34 +01:00
|
|
|
(void)strlcat(names, ", ", sizeof(names));
|
|
|
|
|
|
|
|
/* Host ID. */
|
|
|
|
bufsize = sizeof(hostid);
|
|
|
|
if (sysctlbyname("kern.hostid", &hostid, &bufsize, NULL, 0) < 0) {
|
|
|
|
pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostid) failed");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
(void)snprintf(buf, sizeof(buf), "hostid%lu", hostid);
|
|
|
|
(void)strlcat(names, buf, sizeof(names));
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
*namesp = names;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
return (0);
|
|
|
|
}
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
void
|
|
|
|
yyerror(const char *str)
|
|
|
|
{
|
|
|
|
|
|
|
|
pjdlog_error("Unable to parse configuration file at line %d near '%s': %s",
|
|
|
|
lineno, yytext, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct hastd_config *
|
|
|
|
yy_config_parse(const char *config, bool exitonerror)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
curres = NULL;
|
|
|
|
mynode = false;
|
|
|
|
depth = 0;
|
|
|
|
lineno = 0;
|
|
|
|
|
|
|
|
depth0_timeout = HAST_TIMEOUT;
|
2013-02-17 22:12:34 +01:00
|
|
|
depth0_replication = HAST_REPLICATION_MEMSYNC;
|
2012-05-22 18:33:10 +02:00
|
|
|
depth0_checksum = HAST_CHECKSUM_NONE;
|
|
|
|
depth0_compression = HAST_COMPRESSION_HOLE;
|
|
|
|
strlcpy(depth0_control, HAST_CONTROL, sizeof(depth0_control));
|
|
|
|
strlcpy(depth0_pidfile, HASTD_PIDFILE, sizeof(depth0_pidfile));
|
|
|
|
TAILQ_INIT(&depth0_listen);
|
|
|
|
strlcpy(depth0_listen_tcp4, HASTD_LISTEN_TCP4,
|
|
|
|
sizeof(depth0_listen_tcp4));
|
|
|
|
strlcpy(depth0_listen_tcp6, HASTD_LISTEN_TCP6,
|
|
|
|
sizeof(depth0_listen_tcp6));
|
|
|
|
depth0_exec[0] = '\0';
|
|
|
|
depth0_metaflush = 1;
|
|
|
|
|
|
|
|
lconfig = calloc(1, sizeof(*lconfig));
|
|
|
|
if (lconfig == NULL) {
|
|
|
|
pjdlog_error("Unable to allocate memory for configuration.");
|
|
|
|
if (exitonerror)
|
|
|
|
exit(EX_TEMPFAIL);
|
|
|
|
return (NULL);
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
TAILQ_INIT(&lconfig->hc_listen);
|
|
|
|
TAILQ_INIT(&lconfig->hc_resources);
|
|
|
|
|
|
|
|
yyin = fopen(config, "r");
|
|
|
|
if (yyin == NULL) {
|
|
|
|
pjdlog_errno(LOG_ERR, "Unable to open configuration file %s",
|
|
|
|
config);
|
|
|
|
yy_config_free(lconfig);
|
|
|
|
if (exitonerror)
|
|
|
|
exit(EX_OSFILE);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
yyrestart(yyin);
|
|
|
|
ret = yyparse();
|
|
|
|
fclose(yyin);
|
|
|
|
if (ret != 0) {
|
|
|
|
yy_config_free(lconfig);
|
|
|
|
if (exitonerror)
|
|
|
|
exit(EX_CONFIG);
|
|
|
|
return (NULL);
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
/*
|
|
|
|
* Let's see if everything is set up.
|
|
|
|
*/
|
|
|
|
if (lconfig->hc_controladdr[0] == '\0') {
|
|
|
|
strlcpy(lconfig->hc_controladdr, depth0_control,
|
|
|
|
sizeof(lconfig->hc_controladdr));
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
if (lconfig->hc_pidfile[0] == '\0') {
|
|
|
|
strlcpy(lconfig->hc_pidfile, depth0_pidfile,
|
|
|
|
sizeof(lconfig->hc_pidfile));
|
|
|
|
}
|
|
|
|
if (!TAILQ_EMPTY(&depth0_listen))
|
|
|
|
TAILQ_CONCAT(&lconfig->hc_listen, &depth0_listen, hl_next);
|
|
|
|
if (TAILQ_EMPTY(&lconfig->hc_listen)) {
|
|
|
|
struct hastd_listen *lst;
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
if (family_supported(AF_INET)) {
|
|
|
|
lst = calloc(1, sizeof(*lst));
|
|
|
|
if (lst == NULL) {
|
|
|
|
pjdlog_error("Unable to allocate memory for listen address.");
|
|
|
|
yy_config_free(lconfig);
|
|
|
|
if (exitonerror)
|
|
|
|
exit(EX_TEMPFAIL);
|
|
|
|
return (NULL);
|
2010-08-05 21:08:54 +02:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
(void)strlcpy(lst->hl_addr, depth0_listen_tcp4,
|
|
|
|
sizeof(lst->hl_addr));
|
|
|
|
TAILQ_INSERT_TAIL(&lconfig->hc_listen, lst, hl_next);
|
|
|
|
} else {
|
|
|
|
pjdlog_debug(1,
|
|
|
|
"No IPv4 support in the kernel, not listening on IPv4 address.");
|
|
|
|
}
|
|
|
|
if (family_supported(AF_INET6)) {
|
|
|
|
lst = calloc(1, sizeof(*lst));
|
|
|
|
if (lst == NULL) {
|
|
|
|
pjdlog_error("Unable to allocate memory for listen address.");
|
|
|
|
yy_config_free(lconfig);
|
|
|
|
if (exitonerror)
|
|
|
|
exit(EX_TEMPFAIL);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
(void)strlcpy(lst->hl_addr, depth0_listen_tcp6,
|
|
|
|
sizeof(lst->hl_addr));
|
|
|
|
TAILQ_INSERT_TAIL(&lconfig->hc_listen, lst, hl_next);
|
|
|
|
} else {
|
|
|
|
pjdlog_debug(1,
|
|
|
|
"No IPv6 support in the kernel, not listening on IPv6 address.");
|
|
|
|
}
|
|
|
|
if (TAILQ_EMPTY(&lconfig->hc_listen)) {
|
|
|
|
pjdlog_error("No address to listen on.");
|
|
|
|
yy_config_free(lconfig);
|
|
|
|
if (exitonerror)
|
|
|
|
exit(EX_TEMPFAIL);
|
|
|
|
return (NULL);
|
2010-08-05 21:08:54 +02:00
|
|
|
}
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
TAILQ_FOREACH(curres, &lconfig->hc_resources, hr_next) {
|
|
|
|
PJDLOG_ASSERT(curres->hr_provname[0] != '\0');
|
|
|
|
PJDLOG_ASSERT(curres->hr_localpath[0] != '\0');
|
|
|
|
PJDLOG_ASSERT(curres->hr_remoteaddr[0] != '\0');
|
2010-02-19 00:16:19 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
if (curres->hr_replication == -1) {
|
|
|
|
/*
|
|
|
|
* Replication is not set at resource-level.
|
|
|
|
* Use global or default setting.
|
|
|
|
*/
|
|
|
|
curres->hr_replication = depth0_replication;
|
2013-02-17 22:12:34 +01:00
|
|
|
curres->hr_original_replication = depth0_replication;
|
2012-05-22 18:33:10 +02:00
|
|
|
}
|
|
|
|
if (curres->hr_checksum == -1) {
|
|
|
|
/*
|
|
|
|
* Checksum is not set at resource-level.
|
|
|
|
* Use global or default setting.
|
|
|
|
*/
|
|
|
|
curres->hr_checksum = depth0_checksum;
|
|
|
|
}
|
|
|
|
if (curres->hr_compression == -1) {
|
|
|
|
/*
|
|
|
|
* Compression is not set at resource-level.
|
|
|
|
* Use global or default setting.
|
|
|
|
*/
|
|
|
|
curres->hr_compression = depth0_compression;
|
|
|
|
}
|
|
|
|
if (curres->hr_timeout == -1) {
|
|
|
|
/*
|
|
|
|
* Timeout is not set at resource-level.
|
|
|
|
* Use global or default setting.
|
|
|
|
*/
|
|
|
|
curres->hr_timeout = depth0_timeout;
|
|
|
|
}
|
|
|
|
if (curres->hr_exec[0] == '\0') {
|
|
|
|
/*
|
|
|
|
* Exec is not set at resource-level.
|
|
|
|
* Use global or default setting.
|
|
|
|
*/
|
|
|
|
strlcpy(curres->hr_exec, depth0_exec,
|
|
|
|
sizeof(curres->hr_exec));
|
|
|
|
}
|
|
|
|
if (curres->hr_metaflush == -1) {
|
|
|
|
/*
|
|
|
|
* Metaflush is not set at resource-level.
|
|
|
|
* Use global or default setting.
|
|
|
|
*/
|
|
|
|
curres->hr_metaflush = depth0_metaflush;
|
2010-02-19 00:16:19 +01:00
|
|
|
}
|
|
|
|
}
|
2011-03-21 09:54:59 +01:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
return (lconfig);
|
|
|
|
}
|
2011-05-08 13:10:56 +02:00
|
|
|
|
2012-05-22 18:33:10 +02:00
|
|
|
void
|
|
|
|
yy_config_free(struct hastd_config *config)
|
|
|
|
{
|
|
|
|
struct hastd_listen *lst;
|
|
|
|
struct hast_resource *res;
|
|
|
|
|
|
|
|
while ((lst = TAILQ_FIRST(&depth0_listen)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&depth0_listen, lst, hl_next);
|
|
|
|
free(lst);
|
2011-03-21 09:54:59 +01:00
|
|
|
}
|
2012-05-22 18:33:10 +02:00
|
|
|
while ((lst = TAILQ_FIRST(&config->hc_listen)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&config->hc_listen, lst, hl_next);
|
|
|
|
free(lst);
|
|
|
|
}
|
|
|
|
while ((res = TAILQ_FIRST(&config->hc_resources)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&config->hc_resources, res, hr_next);
|
|
|
|
free(res);
|
|
|
|
}
|
|
|
|
free(config);
|
|
|
|
}
|