/* * * Time stuff * */ void Delay (Time_t d) { thread_t *t; t = (thread_t*)current_process; time_inc (t->time, d); }
/* ---------------------------------------------------------------------- */ gint sd_ipvssync_save_fullcfg(GPtrArray *VCfgArr, gboolean force) { guint i, j, currwgt; CfgVirtual *virt; CfgReal *real; FILE *ipvsfile; gchar buf[80]; struct timeval ctime; gboolean save = TRUE; gboolean complete = FALSE; /* all virtuals tested? */ if (force) LOGINFO("Startup - full ipvs config forced"); gettimeofday(&ctime, NULL); if (G_no_sync) return 1; if (!force && full_sync_time.tv_sec != 0 && !TIME_HAS_COME(full_sync_time, ctime)) return 1; else full_sync_time = ctime; if (!force && !complete) { /* test if all virtuals were tested at least once */ for (i = 0; i < VCfgArr->len ; i++) save &= ((CfgVirtual *) g_ptr_array_index(VCfgArr, i))->tested; if (!save) return 1; complete = TRUE; } if (!force && !save) return 1; time_inc(&full_sync_time, FULL_SYNC_DELAY, 0); lock_ipvssync(); if (!(ipvsfile = fopen(G_full_sync_file, "w"))){ LOGERROR( "\n\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" "@@@ UNABLE TO OPEN FULL SYNC FILE:\n@@@ %s" "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n", G_full_sync_file); exit(1); } strftime(buf, 80, "meta version=1.0 mdate=%F mtime=%T\n\n", localtime(&ctime.tv_sec)); fprintf(ipvsfile, "%s", buf); if (diff_sync_filename) free(diff_sync_filename); diff_sync_filename = g_strdup_printf("%s/diff_sync.%u", G_diff_sync_dir, (unsigned) ctime.tv_sec); fprintf(ipvsfile, "DIFF file=%s\n\n", diff_sync_filename); /* save latest diff filename */ if (diff_sync_file) { fprintf(diff_sync_file, "DIFF file=%s\n", diff_sync_filename); /* switch to diff */ fclose(diff_sync_file); } if (!(diff_sync_file = fopen(diff_sync_filename, "w"))) { LOGERROR( "\n\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" "@@@ UNABLE TO OPEN DIFF SYNC FILE:\n@@@ %s" "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n", diff_sync_filename); fclose(ipvsfile); exit(1); } for (i = 0; i < VCfgArr->len; i++) { virt = g_ptr_array_index(VCfgArr, i); fprintf(ipvsfile, "virtual vname=%s vproto=%s vaddr=%s vport=%d vrt=%s vsched=%s", virt->name, sd_proto_str(virt->ipvs_proto), virt->addrtxt, ntohs(virt->port), sd_rt_str(virt->ipvs_rt), virt->ipvs_sched); if (virt->ipvs_persistent) fprintf(ipvsfile," vpers=%u", virt->ipvs_persistent); if (virt->ipvs_fwmark) fprintf(ipvsfile," vfwmark=%d", virt->ipvs_fwmark); if (virt->ipvs_ops && virt->ipvs_proto == SD_IPVS_UDP) fprintf(ipvsfile," vops=%u", (unsigned) virt->ipvs_ops); fprintf(ipvsfile, "\n"); if (virt->realArr) { for (j = 0; j < virt->realArr->len; j++) { real = g_ptr_array_index(virt->realArr, j); LOGDEBUG("real %s:%s, state %s, rstate %s", real->virt->name, real->name, GBOOLSTR(real->online), sd_rstate_str(real->rstate)); currwgt = sd_ipvssync_calculate_real_weight(real, TRUE); if (real->rstate == REAL_DOWN) { LOGDEBUG("Real down - skipping from output"); continue; } if (real->online || !real->tester->remove_on_fail) { fprintf(ipvsfile, "real rname=%s", real->name); fprintf(ipvsfile, " raddr=%s rport=%d", real->addrtxt, ntohs(real->port)); fprintf(ipvsfile, " rweight=%d", currwgt); if (real->ipvs_lthresh > 0) fprintf(ipvsfile, " rl_thresh=%d", real->ipvs_lthresh); if (real->ipvs_uthresh > 0) fprintf(ipvsfile, " ru_thresh=%d", real->ipvs_uthresh); /* if real has rt overwrite, write rrt */ if (virt->ipvs_rt != real->ipvs_rt) fprintf(ipvsfile, " rrt=%s", sd_rt_str(real->ipvs_rt)); fprintf(ipvsfile, "\n"); } } fprintf(ipvsfile, "\n"); } } fclose(ipvsfile); if (force) LOGINFO("Full ipvssync config saved [%s]", G_full_sync_file); else LOGDEBUG("Full ipvssync config saved [%s]", G_full_sync_file); if (force) touch_fullreload(); unlock_ipvssync(); return 0; }