parse.y (211883) | parse.y (211886) |
---|---|
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 * | 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 211883 2010-08-27 14:28:39Z pjd $ | 30 * $FreeBSD: head/sbin/hastd/parse.y 211886 2010-08-27 15:16:52Z 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 --- 17 unchanged lines hidden (view full) --- 56static struct hastd_config *lconfig; 57static struct hast_resource *curres; 58static bool mynode; 59 60static char depth0_control[HAST_ADDRSIZE]; 61static char depth0_listen[HAST_ADDRSIZE]; 62static int depth0_replication; 63static int depth0_timeout; | 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 --- 17 unchanged lines hidden (view full) --- 56static struct hastd_config *lconfig; 57static struct hast_resource *curres; 58static bool mynode; 59 60static char depth0_control[HAST_ADDRSIZE]; 61static char depth0_listen[HAST_ADDRSIZE]; 62static int depth0_replication; 63static int depth0_timeout; |
64static char depth0_exec[PATH_MAX]; |
|
64 65static char depth1_provname[PATH_MAX]; 66static char depth1_localpath[PATH_MAX]; 67 68extern void yyrestart(FILE *); 69 70static int 71isitme(const char *name) --- 53 unchanged lines hidden (view full) --- 125 mynode = false; 126 depth = 0; 127 lineno = 0; 128 129 depth0_timeout = HAST_TIMEOUT; 130 depth0_replication = HAST_REPLICATION_MEMSYNC; 131 strlcpy(depth0_control, HAST_CONTROL, sizeof(depth0_control)); 132 strlcpy(depth0_listen, HASTD_LISTEN, sizeof(depth0_listen)); | 65 66static char depth1_provname[PATH_MAX]; 67static char depth1_localpath[PATH_MAX]; 68 69extern void yyrestart(FILE *); 70 71static int 72isitme(const char *name) --- 53 unchanged lines hidden (view full) --- 126 mynode = false; 127 depth = 0; 128 lineno = 0; 129 130 depth0_timeout = HAST_TIMEOUT; 131 depth0_replication = HAST_REPLICATION_MEMSYNC; 132 strlcpy(depth0_control, HAST_CONTROL, sizeof(depth0_control)); 133 strlcpy(depth0_listen, HASTD_LISTEN, sizeof(depth0_listen)); |
134 depth0_exec[0] = '\0'; |
|
133 134 lconfig = calloc(1, sizeof(*lconfig)); 135 if (lconfig == NULL) { 136 pjdlog_error("Unable to allocate memory for configuration."); 137 if (exitonerror) 138 exit(EX_TEMPFAIL); 139 return (NULL); 140 } --- 44 unchanged lines hidden (view full) --- 185 } 186 if (curres->hr_timeout == -1) { 187 /* 188 * Timeout is not set at resource-level. 189 * Use global or default setting. 190 */ 191 curres->hr_timeout = depth0_timeout; 192 } | 135 136 lconfig = calloc(1, sizeof(*lconfig)); 137 if (lconfig == NULL) { 138 pjdlog_error("Unable to allocate memory for configuration."); 139 if (exitonerror) 140 exit(EX_TEMPFAIL); 141 return (NULL); 142 } --- 44 unchanged lines hidden (view full) --- 187 } 188 if (curres->hr_timeout == -1) { 189 /* 190 * Timeout is not set at resource-level. 191 * Use global or default setting. 192 */ 193 curres->hr_timeout = depth0_timeout; 194 } |
195 if (curres->hr_exec[0] == '\0') { 196 /* 197 * Exec is not set at resource-level. 198 * Use global or default setting. 199 */ 200 strlcpy(curres->hr_exec, depth0_exec, 201 sizeof(curres->hr_exec)); 202 } |
|
193 } 194 195 return (lconfig); 196} 197 198void 199yy_config_free(struct hastd_config *config) 200{ 201 struct hast_resource *res; 202 203 while ((res = TAILQ_FIRST(&config->hc_resources)) != NULL) { 204 TAILQ_REMOVE(&config->hc_resources, res, hr_next); 205 free(res); 206 } 207 free(config); 208} 209%} 210 | 203 } 204 205 return (lconfig); 206} 207 208void 209yy_config_free(struct hastd_config *config) 210{ 211 struct hast_resource *res; 212 213 while ((res = TAILQ_FIRST(&config->hc_resources)) != NULL) { 214 TAILQ_REMOVE(&config->hc_resources, res, hr_next); 215 free(res); 216 } 217 free(config); 218} 219%} 220 |
211%token CONTROL LISTEN PORT REPLICATION TIMEOUT EXTENTSIZE RESOURCE NAME LOCAL REMOTE ON | 221%token CONTROL LISTEN PORT REPLICATION TIMEOUT EXEC EXTENTSIZE RESOURCE NAME LOCAL REMOTE ON |
212%token FULLSYNC MEMSYNC ASYNC 213%token NUM STR OB CB 214 215%type <num> replication_type 216 217%union 218{ 219 int num; --- 14 unchanged lines hidden (view full) --- 234 control_statement 235 | 236 listen_statement 237 | 238 replication_statement 239 | 240 timeout_statement 241 | | 222%token FULLSYNC MEMSYNC ASYNC 223%token NUM STR OB CB 224 225%type <num> replication_type 226 227%union 228{ 229 int num; --- 14 unchanged lines hidden (view full) --- 244 control_statement 245 | 246 listen_statement 247 | 248 replication_statement 249 | 250 timeout_statement 251 | |
252 exec_statement 253 | |
|
242 node_statement 243 | 244 resource_statement 245 ; 246 247control_statement: CONTROL STR 248 { 249 switch (depth) { --- 83 unchanged lines hidden (view full) --- 333 curres->hr_timeout = $2; 334 break; 335 default: 336 assert(!"timeout at wrong depth level"); 337 } 338 } 339 ; 340 | 254 node_statement 255 | 256 resource_statement 257 ; 258 259control_statement: CONTROL STR 260 { 261 switch (depth) { --- 83 unchanged lines hidden (view full) --- 345 curres->hr_timeout = $2; 346 break; 347 default: 348 assert(!"timeout at wrong depth level"); 349 } 350 } 351 ; 352 |
353exec_statement: EXEC STR 354 { 355 switch (depth) { 356 case 0: 357 if (strlcpy(depth0_exec, $2, sizeof(depth0_exec)) >= 358 sizeof(depth0_exec)) { 359 pjdlog_error("Exec path is too long."); 360 return (1); 361 } 362 break; 363 case 1: 364 if (curres == NULL) 365 break; 366 if (strlcpy(curres->hr_exec, $2, 367 sizeof(curres->hr_exec)) >= 368 sizeof(curres->hr_exec)) { 369 pjdlog_error("Exec path is too long."); 370 return (1); 371 } 372 break; 373 default: 374 assert(!"exec at wrong depth level"); 375 } 376 } 377 ; 378 |
|
341node_statement: ON node_start OB node_entries CB 342 { 343 mynode = false; 344 } 345 ; 346 347node_start: STR 348 { --- 102 unchanged lines hidden (view full) --- 451 sizeof(curres->hr_name)) { 452 pjdlog_error("Resource name is too long."); 453 return (1); 454 } 455 curres->hr_role = HAST_ROLE_INIT; 456 curres->hr_previous_role = HAST_ROLE_INIT; 457 curres->hr_replication = -1; 458 curres->hr_timeout = -1; | 379node_statement: ON node_start OB node_entries CB 380 { 381 mynode = false; 382 } 383 ; 384 385node_start: STR 386 { --- 102 unchanged lines hidden (view full) --- 489 sizeof(curres->hr_name)) { 490 pjdlog_error("Resource name is too long."); 491 return (1); 492 } 493 curres->hr_role = HAST_ROLE_INIT; 494 curres->hr_previous_role = HAST_ROLE_INIT; 495 curres->hr_replication = -1; 496 curres->hr_timeout = -1; |
497 curres->hr_exec[0] = '\0'; |
|
459 curres->hr_provname[0] = '\0'; 460 curres->hr_localpath[0] = '\0'; 461 curres->hr_localfd = -1; 462 curres->hr_remoteaddr[0] = '\0'; 463 curres->hr_ggateunit = -1; 464 } 465 ; 466 467resource_entries: 468 | 469 resource_entries resource_entry 470 ; 471 472resource_entry: 473 replication_statement 474 | 475 timeout_statement 476 | | 498 curres->hr_provname[0] = '\0'; 499 curres->hr_localpath[0] = '\0'; 500 curres->hr_localfd = -1; 501 curres->hr_remoteaddr[0] = '\0'; 502 curres->hr_ggateunit = -1; 503 } 504 ; 505 506resource_entries: 507 | 508 resource_entries resource_entry 509 ; 510 511resource_entry: 512 replication_statement 513 | 514 timeout_statement 515 | |
516 exec_statement 517 | |
|
477 name_statement 478 | 479 local_statement 480 | 481 resource_node_statement 482 ; 483 484name_statement: NAME STR --- 106 unchanged lines hidden --- | 518 name_statement 519 | 520 local_statement 521 | 522 resource_node_statement 523 ; 524 525name_statement: NAME STR --- 106 unchanged lines hidden --- |