📄 amcheck.c
字号:
quoted, strerror(errno)); disklow = 1; amfree(quoted); continue; } /* do the division first to avoid potential integer overflow */ if (fsusage.fsu_bavail_top_bit_set) kb_avail = 0; else kb_avail = fsusage.fsu_bavail / 1024 * fsusage.fsu_blocksize; if(access(holdingdisk_get_diskdir(hdp), W_OK) == -1) { g_fprintf(outf, _("ERROR: holding disk %s: not writable: %s.\n"), quoted, strerror(errno)); g_fprintf(outf, _("Check permissions\n")); disklow = 1; } else if(access(holdingdisk_get_diskdir(hdp), X_OK) == -1) { g_fprintf(outf, _("ERROR: holding disk %s: not searcheable: %s.\n"), quoted, strerror(errno)); g_fprintf(outf, _("Check permissions of ancestors of %s\n"), quoted); disklow = 1; } else if(holdingdisk_get_disksize(hdp) > (off_t)0) { if(kb_avail == 0) { g_fprintf(outf, _("WARNING: holding disk %s: " "no space available (%lld %sB requested)\n"), quoted, (long long)(holdingdisk_get_disksize(hdp)/(off_t)unitdivisor), displayunit); disklow = 1; } else if(kb_avail < holdingdisk_get_disksize(hdp)) { g_fprintf(outf, _("WARNING: holding disk %s: " "only %lld %sB available (%lld %sB requested)\n"), quoted, (long long)(kb_avail / (off_t)unitdivisor), displayunit, (long long)(holdingdisk_get_disksize(hdp)/(off_t)unitdivisor), displayunit); disklow = 1; } else { g_fprintf(outf, _("Holding disk %s: %lld %sB disk space available," " using %lld %sB as requested\n"), quoted, (long long)(kb_avail / (off_t)unitdivisor), displayunit, (long long)(holdingdisk_get_disksize(hdp)/(off_t)unitdivisor), displayunit); } } else { if(kb_avail < -holdingdisk_get_disksize(hdp)) { g_fprintf(outf, _("WARNING: holding disk %s: " "only %lld %sB free, using nothing\n"), quoted, (long long)(kb_avail / (off_t)unitdivisor), displayunit); g_fprintf(outf, _("WARNING: Not enough free space specified in amanda.conf\n")); disklow = 1; } else { g_fprintf(outf, _("Holding disk %s: %lld %sB disk space available, using %lld %sB\n"), quoted, (long long)(kb_avail/(off_t)unitdivisor), displayunit, (long long)((kb_avail + holdingdisk_get_disksize(hdp)) / (off_t)unitdivisor), displayunit); } } amfree(quoted); } } /* check that the log file is writable if it already exists */ if(do_localchk) { char *conf_logdir; char *logfile; char *olddir; struct stat stat_old; struct stat statbuf; conf_logdir = config_dir_relative(getconf_str(CNF_LOGDIR)); logfile = vstralloc(conf_logdir, "/log", NULL); quoted = quote_string(conf_logdir); if(stat(conf_logdir, &statbuf) == -1) { g_fprintf(outf, _("ERROR: logdir %s (%s), you must create directory.\n"), quoted, strerror(errno)); disklow = 1; } else if(access(conf_logdir, W_OK) == -1) { g_fprintf(outf, _("ERROR: log dir %s: not writable\n"), quoted); logbad = 1; } amfree(quoted); if(access(logfile, F_OK) == 0) { testtape = 0; logbad = 2; if(access(logfile, W_OK) != 0) { quoted = quote_string(logfile); g_fprintf(outf, _("ERROR: log file %s: not writable\n"), quoted); amfree(quoted); } } olddir = vstralloc(conf_logdir, "/oldlog", NULL); quoted = quote_string(olddir); if (stat(olddir,&stat_old) == 0) { /* oldlog exist */ if(!(S_ISDIR(stat_old.st_mode))) { g_fprintf(outf, _("ERROR: oldlog directory %s is not a directory\n"), quoted); g_fprintf(outf, _("Remove the entry and create a new directory\n")); logbad = 1; } if(access(olddir, W_OK) == -1) { g_fprintf(outf, _("ERROR: oldlog dir %s: not writable\n"), quoted); g_fprintf(outf, _("Check permissions\n")); logbad = 1; } } else if(lstat(olddir,&stat_old) == 0) { g_fprintf(outf, _("ERROR: oldlog directory %s is not a directory\n"), quoted); g_fprintf(outf, _("Remove the entry and create a new directory\n")); logbad = 1; } amfree(quoted); if (testtape) { logfile = newvstralloc(logfile, conf_logdir, "/amdump", NULL); if (access(logfile, F_OK) == 0) { testtape = 0; logbad = 2; } } amfree(olddir); amfree(logfile); amfree(conf_logdir); } if (testtape) { tapebad = !test_tape_status(outf); } else if (do_tapechk) { g_fprintf(outf, _("WARNING: skipping tape test because amdump or amflush seem to be running\n")); g_fprintf(outf, _("WARNING: if they are not, you must run amcleanup\n")); } else if (logbad == 2) { g_fprintf(outf, _("WARNING: amdump or amflush seem to be running\n")); g_fprintf(outf, _("WARNING: if they are not, you must run amcleanup\n")); } else { g_fprintf(outf, _("NOTE: skipping tape checks\n")); } /* * See if the information file and index directory for each client * and disk is OK. Since we may be seeing clients and/or disks for * the first time, these are just warnings, not errors. */ if(do_localchk) { char *conf_infofile; char *conf_indexdir; char *hostinfodir = NULL; char *hostindexdir = NULL; char *diskdir = NULL; char *infofile = NULL; struct stat statbuf; disk_t *dp; am_host_t *hostp; int indexdir_checked = 0; int hostindexdir_checked = 0; char *host; char *disk; int conf_tapecycle, conf_runspercycle; conf_tapecycle = getconf_int(CNF_TAPECYCLE); conf_runspercycle = getconf_int(CNF_RUNSPERCYCLE); if(conf_tapecycle <= conf_runspercycle) { g_fprintf(outf, _("WARNING: tapecycle (%d) <= runspercycle (%d).\n"), conf_tapecycle, conf_runspercycle); } conf_infofile = config_dir_relative(getconf_str(CNF_INFOFILE)); conf_indexdir = config_dir_relative(getconf_str(CNF_INDEXDIR)); quoted = quote_string(conf_infofile); if(stat(conf_infofile, &statbuf) == -1) { if (errno == ENOENT) { g_fprintf(outf, _("NOTE: conf info dir %s does not exist\n"), quoted); g_fprintf(outf, _("NOTE: it will be created on the next run.\n")); } else { g_fprintf(outf, _("ERROR: conf info dir %s (%s)\n"), quoted, strerror(errno)); infobad = 1; } amfree(conf_infofile); } else if (!S_ISDIR(statbuf.st_mode)) { g_fprintf(outf, _("ERROR: info dir %s: not a directory\n"), quoted); g_fprintf(outf, _("Remove the entry and create a new directory\n")); amfree(conf_infofile); infobad = 1; } else if (access(conf_infofile, W_OK) == -1) { g_fprintf(outf, _("ERROR: info dir %s: not writable\n"), quoted); g_fprintf(outf, _("Check permissions\n")); amfree(conf_infofile); infobad = 1; } else { char *errmsg = NULL; if (check_infofile(conf_infofile, &origq, &errmsg) == -1) { g_fprintf(outf, "ERROR: Can't copy infofile: %s\n", errmsg); infobad = 1; amfree(errmsg); } strappend(conf_infofile, "/"); } amfree(quoted); while(!empty(origq)) { hostp = origq.head->host; host = sanitise_filename(hostp->hostname); if(conf_infofile) { hostinfodir = newstralloc2(hostinfodir, conf_infofile, host); quoted = quote_string(hostinfodir); if(stat(hostinfodir, &statbuf) == -1) { if (errno == ENOENT) { g_fprintf(outf, _("NOTE: host info dir %s does not exist\n"), quoted); g_fprintf(outf, _("NOTE: it will be created on the next run.\n")); } else { g_fprintf(outf, _("ERROR: host info dir %s (%s)\n"), quoted, strerror(errno)); infobad = 1; } amfree(hostinfodir); } else if (!S_ISDIR(statbuf.st_mode)) { g_fprintf(outf, _("ERROR: info dir %s: not a directory\n"), quoted); g_fprintf(outf, _("Remove the entry and create a new directory\n")); amfree(hostinfodir); infobad = 1; } else if (access(hostinfodir, W_OK) == -1) { g_fprintf(outf, _("ERROR: info dir %s: not writable\n"), quoted); g_fprintf(outf, _("Check permissions\n")); amfree(hostinfodir); infobad = 1; } else { strappend(hostinfodir, "/"); } amfree(quoted); } for(dp = hostp->disks; dp != NULL; dp = dp->hostnext) { disk = sanitise_filename(dp->name); if(hostinfodir) { char *quotedif; diskdir = newstralloc2(diskdir, hostinfodir, disk); infofile = vstralloc(diskdir, "/", "info", NULL); quoted = quote_string(diskdir); quotedif = quote_string(infofile); if(stat(diskdir, &statbuf) == -1) { if (errno == ENOENT) { g_fprintf(outf, _("NOTE: info dir %s does not exist\n"), quoted); g_fprintf(outf, _("NOTE: it will be created on the next run.\n")); } else { g_fprintf(outf, _("ERROR: info dir %s (%s)\n"), quoted, strerror(errno)); infobad = 1; } } else if (!S_ISDIR(statbuf.st_mode)) { g_fprintf(outf, _("ERROR: info dir %s: not a directory\n"), quoted); g_fprintf(outf, _("Remove the entry and create a new directory\n")); infobad = 1; } else if (access(diskdir, W_OK) == -1) { g_fprintf(outf, _("ERROR: info dir %s: not writable\n"), quoted); g_fprintf(outf,_("Check permissions\n")); infobad = 1; } else if(stat(infofile, &statbuf) == -1) { if (errno == ENOENT) { g_fprintf(outf, _("NOTE: info file %s does not exist\n"), quotedif); g_fprintf(outf, _("NOTE: it will be created on the next run.\n")); } else { g_fprintf(outf, _("ERROR: info dir %s (%s)\n"), quoted, strerror(errno)); infobad = 1; } } else if (!S_ISREG(statbuf.st_mode)) { g_fprintf(outf, _("ERROR: info file %s: not a file\n"), quotedif); g_fprintf(outf, _("Remove the entry and create a new file\n")); infobad = 1; } else if (access(infofile, R_OK) == -1) { g_fprintf(outf, _("ERROR: info file %s: not readable\n"), quotedif); infobad = 1; } amfree(quotedif); amfree(quoted); amfree(infofile); } if(dp->index) { if(! indexdir_checked) { quoted = quote_string(conf_indexdir); if(stat(conf_indexdir, &statbuf) == -1) { if (errno == ENOENT) { g_fprintf(outf, _("NOTE: index dir %s does not exist\n"), quoted); g_fprintf(outf, _("NOTE: it will be created on the next run.\n")); } else { g_fprintf(outf, _("ERROR: index dir %s (%s)\n"), quoted, strerror(errno)); indexbad = 1; } amfree(conf_indexdir); } else if (!S_ISDIR(statbuf.st_mode)) { g_fprintf(outf, _("ERROR: index dir %s: not a directory\n"), quoted); g_fprintf(outf, _("Remove the entry and create a new directory\n")); amfree(conf_indexdir); indexbad = 1; } else if (access(conf_indexdir, W_OK) == -1) { g_fprintf(outf, _("ERROR: index dir %s: not writable\n"), quoted); amfree(conf_indexdir); indexbad = 1; } else { strappend(conf_indexdir, "/"); } indexdir_checked = 1; amfree(quoted); } if(conf_indexdir) { if(! hostindexdir_checked) { hostindexdir = stralloc2(conf_indexdir, host); quoted = quote_string(hostindexdir); if(stat(hostindexdir, &statbuf) == -1) { if (errno == ENOENT) { g_fprintf(outf, _("NOTE: index dir %s does not exist\n"), quoted); g_fprintf(outf, _("NOTE: it will be created on the next run.\n")); } else { g_fprintf(outf, _("ERROR: index dir %s (%s)\n"), quoted, strerror(errno)); indexbad = 1; } amfree(hostindexdir); } else if (!S_ISDIR(statbuf.st_mode)) { g_fprintf(outf, _("ERROR: index dir %s: not a directory\n"), quoted); g_fprintf(outf, _("Remove the entry and create a new directory\n")); amfree(hostindexdir); indexbad = 1; } else if (access(hostindexdir, W_OK) == -1) { g_fprintf(outf, _("ERROR: index dir %s: not writable\n"), quoted); amfree(hostindexdir); indexbad = 1; } else { strappend(hostindexdir, "/"); } hostindexdir_checked = 1; amfree(quoted); } if(hostindexdir) { diskdir = newstralloc2(diskdir, hostindexdir, disk); quoted = quote_string(diskdir); if(stat(diskdir, &statbuf) == -1) { if (errno == ENOENT) { g_fprintf(outf, _("NOTE: index dir %s does not exist\n"), quoted); g_fprintf(outf, _("NOTE: it will be created on the next run.\n")); } else { g_fprintf(outf, _("ERROR: index dir %s (%s)\n"), quoted, strerror(errno)); indexbad = 1; } } else if (!S_ISDIR(statbuf.st_mode)) { g_fprintf(outf, _("ERROR: index dir %s: not a directory\n"), quoted); g_fprintf(outf, _("Remove the entry and create a new directory\n")); indexbad = 1; } else if (access(diskdir, W_OK) == -1) { g_fprintf(outf, _("ERROR: index dir %s: is not writable\n"), quoted); indexbad = 1; } amfree(quoted); } } } if ( dp->encrypt == ENCRYPT_SERV_CUST ) { if ( dp->srv_encrypt[0] == '\0' ) { g_fprintf(outf, _("ERROR: server encryption program not specified\n")); g_fprintf(outf, _("Specify \"server_custom_encrypt\" in the dumptype\n")); pgmbad = 1; } else if(access(dp->srv_encrypt, X_OK) == -1) { g_fprintf(outf, _("ERROR: %s is not executable, server encryption will not work\n"), dp->srv_encrypt ); g_fprintf(outf, _("Check file type\n")); pgmbad = 1; } } if ( dp->compress == COMP_SERVER_CUST ) { if ( dp->srvcompprog[0] == '\0' ) { g_fprintf(outf, _("ERROR: server custom compression program " "not specified\n")); g_fprintf(outf, _("Specify \"server_custom_compress\" in " "the dumptype\n")); pgmbad = 1; } else if(access(dp->srvcompprog, X_OK) == -1) { quoted = quote_string(dp->srvcompprog); g_fprintf(outf, _("ERROR: %s is not executable, server custom " "compression will not work\n"), quoted); amfree(quoted); g_fprintf(outf, _("Check file type\n")); pgmbad = 1; } } amfree(disk); remove_disk(&origq, dp); } amfree(host); amfree(hostindexdir); hostindexdir_checked = 0; } amfree(diskdir); amfree(hostinfodir); amfree(conf_infofile); amfree(conf_indexdir); } amfree(datestamp); g_fprintf(outf, _("Server check took %s seconds\n"), walltime_str(curclock())); fflush(outf); exit(userbad \ || confbad \ || tapebad \ || disklow \ || logbad \ || infobad \ || indexbad \ || pgmbad); /*NOTREACHED*/ return 0;}/* --------------------------------------------------- */int remote_errors;FILE *outf;static void handle_result(void *, pkt_t *, security_handle_t *);void start_host(am_host_t *hostp);#define HOST_READY ((void *)0) /* must be 0 */#define HOST_ACTIVE ((void *)1)#define HOST_DONE ((void *)2)#define DISK_READY ((void *)0) /* must be 0 */#define DISK_ACTIVE ((void *)1)#define DISK_DONE ((void *)2)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -