📄 diskfile.c
字号:
/* check for duplicate disk */ disk = NULL; if (host) { if ((disk = lookup_disk(hostname, diskname)) != NULL) { dup = 1; } else { disk = host->disks; do { if (match_disk(diskname, disk->name) && match_disk(disk->name, diskname)) { dup = 1; } else { disk = disk->hostnext; } } while (dup == 0 && disk != NULL); } if (dup == 1) { disk_parserror(filename, line_num, _("duplicate disk record, previous on line %d"), disk->line); } } if (!disk) { disk = alloc(SIZEOF(disk_t)); disk->line = line_num; disk->hostname = stralloc(hostname); disk->name = diskname; disk->device = diskdevice; disk->spindle = -1; disk->up = NULL; disk->inprogress = 0; } if (host) { sdisk = sanitise_filename(diskname); for (dp = host->disks; dp != NULL; dp = dp->next) { char *sdiskp = sanitise_filename(dp->name); if (strcmp(diskname, dp->name) != 0 && strcmp(sdisk, sdiskp) == 0) { disk_parserror(filename, line_num, _("Two disks are mapping to the same name: \"%s\" and \"%s\"; you must use different diskname"), dp->name, diskname); return(-1); } amfree(sdiskp); } amfree(sdisk); } if (fp[0] == '{') { s[-1] = (char)ch; s = fp+2; skip_whitespace(s, ch); if (ch != '\0' && ch != '#') { disk_parserror(filename, line_num, _("expected line break after `{\', ignoring rest of line")); } if (strchr(s-1, '}') && (strchr(s-1, '#') == NULL || strchr(s-1, '}') < strchr(s-1, '#'))) { disk_parserror(filename, line_num,_("'}' on same line than '{'")); amfree(hostname); if(!dup) { amfree(disk->device); amfree(disk->name); amfree(disk); } else { amfree(diskdevice); amfree(diskname); } return (-1); } dtype = read_dumptype(vstralloc("custom(", hostname, ":", disk->name, ")", NULL), diskf, (char*)filename, line_num_p); if (dtype == NULL || dup) { disk_parserror(filename, line_num, _("read of custom dumptype failed")); amfree(hostname); if(!dup) { amfree(disk->device); amfree(disk->name); amfree(disk); } else { amfree(diskdevice); amfree(diskname); } return (-1); } amfree(line); *line_p = line = agets(diskf); line_num = *line_num_p; /* no incr, read_dumptype did it already */ if (line == NULL) *line_p = line = stralloc(""); s = line; ch = *s++; } else { if((dtype = lookup_dumptype(dumptype)) == NULL) { char *qdt = quote_string(dumptype); disk_parserror(filename, line_num, _("undefined dumptype `%s'"), qdt); amfree(qdt); amfree(dumptype); amfree(hostname); if (!dup) { amfree(disk->device); amfree(disk->name); amfree(disk); } else { amfree(diskdevice); amfree(diskname); } return (-1); } } if (dup) { amfree(hostname); amfree(diskdevice); amfree(diskname); return (-1); } disk->dtype_name = dumptype_name(dtype); disk->program = dumptype_get_program(dtype); disk->exclude_list = duplicate_sl(dumptype_get_exclude(dtype).sl_list); disk->exclude_file = duplicate_sl(dumptype_get_exclude(dtype).sl_file); disk->exclude_optional = dumptype_get_exclude(dtype).optional; disk->include_list = duplicate_sl(dumptype_get_include(dtype).sl_list); disk->include_file = duplicate_sl(dumptype_get_include(dtype).sl_file); disk->include_optional = dumptype_get_include(dtype).optional; disk->priority = dumptype_get_priority(dtype); disk->dumpcycle = dumptype_get_dumpcycle(dtype);/* disk->frequency = dumptype_get_frequency(dtype);*/ disk->security_driver = dumptype_get_security_driver(dtype); disk->maxdumps = dumptype_get_maxdumps(dtype); disk->tape_splitsize = dumptype_get_tape_splitsize(dtype); disk->split_diskbuffer = dumptype_get_split_diskbuffer(dtype); disk->fallback_splitsize = dumptype_get_fallback_splitsize(dtype); disk->maxpromoteday = dumptype_get_maxpromoteday(dtype); disk->bumppercent = dumptype_get_bumppercent(dtype); disk->bumpsize = dumptype_get_bumpsize(dtype); disk->bumpdays = dumptype_get_bumpdays(dtype); disk->bumpmult = dumptype_get_bumpmult(dtype); disk->starttime = dumptype_get_starttime(dtype); disk->start_t = 0; if (disk->starttime > 0) { st = time(NULL); disk->start_t = st; stm = localtime(&st); disk->start_t -= stm->tm_sec + 60 * stm->tm_min + 3600 * stm->tm_hour; disk->start_t += disk->starttime / 100 * 3600 + disk->starttime % 100 * 60; if ((disk->start_t - st) < -43200) disk->start_t += 86400; } disk->strategy = dumptype_get_strategy(dtype); disk->ignore = dumptype_get_ignore(dtype); disk->estimate = dumptype_get_estimate(dtype); disk->compress = dumptype_get_compress(dtype); disk->srvcompprog = dumptype_get_srvcompprog(dtype); disk->clntcompprog = dumptype_get_clntcompprog(dtype); disk->encrypt = dumptype_get_encrypt(dtype); disk->srv_decrypt_opt = dumptype_get_srv_decrypt_opt(dtype); disk->clnt_decrypt_opt = dumptype_get_clnt_decrypt_opt(dtype); disk->srv_encrypt = dumptype_get_srv_encrypt(dtype); disk->clnt_encrypt = dumptype_get_clnt_encrypt(dtype); disk->amandad_path = dumptype_get_amandad_path(dtype); disk->client_username = dumptype_get_client_username(dtype); disk->ssh_keys = dumptype_get_ssh_keys(dtype); disk->comprate[0] = dumptype_get_comprate(dtype)[0]; disk->comprate[1] = dumptype_get_comprate(dtype)[1]; /* * Boolean parameters with no value (Appears here as value 2) defaults * to TRUE for backward compatibility and for logical consistency. */ disk->record = dumptype_get_record(dtype) != 0; disk->skip_incr = dumptype_get_skip_incr(dtype) != 0; disk->skip_full = dumptype_get_skip_full(dtype) != 0; disk->to_holdingdisk = dumptype_get_to_holdingdisk(dtype); disk->kencrypt = dumptype_get_kencrypt(dtype) != 0; disk->index = dumptype_get_index(dtype) != 0; disk->todo = 1; skip_whitespace(s, ch); fp = s - 1; if(ch && ch != '#') { /* get optional spindle number */ char *fp1; int is_digit=1; skip_non_whitespace(s, ch); s[-1] = '\0'; fp1=fp; if (*fp1 == '-') fp1++; for(;*fp1!='\0';fp1++) { if(!isdigit((int)*fp1)) { is_digit = 0; } } if(is_digit == 0) { disk_parserror(filename, line_num, _("non-integer spindle `%s'"), fp); amfree(hostname); amfree(disk->name); amfree(disk); return (-1); } disk->spindle = atoi(fp); skip_integer(s, ch); } skip_whitespace(s, ch); fp = s - 1; if(ch && ch != '#') { /* get optional network interface */ skip_non_whitespace(s, ch); s[-1] = '\0'; if((cfg_if = lookup_interface(upcase(fp))) == NULL) { disk_parserror(filename, line_num, _("undefined network interface `%s'"), fp); amfree(hostname); amfree(disk->name); amfree(disk); return (-1); } } else { cfg_if = lookup_interface("default"); } /* see if we already have a netif_t for this interface */ for (netif = all_netifs; netif != NULL; netif = netif->next) { if (netif->config == cfg_if) break; } /* nope; make up a new one */ if (!netif) { netif = alloc(sizeof(*netif)); netif->next = all_netifs; all_netifs = netif; netif->config = cfg_if; netif->curusage = 0; } skip_whitespace(s, ch); if(ch && ch != '#') { /* now we have garbage, ignore it */ disk_parserror(filename, line_num, _("end of line expected")); } if(dumptype_get_ignore(dtype) || dumptype_get_strategy(dtype) == DS_SKIP) { disk->todo = 0; } /* success, add disk to lists */ if(host == NULL) { /* new host */ host = alloc(SIZEOF(am_host_t)); host->next = hostlist; hostlist = host; host->hostname = hostname; hostname = NULL; host->disks = NULL; host->inprogress = 0; host->maxdumps = 1; /* will be overwritten */ host->netif = NULL; host->start_t = 0; host->up = NULL; host->features = NULL; } else { amfree(hostname); } host->netif = netif; enqueue_disk(lst, disk); disk->host = host; disk->hostnext = host->disks; host->disks = disk; host->maxdumps = disk->maxdumps; return (0);}printf_arglist_function2(void disk_parserror, const char *, filename, int, line_num, const char *, format){ va_list argp; const char *xlated_fmt = gettext(format); /* print error message */ g_fprintf(stderr, "\"%s\", line %d: ", filename, line_num); arglist_start(argp, format); g_vfprintf(stderr, xlated_fmt, argp); arglist_end(argp); fputc('\n', stderr);}voiddump_queue( char * st, disklist_t q, int npr, /* we print first npr disks on queue, plus last two */ FILE * f){ disk_t *d,*p; int pos; char *qname; if(empty(q)) { g_fprintf(f, _("%s QUEUE: empty\n"), st); return; } g_fprintf(f, _("%s QUEUE:\n"), st); for(pos = 0, d = q.head, p = NULL; d != NULL; p = d, d = d->next, pos++) { qname = quote_string(d->name); if(pos < npr) g_fprintf(f, "%3d: %-10s %-4s\n", pos, d->host->hostname, qname); amfree(qname); } if(pos > npr) { if(pos > npr+2) g_fprintf(f, " ...\n"); if(pos > npr+1) { d = p->prev; g_fprintf(f, "%3d: %-10s %-4s\n", pos-2, d->host->hostname, d->name); } d = p; g_fprintf(f, "%3d: %-10s %-4s\n", pos-1, d->host->hostname, d->name); }}char *optionstr( disk_t * dp, am_feature_t * their_features, FILE * fdout){ char *auth_opt = NULL; char *kencrypt_opt = ""; char *compress_opt = ""; char *encrypt_opt = stralloc(""); char *decrypt_opt = stralloc(""); char *record_opt = ""; char *index_opt = ""; char *exclude_file = NULL; char *exclude_list = NULL; char *include_file = NULL; char *include_list = NULL; char *excl_opt = ""; char *incl_opt = ""; char *exc = NULL; char *result = NULL; sle_t *excl; int nb_exclude_file; int nb_include_file; char *qdpname; char *qname; int err=0; assert(dp != NULL); assert(dp->host != NULL); qdpname = quote_string(dp->name); if(am_has_feature(dp->host->features, fe_options_auth)) { auth_opt = vstralloc("auth=", dp->security_driver, ";", NULL); } else if(strcasecmp(dp->security_driver, "bsd") == 0) { if(am_has_feature(dp->host->features, fe_options_bsd_auth)) auth_opt = stralloc("bsd-auth;"); else if(fdout) { g_fprintf(fdout, _("WARNING: %s:%s does not support auth or bsd-auth\n"), dp->host->hostname, qdpname); } } else if(strcasecmp(dp->security_driver, "krb4") == 0) { if(am_has_feature(dp->host->features, fe_options_krb4_auth)) auth_opt = stralloc("krb4-auth;"); else if(fdout) { g_fprintf(fdout, _("WARNING: %s:%s does not support auth or krb4-auth\n"), dp->host->hostname, qdpname); } if(dp->kencrypt) { if(am_has_feature(dp->host->features, fe_options_kencrypt)) { kencrypt_opt = "kencrypt;"; } else if(fdout) { g_fprintf(fdout, _("WARNING: %s:%s does not support kencrypt\n"), dp->host->hostname, qdpname); } } } switch(dp->compress) { case COMP_FAST: if(am_has_feature(their_features, fe_options_compress_fast)) { compress_opt = "compress-fast;"; } else if(fdout) { g_fprintf(fdout, _("WARNING: %s:%s does not support fast compression\n"), dp->host->hostname, qdpname); } break; case COMP_BEST: if(am_has_feature(their_features, fe_options_compress_best)) { compress_opt = "compress-best;"; } else if(fdout) { g_fprintf(fdout, _("WARNING: %s:%s does not support best compression\n"), dp->host->hostname, qdpname); } break; case COMP_CUST: if(am_has_feature(their_features, fe_options_compress_cust)) { compress_opt = vstralloc("comp-cust=", dp->clntcompprog, ";", NULL); if (BSTRNCMP(compress_opt, "comp-cust=;") == 0){ if(fdout) { g_fprintf(fdout, _("ERROR: %s:%s client custom compression with no compression program specified\n"), dp->host->hostname, qdpname); } err++; } } else if(fdout) { g_fprintf(fdout, _("WARNING: %s:%s does not support client custom compression\n"), dp->host->hostname, qdpname); } break; case COMP_SERVER_FAST: if(am_has_feature(their_features, fe_options_srvcomp_fast)) { compress_opt = "srvcomp-fast;"; } break; case COMP_SERVER_BEST: if(am_has_feature(their_features, fe_options_srvcomp_best)) { compress_opt = "srvcomp-best;"; } break; case COMP_SERVER_CUST: if(am_has_feature(their_features, fe_options_srvcomp_cust)) { compress_opt = vstralloc("srvcomp-cust=", dp->srvcompprog, ";", NULL); if (BSTRNCMP(compress_opt, "srvcomp-cust=;") == 0){ if(fdout) { g_fprintf(fdout, _("ERROR: %s:%s server custom compression with no compression program specified\n"), dp->host->hostname, qdpname); } err++; } } else if(fdout) { g_fprintf(fdout, _("WARNING: %s:%s does not support server custom compression\n"), dp->host->hostname, qdpname); } break; } switch(dp->encrypt) { case ENCRYPT_CUST: if(am_has_feature(their_features, fe_options_encrypt_cust)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -