1%{ 2/*- 3 * Copyright (c) 2009-2010 The FreeBSD Foundation 4 * All rights reserved. 5 * 6 * This software was developed by Pawel Jakub Dawidek under sponsorship from 7 * the FreeBSD Foundation. 8 * --- 13 unchanged lines hidden (view full) --- 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * |
30 * $FreeBSD: head/sbin/hastd/parse.y 207371 2010-04-29 15:36:32Z pjd $ |
31 */ 32 33#include <sys/param.h> /* MAXHOSTNAMELEN */ 34#include <sys/queue.h> 35#include <sys/sysctl.h> 36 37#include <arpa/inet.h> 38 --- 14 unchanged lines hidden (view full) --- 53 54static struct hastd_config lconfig; 55static struct hast_resource *curres; 56static bool mynode; 57 58static char depth0_control[HAST_ADDRSIZE]; 59static char depth0_listen[HAST_ADDRSIZE]; 60static int depth0_replication; |
61static int depth0_timeout; |
62 63static char depth1_provname[PATH_MAX]; 64static char depth1_localpath[PATH_MAX]; 65 66static bool 67isitme(const char *name) 68{ 69 char buf[MAXHOSTNAMELEN]; --- 41 unchanged lines hidden (view full) --- 111struct hastd_config * 112yy_config_parse(const char *config) 113{ 114 int ret; 115 116 curres = NULL; 117 mynode = false; 118 |
119 depth0_timeout = HAST_TIMEOUT; |
120 depth0_replication = HAST_REPLICATION_MEMSYNC; 121 strlcpy(depth0_control, HAST_CONTROL, sizeof(depth0_control)); 122 strlcpy(depth0_listen, HASTD_LISTEN, sizeof(depth0_listen)); 123 124 TAILQ_INIT(&lconfig.hc_resources); 125 126 yyin = fopen(config, "r"); 127 if (yyin == NULL) --- 23 unchanged lines hidden (view full) --- 151 152 if (curres->hr_replication == -1) { 153 /* 154 * Replication is not set at resource-level. 155 * Use global or default setting. 156 */ 157 curres->hr_replication = depth0_replication; 158 } |
159 if (curres->hr_timeout == -1) { 160 /* 161 * Timeout is not set at resource-level. 162 * Use global or default setting. 163 */ 164 curres->hr_timeout = depth0_timeout; 165 } |
166 } 167 168 return (&lconfig); 169} 170 171void 172yy_config_free(struct hastd_config *config) 173{ 174 struct hast_resource *res; 175 176 while ((res = TAILQ_FIRST(&config->hc_resources)) != NULL) { 177 TAILQ_REMOVE(&config->hc_resources, res, hr_next); 178 free(res); 179 } 180} 181%} 182 |
183%token CONTROL LISTEN PORT REPLICATION TIMEOUT EXTENTSIZE RESOURCE NAME LOCAL REMOTE ON |
184%token FULLSYNC MEMSYNC ASYNC 185%token NUM STR OB CB 186 187%type <num> replication_type 188 189%union 190{ 191 int num; --- 12 unchanged lines hidden (view full) --- 204 205statement: 206 control_statement 207 | 208 listen_statement 209 | 210 replication_statement 211 | |
212 timeout_statement 213 | |
214 node_statement 215 | 216 resource_statement 217 ; 218 219control_statement: CONTROL STR 220 { 221 switch (depth) { --- 65 unchanged lines hidden (view full) --- 287replication_type: 288 FULLSYNC { $$ = HAST_REPLICATION_FULLSYNC; } 289 | 290 MEMSYNC { $$ = HAST_REPLICATION_MEMSYNC; } 291 | 292 ASYNC { $$ = HAST_REPLICATION_ASYNC; } 293 ; 294 |
295timeout_statement: TIMEOUT NUM 296 { 297 switch (depth) { 298 case 0: 299 depth0_timeout = $2; 300 break; 301 case 1: 302 if (curres != NULL) 303 curres->hr_timeout = $2; 304 break; 305 default: 306 assert(!"timeout at wrong depth level"); 307 } 308 } 309 ; 310 |
311node_statement: ON node_start OB node_entries CB 312 { 313 mynode = false; 314 } 315 ; 316 317node_start: STR 318 { --- 92 unchanged lines hidden (view full) --- 411 sizeof(curres->hr_name)) >= 412 sizeof(curres->hr_name)) { 413 errx(EX_CONFIG, 414 "resource name (%s) too long", $1); 415 } 416 curres->hr_role = HAST_ROLE_INIT; 417 curres->hr_previous_role = HAST_ROLE_INIT; 418 curres->hr_replication = -1; |
419 curres->hr_timeout = -1; |
420 curres->hr_provname[0] = '\0'; 421 curres->hr_localpath[0] = '\0'; 422 curres->hr_localfd = -1; 423 curres->hr_remoteaddr[0] = '\0'; 424 curres->hr_ggateunit = -1; 425 } 426 ; 427 428resource_entries: 429 | 430 resource_entries resource_entry 431 ; 432 433resource_entry: 434 replication_statement 435 | |
436 timeout_statement 437 | |
438 name_statement 439 | 440 local_statement 441 | 442 resource_node_statement 443 ; 444 445name_statement: NAME STR --- 92 unchanged lines hidden --- |