GSList * cmdline_match_holding( GSList *dumpspec_list) { dumpspec_t *de; GSList *li, *hi; GSList *holding_files; GSList *matching_files = NULL; dumpfile_t file; holding_files = holding_get_files(NULL, 1); for (hi = holding_files; hi != NULL; hi = hi->next) { /* TODO add level */ if (!holding_file_get_dumpfile((char *)hi->data, &file)) continue; if (file.type != F_DUMPFILE) { dumpfile_free_data(&file); continue; } for (li = dumpspec_list; li != NULL; li = li->next) { de = (dumpspec_t *)(li->data); if (de->host && de->host[0] && !match_host(de->host, file.name)) continue; if (de->disk && de->disk[0] && !match_disk(de->disk, file.disk)) continue; if (de->datestamp && de->datestamp[0] && !match_datestamp(de->datestamp, file.datestamp)) continue; matching_files = g_slist_append(matching_files, g_strdup((char *)hi->data)); break; } dumpfile_free_data(&file); } slist_free_full(holding_files, g_free); return matching_files; }
GSList * holding_get_files_for_flush( GSList *dateargs) { GSList *file_list, *file_elt; GSList *date; int date_matches; dumpfile_t file; GSList *result_list = NULL; /* loop over *all* files, checking each one's datestamp against the expressions * in dateargs */ file_list = holding_get_files(NULL, 1); for (file_elt = file_list; file_elt != NULL; file_elt = file_elt->next) { /* get info on that file */ if (!holding_file_get_dumpfile((char *)file_elt->data, &file)) continue; if (file.type != F_DUMPFILE) { dumpfile_free_data(&file); continue; } if (dateargs) { date_matches = 0; /* loop over date args, until we find a match */ for (date = dateargs; date !=NULL; date = date->next) { if (g_str_equal((char *)date->data, file.datestamp)) { date_matches = 1; break; } } } else { /* if no date list was provided, then all dates match */ date_matches = 1; } if (!date_matches) { dumpfile_free_data(&file); continue; } /* passed all tests -- we'll flush this file */ result_list = g_slist_insert_sorted(result_list, g_strdup(file_elt->data), g_compare_strings); dumpfile_free_data(&file); } if (file_list) slist_free_full(file_list, g_free); return result_list; }
GSList * holding_get_all_datestamps(void) { GSList *all_files, *file; GSList *datestamps = NULL; /* enumerate all files */ all_files = holding_get_files(NULL, 1); for (file = all_files; file != NULL; file = file->next) { dumpfile_t dfile; if (!holding_file_get_dumpfile((char *)file->data, &dfile)) continue; if (!g_slist_find_custom(datestamps, dfile.datestamp, g_compare_strings)) { datestamps = g_slist_insert_sorted(datestamps, g_strdup(dfile.datestamp), g_compare_strings); } dumpfile_free_data(&dfile); } slist_free_full(all_files, g_free); return datestamps; }
/* Recurse over all holding chunks in a holding file. * * Call per_chunk_fn for each chunk of the given file * * datap is passed, unchanged, to all holding_walk_fns. * * @param hfile: holding file to examine (fully qualified path) * @param datap: generic user-data pointer * @param per_chunk_fn: function to call for each holding chunk */ static void holding_walk_file( char *hfile, gpointer datap, holding_walk_fn per_chunk_fn) { dumpfile_t file; char *filename = NULL; /* Loop through all cont_filenames (subsequent chunks) */ filename = g_strdup(hfile); while (filename != NULL && filename[0] != '\0') { int is_cruft = 0; /* get the header to look for cont_filename */ if (!holding_file_get_dumpfile(filename, &file)) { is_cruft = 1; } if (per_chunk_fn) per_chunk_fn(datap, hfile, filename, filename, is_cruft); amfree(filename); /* and go on to the next chunk if this wasn't cruft */ if (!is_cruft) filename = g_strdup(file.cont_filename); dumpfile_free_data(&file); } amfree(filename); }
off_t holding_file_size( char *hfile, int strip_headers) { dumpfile_t file; char *filename; off_t size = (off_t)0; struct stat finfo; /* (note: we don't use holding_get_file_chunks here because that would * entail opening each file twice) */ /* Loop through all cont_filenames (subsequent chunks) */ filename = g_strdup(hfile); while (filename != NULL && filename[0] != '\0') { /* stat the file for its size */ if (stat(filename, &finfo) == -1) { dbprintf(_("stat %s: %s\n"), filename, strerror(errno)); size = -1; break; } size += (finfo.st_size+(off_t)1023)/(off_t)1024; if (strip_headers) size -= (off_t)(DISK_BLOCK_BYTES / 1024); /* get the header to look for cont_filename */ if (!holding_file_get_dumpfile(filename, &file)) { dbprintf(_("holding_file_size: open of %s failed.\n"), filename); size = -1; break; } /* on to the next chunk */ g_free(filename); filename = g_strdup(file.cont_filename); dumpfile_free_data(&file); } amfree(filename); return size; }
void holding_set_from_driver( char *holding_file, off_t orig_size, crc_t native_crc, crc_t client_crc, crc_t server_crc) { int fd; size_t buflen; char buffer[DISK_BLOCK_BYTES]; char *read_buffer; dumpfile_t file; if((fd = robust_open(holding_file, O_RDWR, 0)) == -1) { dbprintf(_("holding_set_origsize: open of %s failed: %s\n"), holding_file, strerror(errno)); return; } buflen = read_fully(fd, buffer, sizeof(buffer), NULL); if (buflen <= 0) { dbprintf(_("holding_set_origsize: %s: empty file?\n"), holding_file); close(fd); return; } parse_file_header(buffer, &file, (size_t)buflen); lseek(fd, (off_t)0, SEEK_SET); file.orig_size = orig_size; file.native_crc = native_crc; file.client_crc = client_crc; file.server_crc = server_crc; read_buffer = build_header(&file, NULL, DISK_BLOCK_BYTES); full_write(fd, read_buffer, DISK_BLOCK_BYTES); dumpfile_free_data(&file); amfree(read_buffer); close(fd); }
void dumpfile_free(dumpfile_t* info) { dumpfile_free_data(info); amfree(info); }
int rename_tmp_holding( char * holding_file, int complete) { int fd; size_t buflen; char buffer[DISK_BLOCK_BYTES]; dumpfile_t file; char *filename; char *filename_tmp = NULL; memset(buffer, 0, sizeof(buffer)); filename = g_strdup(holding_file); while(filename != NULL && filename[0] != '\0') { g_free(filename_tmp); filename_tmp = g_strconcat(filename, ".tmp", NULL); if((fd = robust_open(filename_tmp,O_RDONLY, 0)) == -1) { dbprintf(_("rename_tmp_holding: open of %s failed: %s\n"),filename_tmp,strerror(errno)); amfree(filename); amfree(filename_tmp); return 0; } buflen = read_fully(fd, buffer, sizeof(buffer), NULL); close(fd); if(rename(filename_tmp, filename) != 0) { dbprintf(_("rename_tmp_holding: could not rename \"%s\" to \"%s\": %s"), filename_tmp, filename, strerror(errno)); } if (buflen <= 0) { dbprintf(_("rename_tmp_holding: %s: empty file?\n"), filename); amfree(filename); amfree(filename_tmp); return 0; } parse_file_header(buffer, &file, (size_t)buflen); if(complete == 0 ) { char * header; if((fd = robust_open(filename, O_RDWR, 0)) == -1) { dbprintf(_("rename_tmp_holdingX: open of %s failed: %s\n"), filename, strerror(errno)); dumpfile_free_data(&file); amfree(filename); amfree(filename_tmp); return 0; } file.is_partial = 1; if (debug_holding > 1) dump_dumpfile_t(&file); header = build_header(&file, NULL, DISK_BLOCK_BYTES); if (!header) /* this shouldn't happen */ error(_("header does not fit in %zd bytes"), (size_t)DISK_BLOCK_BYTES); if (full_write(fd, header, DISK_BLOCK_BYTES) != DISK_BLOCK_BYTES) { dbprintf(_("rename_tmp_holding: writing new header failed: %s"), strerror(errno)); dumpfile_free_data(&file); amfree(filename); amfree(filename_tmp); free(header); close(fd); return 0; } free(header); close(fd); } g_free(filename); filename = g_strdup(file.cont_filename); dumpfile_free_data(&file); } amfree(filename); amfree(filename_tmp); return 1; }
static int holding_cleanup_file( gpointer datap, G_GNUC_UNUSED char *base, char *element, char *fqpath, int is_cruft) { holding_cleanup_datap_t *data = (holding_cleanup_datap_t *)datap; int stat; int l; dumpfile_t file; disk_t *dp; if (is_cruft) { if (data->verbose_output) g_fprintf(data->verbose_output, _("Invalid holding file '%s'\n"), element); return 0; } stat = holding_file_get_dumpfile(fqpath, &file); if (!stat) { if (data->verbose_output) g_fprintf(data->verbose_output, _("Could not read read header from '%s'\n"), element); dumpfile_free_data(&file); return 0; } if (file.type != F_DUMPFILE && file.type != F_CONT_DUMPFILE) { if (data->verbose_output) g_fprintf(data->verbose_output, _("File '%s' is not a dump file\n"), element); dumpfile_free_data(&file); return 0; } if(file.dumplevel < 0 || file.dumplevel > 399) { if (data->verbose_output) g_fprintf(data->verbose_output, _("File '%s' has invalid level %d\n"), element, file.dumplevel); dumpfile_free_data(&file); return 0; } dp = lookup_disk(file.name, file.disk); if (dp == NULL) { if (data->verbose_output) g_fprintf(data->verbose_output, _("File '%s' is for '%s:%s', which is not in the disklist\n"), element, file.name, file.disk); dumpfile_free_data(&file); return 0; } if ((l = strlen(element)) >= 7 && g_str_has_prefix(&element[l - 4], ".tmp")) { char *destname; /* generate a name without '.tmp' */ destname = g_strdup(fqpath); destname[strlen(destname) - 4] = '\0'; /* OK, it passes muster -- rename it to salvage some data, * and mark the DLE as corrupted */ if (data->verbose_output) g_fprintf(data->verbose_output, _("Processing partial holding file '%s'\n"), element); if(rename_tmp_holding(destname, 0)) { if (data->corrupt_dle) data->corrupt_dle(dp->host->hostname, dp->name); } else { dbprintf(_("rename_tmp_holding(%s) failed\n"), destname); if (data->verbose_output) g_fprintf(data->verbose_output, _("Rename of '%s' to '%s' failed.\n"), element, destname); } amfree(destname); } dumpfile_free_data(&file); return 1; }
/* Recurse over all holding files in a holding directory. * * Call per_file_fn for each file, and so on, stopping at the level given by * stop_at. * * datap is passed, unchanged, to all holding_walk_fns. * * @param hdir: holding directory to examine (fully qualified path) * @param datap: generic user-data pointer * @param stop_at: do not proceed beyond this level of the hierarchy * @param per_file_fn: function to call for each holding file * @param per_chunk_fn: function to call for each holding chunk */ static void holding_walk_dir( char *hdir, gpointer datap, stop_at_t stop_at, holding_walk_fn per_file_fn, holding_walk_fn per_chunk_fn) { DIR *dir; struct dirent *workdir; char *hfile = NULL; dumpfile_t dumpf; int dumpf_ok; int proceed = 1; if ((dir = opendir(hdir)) == NULL) { if (errno != ENOENT) dbprintf(_("Warning: could not open holding dir %s: %s\n"), hdir, strerror(errno)); return; } while ((workdir = readdir(dir)) != NULL) { int is_cruft = 0; if (is_dot_or_dotdot(workdir->d_name)) continue; /* expected cruft */ g_free(hfile); hfile = g_strconcat(hdir, "/", workdir->d_name, NULL); /* filter out various undesirables */ if (is_emptyfile(hfile)) is_cruft = 1; if (is_dir(hfile)) { is_cruft= 1; } if (!(dumpf_ok=holding_file_get_dumpfile(hfile, &dumpf)) || dumpf.type != F_DUMPFILE) { if (dumpf_ok && dumpf.type == F_CONT_DUMPFILE) { dumpfile_free_data(&dumpf); continue; /* silently skip expected file */ } is_cruft = 1; } if (dumpf.dumplevel < 0 || dumpf.dumplevel > 9) { is_cruft = 1; } if (per_file_fn) proceed = per_file_fn(datap, hdir, workdir->d_name, hfile, is_cruft); if (!is_cruft && proceed && stop_at != STOP_AT_FILE) holding_walk_file(hfile, datap, per_chunk_fn); dumpfile_free_data(&dumpf); } closedir(dir); amfree(hfile); }
int main( int argc, char ** argv) { int foreground; int batch; int redirect; char **datearg = NULL; int nb_datearg = 0; char *conf_diskfile; char *conf_tapelist; char *conf_logfile; int conf_usetimestamps; disklist_t diskq; disk_t *dp; pid_t pid; pid_t driver_pid, reporter_pid; amwait_t exitcode; int opt; GSList *holding_list=NULL, *holding_file; int driver_pipe[2]; char date_string[100]; char date_string_standard[100]; time_t today; char *errstr; struct tm *tm; char *tapedev; char *tpchanger; char *qdisk, *qhname; GSList *datestamp_list = NULL; config_overrides_t *cfg_ovr; char **config_options; find_result_t *holding_files; disklist_t holding_disklist = { NULL, NULL }; /* * Configure program for internationalization: * 1) Only set the message locale for now. * 2) Set textdomain for all amanda related programs to "amanda" * We don't want to be forced to support dozens of message catalogs. */ setlocale(LC_MESSAGES, "C"); textdomain("amanda"); safe_fd(-1, 0); safe_cd(); set_pname("amflush"); /* Don't die when child closes pipe */ signal(SIGPIPE, SIG_IGN); dbopen(DBG_SUBDIR_SERVER); add_amanda_log_handler(amanda_log_stderr); foreground = 0; batch = 0; redirect = 1; /* process arguments */ cfg_ovr = new_config_overrides(argc/2); while((opt = getopt(argc, argv, "bfso:D:")) != EOF) { switch(opt) { case 'b': batch = 1; break; case 'f': foreground = 1; break; case 's': redirect = 0; break; case 'o': add_config_override_opt(cfg_ovr, optarg); break; case 'D': if (datearg == NULL) datearg = g_malloc(21*sizeof(char *)); if(nb_datearg == 20) { g_fprintf(stderr,_("maximum of 20 -D arguments.\n")); exit(1); } datearg[nb_datearg++] = g_strdup(optarg); datearg[nb_datearg] = NULL; break; } } argc -= optind, argv += optind; if(!foreground && !redirect) { g_fprintf(stderr,_("Can't redirect to stdout/stderr if not in forground.\n")); exit(1); } if(argc < 1) { error(_("Usage: amflush [-b] [-f] [-s] [-D date]* [-o configoption]* <confdir> [host [disk]* ]*")); /*NOTREACHED*/ } set_config_overrides(cfg_ovr); config_init(CONFIG_INIT_EXPLICIT_NAME, argv[0]); conf_diskfile = config_dir_relative(getconf_str(CNF_DISKFILE)); read_diskfile(conf_diskfile, &diskq); amfree(conf_diskfile); if (config_errors(NULL) >= CFGERR_WARNINGS) { config_print_errors(); if (config_errors(NULL) >= CFGERR_ERRORS) { g_critical(_("errors processing config file")); } } check_running_as(RUNNING_AS_DUMPUSER); dbrename(get_config_name(), DBG_SUBDIR_SERVER); /* load DLEs from the holding disk, in case there's anything to flush there */ search_holding_disk(&holding_files, &holding_disklist); /* note that the dumps are added to the global disklist, so we need not * consult holding_files or holding_disklist after this. The holding-only * dumps will be filtered properly by match_disklist, setting the dp->todo * flag appropriately. */ errstr = match_disklist(&diskq, argc-1, argv+1); if (errstr) { g_printf(_("%s"),errstr); amfree(errstr); } conf_tapelist = config_dir_relative(getconf_str(CNF_TAPELIST)); if(read_tapelist(conf_tapelist)) { error(_("could not load tapelist \"%s\""), conf_tapelist); /*NOTREACHED*/ } amfree(conf_tapelist); conf_usetimestamps = getconf_boolean(CNF_USETIMESTAMPS); amflush_datestamp = get_datestamp_from_time(0); if(conf_usetimestamps == 0) { amflush_timestamp = g_strdup(amflush_datestamp); } else { amflush_timestamp = get_timestamp_from_time(0); } conf_logdir = config_dir_relative(getconf_str(CNF_LOGDIR)); conf_logfile = g_strjoin(NULL, conf_logdir, "/log", NULL); if (access(conf_logfile, F_OK) == 0) { run_amcleanup(get_config_name()); } if (access(conf_logfile, F_OK) == 0) { char *process_name = get_master_process(conf_logfile); error(_("%s exists: %s is already running, or you must run amcleanup"), conf_logfile, process_name); /*NOTREACHED*/ } driver_program = g_strjoin(NULL, amlibexecdir, "/", "driver", NULL); reporter_program = g_strjoin(NULL, sbindir, "/", "amreport", NULL); logroll_program = g_strjoin(NULL, amlibexecdir, "/", "amlogroll", NULL); tapedev = getconf_str(CNF_TAPEDEV); tpchanger = getconf_str(CNF_TPCHANGER); if (tapedev == NULL && tpchanger == NULL) { error(_("No tapedev or tpchanger specified")); } /* if dates were specified (-D), then use match_datestamp * against the list of all datestamps to turn that list * into a set of existing datestamps (basically, evaluate the * expressions into actual datestamps) */ if(datearg) { GSList *all_datestamps; GSList *datestamp; int i, ok; all_datestamps = holding_get_all_datestamps(); for(datestamp = all_datestamps; datestamp != NULL; datestamp = datestamp->next) { ok = 0; for(i=0; i<nb_datearg && ok==0; i++) { ok = match_datestamp(datearg[i], (char *)datestamp->data); } if (ok) datestamp_list = g_slist_insert_sorted(datestamp_list, g_strdup((char *)datestamp->data), g_compare_strings); } slist_free_full(all_datestamps, g_free); } else { /* otherwise, in batch mode, use all datestamps */ if(batch) { datestamp_list = holding_get_all_datestamps(); } /* or allow the user to pick datestamps */ else { datestamp_list = pick_datestamp(); } } if(!datestamp_list) { g_printf(_("Could not find any Amanda directories to flush.\n")); exit(1); } holding_list = holding_get_files_for_flush(datestamp_list); if (holding_list == NULL) { g_printf(_("Could not find any valid dump image, check directory.\n")); exit(1); } if (access(conf_logfile, F_OK) == 0) { char *process_name = get_master_process(conf_logfile); error(_("%s exists: someone started %s"), conf_logfile, process_name); /*NOTREACHED*/ } log_add(L_INFO, "%s pid %ld", get_pname(), (long)getpid()); if(!batch) confirm(datestamp_list); for(dp = diskq.head; dp != NULL; dp = dp->next) { if(dp->todo) { char *qname; qname = quote_string(dp->name); log_add(L_DISK, "%s %s", dp->host->hostname, qname); amfree(qname); } } if(!foreground) { /* write it before redirecting stdout */ puts(_("Running in background, you can log off now.")); puts(_("You'll get mail when amflush is finished.")); } if(redirect) redirect_stderr(); if(!foreground) detach(); add_amanda_log_handler(amanda_log_stderr); add_amanda_log_handler(amanda_log_trace_log); today = time(NULL); tm = localtime(&today); if (tm) { strftime(date_string, 100, "%a %b %e %H:%M:%S %Z %Y", tm); strftime(date_string_standard, 100, "%Y-%m-%d %H:%M:%S %Z", tm); } else { error(_("BAD DATE")); /* should never happen */ } g_fprintf(stderr, _("amflush: start at %s\n"), date_string); g_fprintf(stderr, _("amflush: datestamp %s\n"), amflush_timestamp); g_fprintf(stderr, _("amflush: starttime %s\n"), amflush_timestamp); g_fprintf(stderr, _("amflush: starttime-locale-independent %s\n"), date_string_standard); log_add(L_START, _("date %s"), amflush_timestamp); /* START DRIVER */ if(pipe(driver_pipe) == -1) { error(_("error [opening pipe to driver: %s]"), strerror(errno)); /*NOTREACHED*/ } if((driver_pid = fork()) == 0) { /* * This is the child process. */ dup2(driver_pipe[0], 0); close(driver_pipe[1]); config_options = get_config_options(3); config_options[0] = "driver"; config_options[1] = get_config_name(); config_options[2] = "nodump"; safe_fd(-1, 0); execve(driver_program, config_options, safe_env()); error(_("cannot exec %s: %s"), driver_program, strerror(errno)); /*NOTREACHED*/ } else if(driver_pid == -1) { error(_("cannot fork for %s: %s"), driver_program, strerror(errno)); /*NOTREACHED*/ } driver_stream = fdopen(driver_pipe[1], "w"); if (!driver_stream) { error(_("Can't fdopen: %s"), strerror(errno)); /*NOTREACHED*/ } g_fprintf(driver_stream, "DATE %s\n", amflush_timestamp); for(holding_file=holding_list; holding_file != NULL; holding_file = holding_file->next) { dumpfile_t file; holding_file_get_dumpfile((char *)holding_file->data, &file); if (holding_file_size((char *)holding_file->data, 1) <= 0) { g_debug("%s is empty - ignoring", (char *)holding_file->data); log_add(L_INFO, "%s: removing file with no data.", (char *)holding_file->data); holding_file_unlink((char *)holding_file->data); dumpfile_free_data(&file); continue; } /* search_holding_disk should have already ensured that every * holding dumpfile has an entry in the dynamic disklist */ dp = lookup_disk(file.name, file.disk); assert(dp != NULL); /* but match_disklist may have indicated we should not flush it */ if (dp->todo == 0) continue; qdisk = quote_string(file.disk); qhname = quote_string((char *)holding_file->data); g_fprintf(stderr, "FLUSH %s %s %s %d %s\n", file.name, qdisk, file.datestamp, file.dumplevel, qhname); g_debug("flushing '%s'", (char *)holding_file->data); g_fprintf(driver_stream, "FLUSH %s %s %s %d %s\n", file.name, qdisk, file.datestamp, file.dumplevel, qhname); amfree(qdisk); amfree(qhname); dumpfile_free_data(&file); } g_fprintf(stderr, "ENDFLUSH\n"); fflush(stderr); g_fprintf(driver_stream, "ENDFLUSH\n"); fflush(driver_stream); fclose(driver_stream); /* WAIT DRIVER */ while(1) { if((pid = wait(&exitcode)) == -1) { if(errno == EINTR) { continue; } else { error(_("wait for %s: %s"), driver_program, strerror(errno)); /*NOTREACHED*/ } } else if (pid == driver_pid) { break; } } slist_free_full(datestamp_list, g_free); datestamp_list = NULL; slist_free_full(holding_list, g_free); holding_list = NULL; if(redirect) { /* rename errfile */ char *errfile, *errfilex, *nerrfilex, number[100]; int tapecycle; int maxdays, days; struct stat stat_buf; errfile = g_strjoin(NULL, conf_logdir, "/amflush", NULL); errfilex = NULL; nerrfilex = NULL; tapecycle = getconf_int(CNF_TAPECYCLE); maxdays = tapecycle + 2; days = 1; /* First, find out the last existing errfile, */ /* to avoid ``infinite'' loops if tapecycle is infinite */ g_snprintf(number,100,"%d",days); errfilex = newvstralloc(errfilex, errfile, ".", number, NULL); while ( days < maxdays && stat(errfilex,&stat_buf)==0) { days++; g_snprintf(number,100,"%d",days); errfilex = newvstralloc(errfilex, errfile, ".", number, NULL); } g_snprintf(number,100,"%d",days); errfilex = newvstralloc(errfilex, errfile, ".", number, NULL); nerrfilex = NULL; while (days > 1) { amfree(nerrfilex); nerrfilex = errfilex; days--; g_snprintf(number,100,"%d",days); errfilex = g_strjoin(NULL, errfile, ".", number, NULL); if (rename(errfilex, nerrfilex) != 0) { error(_("cannot rename \"%s\" to \"%s\": %s"), errfilex, nerrfilex, strerror(errno)); /*NOTREACHED*/ } } errfilex = newvstralloc(errfilex, errfile, ".1", NULL); if (rename(errfile,errfilex) != 0) { error(_("cannot rename \"%s\" to \"%s\": %s"), errfilex, nerrfilex, strerror(errno)); /*NOTREACHED*/ } amfree(errfile); amfree(errfilex); amfree(nerrfilex); } /* * Have amreport generate report and send mail. Note that we do * not bother checking the exit status. If it does not work, it * can be rerun. */ if((reporter_pid = fork()) == 0) { /* * This is the child process. */ config_options = get_config_options(3); config_options[0] = "amreport"; config_options[1] = get_config_name(); config_options[2] = "--from-amdump"; safe_fd(-1, 0); execve(reporter_program, config_options, safe_env()); error(_("cannot exec %s: %s"), reporter_program, strerror(errno)); /*NOTREACHED*/ } else if(reporter_pid == -1) { error(_("cannot fork for %s: %s"), reporter_program, strerror(errno)); /*NOTREACHED*/ } while(1) { if((pid = wait(&exitcode)) == -1) { if(errno == EINTR) { continue; } else { error(_("wait for %s: %s"), reporter_program, strerror(errno)); /*NOTREACHED*/ } } else if (pid == reporter_pid) { break; } } log_add(L_INFO, "pid-done %ld", (long)getpid()); /* * Call amlogroll to rename the log file to its datestamped version. * Since we exec at this point, our exit code will be that of amlogroll. */ config_options = get_config_options(2); config_options[0] = "amlogroll"; config_options[1] = get_config_name(); safe_fd(-1, 0); execve(logroll_program, config_options, safe_env()); error(_("cannot exec %s: %s"), logroll_program, strerror(errno)); /*NOTREACHED*/ return 0; /* keep the compiler happy */ }
void search_holding_disk( find_result_t **output_find, disklist_t * dynamic_disklist) { GSList *holding_file_list; GSList *e; char *holding_file; disk_t *dp; char *orig_name; holding_file_list = holding_get_files(NULL, 1); if (string_chunk == NULL) { string_chunk = g_string_chunk_new(32768); } for(e = holding_file_list; e != NULL; e = e->next) { dumpfile_t file; holding_file = (char *)e->data; if (!holding_file_get_dumpfile(holding_file, &file)) continue; if (file.dumplevel < 0 || file.dumplevel >= DUMP_LEVELS) { dumpfile_free_data(&file); continue; } dp = NULL; orig_name = g_strdup(file.name); for(;;) { char *s; if((dp = lookup_disk(file.name, file.disk))) break; if((s = strrchr(file.name,'.')) == NULL) break; *s = '\0'; } strcpy(file.name, orig_name); /* restore munged string */ g_free(orig_name); if ( dp == NULL ) { if (dynamic_disklist == NULL) { dumpfile_free_data(&file); continue; } dp = add_disk(dynamic_disklist, file.name, file.disk); enqueue_disk(dynamic_disklist, dp); } if(find_match(file.name,file.disk)) { find_result_t *new_output_find = g_new0(find_result_t, 1); new_output_find->next=*output_find; new_output_find->timestamp = g_string_chunk_insert_const(string_chunk, file.datestamp); new_output_find->write_timestamp = g_string_chunk_insert_const(string_chunk, "00000000000000"); new_output_find->hostname = g_string_chunk_insert_const(string_chunk, file.name); new_output_find->diskname = g_string_chunk_insert_const(string_chunk, file.disk); new_output_find->level=file.dumplevel; new_output_find->label=g_string_chunk_insert_const(string_chunk, holding_file); new_output_find->partnum = -1; new_output_find->totalparts = -1; new_output_find->filenum=0; if (file.is_partial) { new_output_find->status="PARTIAL"; new_output_find->dump_status="PARTIAL"; } else { new_output_find->status="OK"; new_output_find->dump_status="OK"; } new_output_find->message=""; new_output_find->kb = holding_file_size(holding_file, 1); new_output_find->bytes = 0; new_output_find->orig_kb = file.orig_size; *output_find=new_output_find; } dumpfile_free_data(&file); } slist_free_full(holding_file_list, g_free); }