parse.y (244538) | parse.y (246922) |
---|---|
1%{ 2/*- 3 * Copyright (c) 2009-2010 The FreeBSD Foundation 4 * Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net> 5 * All rights reserved. 6 * 7 * This software was developed by Pawel Jakub Dawidek under sponsorship from 8 * the FreeBSD Foundation. --- 14 unchanged lines hidden (view full) --- 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * | 1%{ 2/*- 3 * Copyright (c) 2009-2010 The FreeBSD Foundation 4 * Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net> 5 * All rights reserved. 6 * 7 * This software was developed by Pawel Jakub Dawidek under sponsorship from 8 * the FreeBSD Foundation. --- 14 unchanged lines hidden (view full) --- 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * |
31 * $FreeBSD: head/sbin/hastd/parse.y 244538 2012-12-21 15:54:13Z kevlo $ | 31 * $FreeBSD: head/sbin/hastd/parse.y 246922 2013-02-17 21:12:34Z pjd $ |
32 */ 33 34#include <sys/param.h> /* MAXHOSTNAMELEN */ 35#include <sys/queue.h> 36#include <sys/socket.h> 37#include <sys/sysctl.h> 38 39#include <arpa/inet.h> --- 191 unchanged lines hidden (view full) --- 231 { 232 switch (depth) { 233 case 0: 234 depth0_replication = $2; 235 break; 236 case 1: 237 PJDLOG_ASSERT(curres != NULL); 238 curres->hr_replication = $2; | 32 */ 33 34#include <sys/param.h> /* MAXHOSTNAMELEN */ 35#include <sys/queue.h> 36#include <sys/socket.h> 37#include <sys/sysctl.h> 38 39#include <arpa/inet.h> --- 191 unchanged lines hidden (view full) --- 231 { 232 switch (depth) { 233 case 0: 234 depth0_replication = $2; 235 break; 236 case 1: 237 PJDLOG_ASSERT(curres != NULL); 238 curres->hr_replication = $2; |
239 curres->hr_original_replication = $2; |
|
239 break; 240 default: 241 PJDLOG_ABORT("replication at wrong depth level"); 242 } 243 } 244 ; 245 246replication_type: --- 281 unchanged lines hidden (view full) --- 528 free(curres); 529 free($1); 530 return (1); 531 } 532 free($1); 533 curres->hr_role = HAST_ROLE_INIT; 534 curres->hr_previous_role = HAST_ROLE_INIT; 535 curres->hr_replication = -1; | 240 break; 241 default: 242 PJDLOG_ABORT("replication at wrong depth level"); 243 } 244 } 245 ; 246 247replication_type: --- 281 unchanged lines hidden (view full) --- 529 free(curres); 530 free($1); 531 return (1); 532 } 533 free($1); 534 curres->hr_role = HAST_ROLE_INIT; 535 curres->hr_previous_role = HAST_ROLE_INIT; 536 curres->hr_replication = -1; |
537 curres->hr_original_replication = -1; |
|
536 curres->hr_checksum = -1; 537 curres->hr_compression = -1; | 538 curres->hr_checksum = -1; 539 curres->hr_compression = -1; |
540 curres->hr_version = 1; |
|
538 curres->hr_timeout = -1; 539 curres->hr_exec[0] = '\0'; 540 curres->hr_provname[0] = '\0'; 541 curres->hr_localpath[0] = '\0'; 542 curres->hr_localfd = -1; 543 curres->hr_localflush = true; 544 curres->hr_metaflush = -1; 545 curres->hr_remoteaddr[0] = '\0'; --- 173 unchanged lines hidden (view full) --- 719 ; 720 721%% 722 723static int 724isitme(const char *name) 725{ 726 char buf[MAXHOSTNAMELEN]; | 541 curres->hr_timeout = -1; 542 curres->hr_exec[0] = '\0'; 543 curres->hr_provname[0] = '\0'; 544 curres->hr_localpath[0] = '\0'; 545 curres->hr_localfd = -1; 546 curres->hr_localflush = true; 547 curres->hr_metaflush = -1; 548 curres->hr_remoteaddr[0] = '\0'; --- 173 unchanged lines hidden (view full) --- 722 ; 723 724%% 725 726static int 727isitme(const char *name) 728{ 729 char buf[MAXHOSTNAMELEN]; |
730 unsigned long hostid; |
|
727 char *pos; 728 size_t bufsize; 729 730 /* 731 * First check if the given name matches our full hostname. 732 */ 733 if (gethostname(buf, sizeof(buf)) < 0) { 734 pjdlog_errno(LOG_ERR, "gethostname() failed"); 735 return (-1); 736 } 737 if (strcmp(buf, name) == 0) 738 return (1); 739 740 /* | 731 char *pos; 732 size_t bufsize; 733 734 /* 735 * First check if the given name matches our full hostname. 736 */ 737 if (gethostname(buf, sizeof(buf)) < 0) { 738 pjdlog_errno(LOG_ERR, "gethostname() failed"); 739 return (-1); 740 } 741 if (strcmp(buf, name) == 0) 742 return (1); 743 744 /* |
741 * Now check if it matches first part of the host name. | 745 * Check if it matches first part of the host name. |
742 */ 743 pos = strchr(buf, '.'); 744 if (pos != NULL && (size_t)(pos - buf) == strlen(name) && 745 strncmp(buf, name, pos - buf) == 0) { 746 return (1); 747 } 748 749 /* | 746 */ 747 pos = strchr(buf, '.'); 748 if (pos != NULL && (size_t)(pos - buf) == strlen(name) && 749 strncmp(buf, name, pos - buf) == 0) { 750 return (1); 751 } 752 753 /* |
750 * At the end check if name is equal to our host's UUID. | 754 * Check if it matches host UUID. |
751 */ 752 bufsize = sizeof(buf); 753 if (sysctlbyname("kern.hostuuid", buf, &bufsize, NULL, 0) < 0) { 754 pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostuuid) failed"); 755 return (-1); 756 } 757 if (strcasecmp(buf, name) == 0) 758 return (1); 759 760 /* | 755 */ 756 bufsize = sizeof(buf); 757 if (sysctlbyname("kern.hostuuid", buf, &bufsize, NULL, 0) < 0) { 758 pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostuuid) failed"); 759 return (-1); 760 } 761 if (strcasecmp(buf, name) == 0) 762 return (1); 763 764 /* |
765 * Check if it matches hostid. 766 */ 767 bufsize = sizeof(hostid); 768 if (sysctlbyname("kern.hostid", &hostid, &bufsize, NULL, 0) < 0) { 769 pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostid) failed"); 770 return (-1); 771 } 772 (void)snprintf(buf, sizeof(buf), "hostid%lu", hostid); 773 if (strcmp(buf, name) == 0) 774 return (1); 775 776 /* |
|
761 * Looks like this isn't about us. 762 */ 763 return (0); 764} 765 766static bool 767family_supported(int family) 768{ 769 int sock; 770 771 sock = socket(family, SOCK_STREAM, 0); | 777 * Looks like this isn't about us. 778 */ 779 return (0); 780} 781 782static bool 783family_supported(int family) 784{ 785 int sock; 786 787 sock = socket(family, SOCK_STREAM, 0); |
772 if (sock == -1 && errno == EAFNOSUPPORT) | 788 if (sock == -1 && errno == EPROTONOSUPPORT) |
773 return (false); 774 if (sock >= 0) 775 (void)close(sock); 776 return (true); 777} 778 779static int 780node_names(char **namesp) 781{ 782 static char names[MAXHOSTNAMELEN * 3]; 783 char buf[MAXHOSTNAMELEN]; | 789 return (false); 790 if (sock >= 0) 791 (void)close(sock); 792 return (true); 793} 794 795static int 796node_names(char **namesp) 797{ 798 static char names[MAXHOSTNAMELEN * 3]; 799 char buf[MAXHOSTNAMELEN]; |
800 unsigned long hostid; |
|
784 char *pos; 785 size_t bufsize; 786 787 if (gethostname(buf, sizeof(buf)) < 0) { 788 pjdlog_errno(LOG_ERR, "gethostname() failed"); 789 return (-1); 790 } 791 --- 11 unchanged lines hidden (view full) --- 803 804 /* Host UUID. */ 805 bufsize = sizeof(buf); 806 if (sysctlbyname("kern.hostuuid", buf, &bufsize, NULL, 0) < 0) { 807 pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostuuid) failed"); 808 return (-1); 809 } 810 (void)strlcat(names, buf, sizeof(names)); | 801 char *pos; 802 size_t bufsize; 803 804 if (gethostname(buf, sizeof(buf)) < 0) { 805 pjdlog_errno(LOG_ERR, "gethostname() failed"); 806 return (-1); 807 } 808 --- 11 unchanged lines hidden (view full) --- 820 821 /* Host UUID. */ 822 bufsize = sizeof(buf); 823 if (sysctlbyname("kern.hostuuid", buf, &bufsize, NULL, 0) < 0) { 824 pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostuuid) failed"); 825 return (-1); 826 } 827 (void)strlcat(names, buf, sizeof(names)); |
828 (void)strlcat(names, ", ", sizeof(names)); |
|
811 | 829 |
830 /* Host ID. */ 831 bufsize = sizeof(hostid); 832 if (sysctlbyname("kern.hostid", &hostid, &bufsize, NULL, 0) < 0) { 833 pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostid) failed"); 834 return (-1); 835 } 836 (void)snprintf(buf, sizeof(buf), "hostid%lu", hostid); 837 (void)strlcat(names, buf, sizeof(names)); 838 |
|
812 *namesp = names; 813 814 return (0); 815} 816 817void 818yyerror(const char *str) 819{ --- 8 unchanged lines hidden (view full) --- 828 int ret; 829 830 curres = NULL; 831 mynode = false; 832 depth = 0; 833 lineno = 0; 834 835 depth0_timeout = HAST_TIMEOUT; | 839 *namesp = names; 840 841 return (0); 842} 843 844void 845yyerror(const char *str) 846{ --- 8 unchanged lines hidden (view full) --- 855 int ret; 856 857 curres = NULL; 858 mynode = false; 859 depth = 0; 860 lineno = 0; 861 862 depth0_timeout = HAST_TIMEOUT; |
836 depth0_replication = HAST_REPLICATION_FULLSYNC; | 863 depth0_replication = HAST_REPLICATION_MEMSYNC; |
837 depth0_checksum = HAST_CHECKSUM_NONE; 838 depth0_compression = HAST_COMPRESSION_HOLE; 839 strlcpy(depth0_control, HAST_CONTROL, sizeof(depth0_control)); 840 strlcpy(depth0_pidfile, HASTD_PIDFILE, sizeof(depth0_pidfile)); 841 TAILQ_INIT(&depth0_listen); 842 strlcpy(depth0_listen_tcp4, HASTD_LISTEN_TCP4, 843 sizeof(depth0_listen_tcp4)); 844 strlcpy(depth0_listen_tcp6, HASTD_LISTEN_TCP6, --- 93 unchanged lines hidden (view full) --- 938 PJDLOG_ASSERT(curres->hr_remoteaddr[0] != '\0'); 939 940 if (curres->hr_replication == -1) { 941 /* 942 * Replication is not set at resource-level. 943 * Use global or default setting. 944 */ 945 curres->hr_replication = depth0_replication; | 864 depth0_checksum = HAST_CHECKSUM_NONE; 865 depth0_compression = HAST_COMPRESSION_HOLE; 866 strlcpy(depth0_control, HAST_CONTROL, sizeof(depth0_control)); 867 strlcpy(depth0_pidfile, HASTD_PIDFILE, sizeof(depth0_pidfile)); 868 TAILQ_INIT(&depth0_listen); 869 strlcpy(depth0_listen_tcp4, HASTD_LISTEN_TCP4, 870 sizeof(depth0_listen_tcp4)); 871 strlcpy(depth0_listen_tcp6, HASTD_LISTEN_TCP6, --- 93 unchanged lines hidden (view full) --- 965 PJDLOG_ASSERT(curres->hr_remoteaddr[0] != '\0'); 966 967 if (curres->hr_replication == -1) { 968 /* 969 * Replication is not set at resource-level. 970 * Use global or default setting. 971 */ 972 curres->hr_replication = depth0_replication; |
973 curres->hr_original_replication = depth0_replication; |
|
946 } | 974 } |
947 if (curres->hr_replication == HAST_REPLICATION_MEMSYNC) { 948 pjdlog_warning("Replication mode \"%s\" is not implemented, falling back to \"%s\".", 949 "memsync", "fullsync"); 950 curres->hr_replication = HAST_REPLICATION_FULLSYNC; 951 } | |
952 if (curres->hr_checksum == -1) { 953 /* 954 * Checksum is not set at resource-level. 955 * Use global or default setting. 956 */ 957 curres->hr_checksum = depth0_checksum; 958 } 959 if (curres->hr_compression == -1) { --- 53 unchanged lines hidden --- | 975 if (curres->hr_checksum == -1) { 976 /* 977 * Checksum is not set at resource-level. 978 * Use global or default setting. 979 */ 980 curres->hr_checksum = depth0_checksum; 981 } 982 if (curres->hr_compression == -1) { --- 53 unchanged lines hidden --- |