4455 if (nvlist_add_string(nvl, VRRP_EVENT_ROUTER_NAME, name) != 0)
4456 goto failed;
4457
4458 if (nvlist_add_uint8(nvl, VRRP_EVENT_STATE, st) != 0)
4459 goto failed;
4460
4461 if (nvlist_add_uint8(nvl, VRRP_EVENT_PREV_STATE, prev_st) != 0)
4462 goto failed;
4463
4464 if (sysevent_post_event(EC_VRRP, ESC_VRRP_STATE_CHANGE,
4465 SUNW_VENDOR, VRRP_EVENT_PUBLISHER, nvl, &eid) == 0) {
4466 nvlist_free(nvl);
4467 return (0);
4468 }
4469
4470 failed:
4471 vrrp_log(VRRP_ERR, "vrrpd_post_event(): `state change (%s --> %s)' "
4472 "sysevent posting failed: %s", vrrp_state2str(prev_st),
4473 vrrp_state2str(st), strerror(errno));
4474
4475 if (nvl != NULL)
4476 nvlist_free(nvl);
4477 return (-1);
4478 }
4479
4480 /*
4481 * timeval processing functions
4482 */
4483 static int
4484 timeval_to_milli(struct timeval tv)
4485 {
4486 return ((int)(tv.tv_sec * 1000 + tv.tv_usec / 1000 + 0.5));
4487 }
4488
4489 static struct timeval
4490 timeval_delta(struct timeval t1, struct timeval t2)
4491 {
4492 struct timeval t;
4493 t.tv_sec = t1.tv_sec - t2.tv_sec;
4494 t.tv_usec = t1.tv_usec - t2.tv_usec;
4495
|
4455 if (nvlist_add_string(nvl, VRRP_EVENT_ROUTER_NAME, name) != 0)
4456 goto failed;
4457
4458 if (nvlist_add_uint8(nvl, VRRP_EVENT_STATE, st) != 0)
4459 goto failed;
4460
4461 if (nvlist_add_uint8(nvl, VRRP_EVENT_PREV_STATE, prev_st) != 0)
4462 goto failed;
4463
4464 if (sysevent_post_event(EC_VRRP, ESC_VRRP_STATE_CHANGE,
4465 SUNW_VENDOR, VRRP_EVENT_PUBLISHER, nvl, &eid) == 0) {
4466 nvlist_free(nvl);
4467 return (0);
4468 }
4469
4470 failed:
4471 vrrp_log(VRRP_ERR, "vrrpd_post_event(): `state change (%s --> %s)' "
4472 "sysevent posting failed: %s", vrrp_state2str(prev_st),
4473 vrrp_state2str(st), strerror(errno));
4474
4475 nvlist_free(nvl);
4476 return (-1);
4477 }
4478
4479 /*
4480 * timeval processing functions
4481 */
4482 static int
4483 timeval_to_milli(struct timeval tv)
4484 {
4485 return ((int)(tv.tv_sec * 1000 + tv.tv_usec / 1000 + 0.5));
4486 }
4487
4488 static struct timeval
4489 timeval_delta(struct timeval t1, struct timeval t2)
4490 {
4491 struct timeval t;
4492 t.tv_sec = t1.tv_sec - t2.tv_sec;
4493 t.tv_usec = t1.tv_usec - t2.tv_usec;
4494
|