primary.c (216494) | primary.c (217784) |
---|---|
1/*- 2 * Copyright (c) 2009 The FreeBSD Foundation 3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org> 4 * All rights reserved. 5 * 6 * This software was developed by Pawel Jakub Dawidek under sponsorship from 7 * the FreeBSD Foundation. 8 * --- 15 unchanged lines hidden (view full) --- 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 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2009 The FreeBSD Foundation 3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org> 4 * All rights reserved. 5 * 6 * This software was developed by Pawel Jakub Dawidek under sponsorship from 7 * the FreeBSD Foundation. 8 * --- 15 unchanged lines hidden (view full) --- 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 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/sbin/hastd/primary.c 216494 2010-12-16 19:48:03Z pjd $"); | 32__FBSDID("$FreeBSD: head/sbin/hastd/primary.c 217784 2011-01-24 15:04:15Z pjd $"); |
33 34#include <sys/types.h> 35#include <sys/time.h> 36#include <sys/bio.h> 37#include <sys/disk.h> 38#include <sys/refcount.h> 39#include <sys/stat.h> 40 --- 790 unchanged lines hidden (view full) --- 831 setproctitle("%s (primary)", res->hr_name); 832 833 /* Declare that we are sender. */ 834 proto_send(res->hr_event, NULL, 0); 835 836 init_local(res); 837 init_ggate(res); 838 init_environment(res); | 33 34#include <sys/types.h> 35#include <sys/time.h> 36#include <sys/bio.h> 37#include <sys/disk.h> 38#include <sys/refcount.h> 39#include <sys/stat.h> 40 --- 790 unchanged lines hidden (view full) --- 831 setproctitle("%s (primary)", res->hr_name); 832 833 /* Declare that we are sender. */ 834 proto_send(res->hr_event, NULL, 0); 835 836 init_local(res); 837 init_ggate(res); 838 init_environment(res); |
839 |
|
839 /* 840 * Create the guard thread first, so we can handle signals from the 841 * very begining. 842 */ 843 error = pthread_create(&td, NULL, guard_thread, res); 844 assert(error == 0); 845 /* 846 * Create the control thread before sending any event to the parent, --- 992 unchanged lines hidden (view full) --- 1839 pjdlog_debug(2, "sync: (%p) Moving request to the free queue.", 1840 hio); 1841 QUEUE_INSERT2(hio, free); 1842 } 1843 /* NOTREACHED */ 1844 return (NULL); 1845} 1846 | 840 /* 841 * Create the guard thread first, so we can handle signals from the 842 * very begining. 843 */ 844 error = pthread_create(&td, NULL, guard_thread, res); 845 assert(error == 0); 846 /* 847 * Create the control thread before sending any event to the parent, --- 992 unchanged lines hidden (view full) --- 1840 pjdlog_debug(2, "sync: (%p) Moving request to the free queue.", 1841 hio); 1842 QUEUE_INSERT2(hio, free); 1843 } 1844 /* NOTREACHED */ 1845 return (NULL); 1846} 1847 |
1847static void 1848config_reload(void) | 1848void 1849primary_config_reload(struct hast_resource *res, struct nv *nv) |
1849{ | 1850{ |
1850 struct hastd_config *newcfg; 1851 struct hast_resource *res; | |
1852 unsigned int ii, ncomps; | 1851 unsigned int ii, ncomps; |
1853 int modified; | 1852 int modified, vint; 1853 const char *vstr; |
1854 1855 pjdlog_info("Reloading configuration..."); 1856 | 1854 1855 pjdlog_info("Reloading configuration..."); 1856 |
1857 assert(res->hr_role == HAST_ROLE_PRIMARY); 1858 assert(gres == res); 1859 nv_assert(nv, "remoteaddr"); 1860 nv_assert(nv, "replication"); 1861 nv_assert(nv, "timeout"); 1862 nv_assert(nv, "exec"); 1863 |
|
1857 ncomps = HAST_NCOMPONENTS; 1858 | 1864 ncomps = HAST_NCOMPONENTS; 1865 |
1859 newcfg = yy_config_parse(cfgpath, false); 1860 if (newcfg == NULL) 1861 goto failed; 1862 1863 TAILQ_FOREACH(res, &newcfg->hc_resources, hr_next) { 1864 if (strcmp(res->hr_name, gres->hr_name) == 0) 1865 break; 1866 } 1867 /* 1868 * If resource was removed from the configuration file, resource 1869 * name, provider name or path to local component was modified we 1870 * shouldn't be here. This means that someone modified configuration 1871 * file and send SIGHUP to us instead of main hastd process. 1872 * Log advice and ignore the signal. 1873 */ 1874 if (res == NULL || strcmp(gres->hr_name, res->hr_name) != 0 || 1875 strcmp(gres->hr_provname, res->hr_provname) != 0 || 1876 strcmp(gres->hr_localpath, res->hr_localpath) != 0) { 1877 pjdlog_warning("To reload configuration send SIGHUP to the main hastd process (pid %u).", 1878 (unsigned int)getppid()); 1879 goto failed; 1880 } 1881 | |
1882#define MODIFIED_REMOTEADDR 0x1 1883#define MODIFIED_REPLICATION 0x2 1884#define MODIFIED_TIMEOUT 0x4 1885#define MODIFIED_EXEC 0x8 1886 modified = 0; | 1866#define MODIFIED_REMOTEADDR 0x1 1867#define MODIFIED_REPLICATION 0x2 1868#define MODIFIED_TIMEOUT 0x4 1869#define MODIFIED_EXEC 0x8 1870 modified = 0; |
1887 if (strcmp(gres->hr_remoteaddr, res->hr_remoteaddr) != 0) { | 1871 1872 vstr = nv_get_string(nv, "remoteaddr"); 1873 if (strcmp(gres->hr_remoteaddr, vstr) != 0) { |
1888 /* 1889 * Don't copy res->hr_remoteaddr to gres just yet. 1890 * We want remote_close() to log disconnect from the old 1891 * addresses, not from the new ones. 1892 */ 1893 modified |= MODIFIED_REMOTEADDR; 1894 } | 1874 /* 1875 * Don't copy res->hr_remoteaddr to gres just yet. 1876 * We want remote_close() to log disconnect from the old 1877 * addresses, not from the new ones. 1878 */ 1879 modified |= MODIFIED_REMOTEADDR; 1880 } |
1895 if (gres->hr_replication != res->hr_replication) { 1896 gres->hr_replication = res->hr_replication; | 1881 vint = nv_get_int32(nv, "replication"); 1882 if (gres->hr_replication != vint) { 1883 gres->hr_replication = vint; |
1897 modified |= MODIFIED_REPLICATION; 1898 } | 1884 modified |= MODIFIED_REPLICATION; 1885 } |
1899 if (gres->hr_timeout != res->hr_timeout) { 1900 gres->hr_timeout = res->hr_timeout; | 1886 vint = nv_get_int32(nv, "timeout"); 1887 if (gres->hr_timeout != vint) { 1888 gres->hr_timeout = vint; |
1901 modified |= MODIFIED_TIMEOUT; 1902 } | 1889 modified |= MODIFIED_TIMEOUT; 1890 } |
1903 if (strcmp(gres->hr_exec, res->hr_exec) != 0) { 1904 strlcpy(gres->hr_exec, res->hr_exec, sizeof(gres->hr_exec)); | 1891 vstr = nv_get_string(nv, "exec"); 1892 if (strcmp(gres->hr_exec, vstr) != 0) { 1893 strlcpy(gres->hr_exec, vstr, sizeof(gres->hr_exec)); |
1905 modified |= MODIFIED_EXEC; 1906 } | 1894 modified |= MODIFIED_EXEC; 1895 } |
1896 |
|
1907 /* 1908 * If only timeout was modified we only need to change it without 1909 * reconnecting. 1910 */ 1911 if (modified == MODIFIED_TIMEOUT) { 1912 for (ii = 0; ii < ncomps; ii++) { 1913 if (!ISREMOTE(ii)) 1914 continue; --- 17 unchanged lines hidden (view full) --- 1932 } else if ((modified & 1933 (MODIFIED_REMOTEADDR | MODIFIED_REPLICATION)) != 0) { 1934 for (ii = 0; ii < ncomps; ii++) { 1935 if (!ISREMOTE(ii)) 1936 continue; 1937 remote_close(gres, ii); 1938 } 1939 if (modified & MODIFIED_REMOTEADDR) { | 1897 /* 1898 * If only timeout was modified we only need to change it without 1899 * reconnecting. 1900 */ 1901 if (modified == MODIFIED_TIMEOUT) { 1902 for (ii = 0; ii < ncomps; ii++) { 1903 if (!ISREMOTE(ii)) 1904 continue; --- 17 unchanged lines hidden (view full) --- 1922 } else if ((modified & 1923 (MODIFIED_REMOTEADDR | MODIFIED_REPLICATION)) != 0) { 1924 for (ii = 0; ii < ncomps; ii++) { 1925 if (!ISREMOTE(ii)) 1926 continue; 1927 remote_close(gres, ii); 1928 } 1929 if (modified & MODIFIED_REMOTEADDR) { |
1940 strlcpy(gres->hr_remoteaddr, res->hr_remoteaddr, | 1930 vstr = nv_get_string(nv, "remoteaddr"); 1931 strlcpy(gres->hr_remoteaddr, vstr, |
1941 sizeof(gres->hr_remoteaddr)); 1942 } 1943 } 1944#undef MODIFIED_REMOTEADDR 1945#undef MODIFIED_REPLICATION 1946#undef MODIFIED_TIMEOUT 1947#undef MODIFIED_EXEC 1948 1949 pjdlog_info("Configuration reloaded successfully."); | 1932 sizeof(gres->hr_remoteaddr)); 1933 } 1934 } 1935#undef MODIFIED_REMOTEADDR 1936#undef MODIFIED_REPLICATION 1937#undef MODIFIED_TIMEOUT 1938#undef MODIFIED_EXEC 1939 1940 pjdlog_info("Configuration reloaded successfully."); |
1950 return; 1951failed: 1952 if (newcfg != NULL) { 1953 if (newcfg->hc_controlconn != NULL) 1954 proto_close(newcfg->hc_controlconn); 1955 if (newcfg->hc_listenconn != NULL) 1956 proto_close(newcfg->hc_listenconn); 1957 yy_config_free(newcfg); 1958 } 1959 pjdlog_warning("Configuration not reloaded."); | |
1960} 1961 1962static void 1963guard_one(struct hast_resource *res, unsigned int ncomp) 1964{ 1965 struct proto_conn *in, *out; 1966 1967 if (!ISREMOTE(ncomp)) --- 59 unchanged lines hidden (view full) --- 2027 time_t lastcheck, now; 2028 sigset_t mask; 2029 int signo; 2030 2031 ncomps = HAST_NCOMPONENTS; 2032 lastcheck = time(NULL); 2033 2034 PJDLOG_VERIFY(sigemptyset(&mask) == 0); | 1941} 1942 1943static void 1944guard_one(struct hast_resource *res, unsigned int ncomp) 1945{ 1946 struct proto_conn *in, *out; 1947 1948 if (!ISREMOTE(ncomp)) --- 59 unchanged lines hidden (view full) --- 2008 time_t lastcheck, now; 2009 sigset_t mask; 2010 int signo; 2011 2012 ncomps = HAST_NCOMPONENTS; 2013 lastcheck = time(NULL); 2014 2015 PJDLOG_VERIFY(sigemptyset(&mask) == 0); |
2035 PJDLOG_VERIFY(sigaddset(&mask, SIGHUP) == 0); | |
2036 PJDLOG_VERIFY(sigaddset(&mask, SIGINT) == 0); 2037 PJDLOG_VERIFY(sigaddset(&mask, SIGTERM) == 0); 2038 2039 timeout.tv_sec = RETRY_SLEEP; 2040 timeout.tv_nsec = 0; 2041 signo = -1; 2042 2043 for (;;) { 2044 switch (signo) { | 2016 PJDLOG_VERIFY(sigaddset(&mask, SIGINT) == 0); 2017 PJDLOG_VERIFY(sigaddset(&mask, SIGTERM) == 0); 2018 2019 timeout.tv_sec = RETRY_SLEEP; 2020 timeout.tv_nsec = 0; 2021 signo = -1; 2022 2023 for (;;) { 2024 switch (signo) { |
2045 case SIGHUP: 2046 config_reload(); 2047 break; | |
2048 case SIGINT: 2049 case SIGTERM: 2050 sigexit_received = true; 2051 primary_exitx(EX_OK, 2052 "Termination signal received, exiting."); 2053 break; 2054 default: 2055 break; --- 14 unchanged lines hidden --- | 2025 case SIGINT: 2026 case SIGTERM: 2027 sigexit_received = true; 2028 primary_exitx(EX_OK, 2029 "Termination signal received, exiting."); 2030 break; 2031 default: 2032 break; --- 14 unchanged lines hidden --- |