Deleted Added
full compact
hastd.c (217729) hastd.c (217784)
1/*-
2 * Copyright (c) 2009-2010 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-2010 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/hastd.c 217729 2011-01-22 22:31:55Z pjd $");
32__FBSDID("$FreeBSD: head/sbin/hastd/hastd.c 217784 2011-01-24 15:04:15Z pjd $");
33
34#include <sys/param.h>
35#include <sys/linker.h>
36#include <sys/module.h>
37#include <sys/wait.h>
38
39#include <assert.h>
40#include <err.h>

--- 159 unchanged lines hidden (view full) ---

200 if (res0->hr_timeout != res1->hr_timeout)
201 return (true);
202 if (strcmp(res0->hr_exec, res1->hr_exec) != 0)
203 return (true);
204 return (false);
205}
206
207static void
33
34#include <sys/param.h>
35#include <sys/linker.h>
36#include <sys/module.h>
37#include <sys/wait.h>
38
39#include <assert.h>
40#include <err.h>

--- 159 unchanged lines hidden (view full) ---

200 if (res0->hr_timeout != res1->hr_timeout)
201 return (true);
202 if (strcmp(res0->hr_exec, res1->hr_exec) != 0)
203 return (true);
204 return (false);
205}
206
207static void
208resource_reload(const struct hast_resource *res)
209{
210 struct nv *nvin, *nvout;
211 int error;
212
213 assert(res->hr_role == HAST_ROLE_PRIMARY);
214
215 nvout = nv_alloc();
216 nv_add_uint8(nvout, HASTCTL_RELOAD, "cmd");
217 nv_add_string(nvout, res->hr_remoteaddr, "remoteaddr");
218 nv_add_int32(nvout, (int32_t)res->hr_replication, "replication");
219 nv_add_int32(nvout, (int32_t)res->hr_timeout, "timeout");
220 nv_add_string(nvout, res->hr_exec, "exec");
221 if (nv_error(nvout) != 0) {
222 nv_free(nvout);
223 pjdlog_error("Unable to allocate header for reload message.");
224 return;
225 }
226 if (hast_proto_send(res, res->hr_ctrl, nvout, NULL, 0) < 0) {
227 pjdlog_errno(LOG_ERR, "Unable to send reload message");
228 nv_free(nvout);
229 return;
230 }
231 nv_free(nvout);
232
233 /* Receive response. */
234 if (hast_proto_recv_hdr(res->hr_ctrl, &nvin) < 0) {
235 pjdlog_errno(LOG_ERR, "Unable to receive reload reply");
236 return;
237 }
238 error = nv_get_int16(nvin, "error");
239 nv_free(nvin);
240 if (error != 0) {
241 pjdlog_common(LOG_ERR, 0, error, "Reload failed");
242 return;
243 }
244}
245
246static void
208hastd_reload(void)
209{
210 struct hastd_config *newcfg;
211 struct hast_resource *nres, *cres, *tres;
212 uint8_t role;
213
214 pjdlog_info("Reloading configuration...");
215

--- 117 unchanged lines hidden (view full) ---

333 pjdlog_info("Resource %s configuration was modified, reloading it.",
334 cres->hr_name);
335 strlcpy(cres->hr_remoteaddr, nres->hr_remoteaddr,
336 sizeof(cres->hr_remoteaddr));
337 cres->hr_replication = nres->hr_replication;
338 cres->hr_timeout = nres->hr_timeout;
339 strlcpy(cres->hr_exec, nres->hr_exec,
340 sizeof(cres->hr_exec));
247hastd_reload(void)
248{
249 struct hastd_config *newcfg;
250 struct hast_resource *nres, *cres, *tres;
251 uint8_t role;
252
253 pjdlog_info("Reloading configuration...");
254

--- 117 unchanged lines hidden (view full) ---

372 pjdlog_info("Resource %s configuration was modified, reloading it.",
373 cres->hr_name);
374 strlcpy(cres->hr_remoteaddr, nres->hr_remoteaddr,
375 sizeof(cres->hr_remoteaddr));
376 cres->hr_replication = nres->hr_replication;
377 cres->hr_timeout = nres->hr_timeout;
378 strlcpy(cres->hr_exec, nres->hr_exec,
379 sizeof(cres->hr_exec));
341 if (cres->hr_workerpid != 0) {
342 if (kill(cres->hr_workerpid, SIGHUP) < 0) {
343 pjdlog_errno(LOG_WARNING,
344 "Unable to send SIGHUP to worker process %u",
345 (unsigned int)cres->hr_workerpid);
346 }
347 }
380 if (cres->hr_workerpid != 0)
381 resource_reload(cres);
348 }
349 }
350
351 yy_config_free(newcfg);
352 pjdlog_info("Configuration reloaded successfully.");
353 return;
354failed:
355 if (newcfg != NULL) {

--- 458 unchanged lines hidden ---
382 }
383 }
384
385 yy_config_free(newcfg);
386 pjdlog_info("Configuration reloaded successfully.");
387 return;
388failed:
389 if (newcfg != NULL) {

--- 458 unchanged lines hidden ---