void VSL_Delete(struct VSL_data *vsl) { CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC); vbit_destroy(vsl->vbm_select); vbit_destroy(vsl->vbm_supress); vsl_IX_free(&vsl->vslf_select); vsl_IX_free(&vsl->vslf_suppress); VSL_ResetError(vsl); FREE_OBJ(vsl); }
int VUT_Main(void) { struct VSL_cursor *c; int i = -1; AN(VUT.vslq); while (!VUT.sigint) { if (VUT.sighup && VUT.sighup_f) { /* sighup callback */ VUT.sighup = 0; i = (VUT.sighup_f)(); if (i) break; } if (VUT.sigusr1) { /* Flush and report any incomplete records */ VUT.sigusr1 = 0; VSLQ_Flush(VUT.vslq, vut_dispatch, NULL); } if (VUT.vsm != NULL && !VSM_IsOpen(VUT.vsm)) { /* Reconnect VSM */ AZ(VUT.r_arg); VTIM_sleep(0.1); if (VSM_Open(VUT.vsm)) { VSM_ResetError(VUT.vsm); continue; } c = VSL_CursorVSM(VUT.vsl, VUT.vsm, VSL_COPT_TAIL | VSL_COPT_BATCH); if (c == NULL) { VSL_ResetError(VUT.vsl); VSM_Close(VUT.vsm); continue; } VSLQ_SetCursor(VUT.vslq, &c); AZ(c); VUT_Error(0, "Log reacquired"); } i = VSLQ_Dispatch(VUT.vslq, vut_dispatch, NULL); if (i == 1) /* Call again */ continue; else if (i == 0) { /* Nothing to do but wait */ if (VUT.idle_f) { i = (VUT.idle_f)(); if (i) break; } VTIM_sleep(0.01); continue; } else if (i == -1) { /* EOF */ break; } if (VUT.vsm == NULL) break; /* XXX: Make continuation optional */ VSLQ_Flush(VUT.vslq, vut_dispatch, NULL); if (i == -2) /* Abandoned */ VUT_Error(0, "Log abandoned"); else if (i < -2) /* Overrun */ VUT_Error(0, "Log overrun"); VSM_Close(VUT.vsm); } return (i); }
void VUT_Setup(void) { struct VSL_cursor *c; double t_start; int i; AN(VUT.vsl); AZ(VUT.vsm); AZ(VUT.vslq); /* Check input arguments */ if ((VUT.n_arg == NULL ? 0 : 1) + (VUT.N_arg == NULL ? 0 : 1) + (VUT.r_arg == NULL ? 0 : 1) > 1) VUT_Error(1, "Only one of -n, -N and -r options may be used"); /* Create and validate the query expression */ VUT.vslq = VSLQ_New(VUT.vsl, NULL, VUT.g_arg, VUT.q_arg); if (VUT.vslq == NULL) VUT_Error(1, "Query expression error:\n%s", VSL_Error(VUT.vsl)); /* Setup input */ if (VUT.r_arg) { REPLACE(VUT.name, VUT.r_arg); c = VSL_CursorFile(VUT.vsl, VUT.r_arg, 0); if (c == NULL) VUT_Error(1, "Can't open log file (%s)", VSL_Error(VUT.vsl)); } else { VUT.vsm = VSM_New(); AN(VUT.vsm); if (VUT.n_arg && VSM_n_Arg(VUT.vsm, VUT.n_arg) <= 0) VUT_Error(1, "%s", VSM_Error(VUT.vsm)); if (VUT.N_arg && VSM_N_Arg(VUT.vsm, VUT.N_arg) <= 0) VUT_Error(1, "%s", VSM_Error(VUT.vsm)); REPLACE(VUT.name, VSM_Name(VUT.vsm)); t_start = NAN; c = NULL; while (1) { i = VSM_Open(VUT.vsm); if (!i) c = VSL_CursorVSM(VUT.vsl, VUT.vsm, (VUT.d_opt ? VSL_COPT_TAILSTOP : VSL_COPT_TAIL) | VSL_COPT_BATCH); if (c) break; if (isnan(t_start) && VUT.t_arg > 0.) { VUT_Error(0, "Can't open log -" " retrying for %.0f seconds", VUT.t_arg); t_start = VTIM_real(); } VSM_Close(VUT.vsm); if (VUT.t_arg <= 0.) break; if (VTIM_real() - t_start > VUT.t_arg) break; VSM_ResetError(VUT.vsm); VSL_ResetError(VUT.vsl); VTIM_sleep(0.5); } if (VUT.t_arg >= 0. && (i || !c)) { if (i) VUT_Error(1, "Can't open VSM file (%s)", VSM_Error(VUT.vsm)); else VUT_Error(1, "Can't open log (%s)", VSL_Error(VUT.vsl)); } else if (!isnan(t_start)) VUT_Error(0, "Log opened"); } if (c) VSLQ_SetCursor(VUT.vslq, &c); AZ(c); /* Signal handlers */ (void)signal(SIGHUP, vut_sighup); (void)signal(SIGINT, vut_sigint); (void)signal(SIGTERM, vut_sigint); (void)signal(SIGUSR1, vut_sigusr1); /* Open PID file */ if (VUT.P_arg) { AZ(VUT.pfh); VUT.pfh = VPF_Open(VUT.P_arg, 0644, NULL); if (VUT.pfh == NULL) VUT_Error(1, "%s: %s", VUT.P_arg, strerror(errno)); } /* Daemon mode */ if (VUT.D_opt && varnish_daemon(0, 0) == -1) VUT_Error(1, "Daemon mode: %s", strerror(errno)); /* Write PID and setup exit handler */ if (VUT.pfh != NULL) { VPF_Write(VUT.pfh); AZ(atexit(vut_vpf_remove)); } }