Ignore:
Timestamp:
Sep 20, 2013, 2:29:57 PM (11 years ago)
Author:
Bruno Cornec
Message:

Simplify the interface of mr_getline and mr_asprintf. With 3.1 compatibility now will allow backports from this branch into 3.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/mondo/src/common/libmondo-filelist.c

    r3171 r3185  
    9696    log_to_screen("Dividing filelist into sets. Please wait.");
    9797    i = 0;
    98     mr_asprintf(&filelist, "%s/archives/filelist.full", bkpinfo->scratchdir);
     98    mr_asprintf(filelist, "%s/archives/filelist.full", bkpinfo->scratchdir);
    9999    if (!does_file_exist(filelist)) {
    100100        log_it("filelist %s not found", filelist);
     
    107107    estimate_noof_media_required(noof_sets);    // for cosmetic purposes
    108108
    109     mr_asprintf(&tempfile, "%s/biggielist.txt", bkpinfo->tmpdir);
     109    mr_asprintf(tempfile, "%s/biggielist.txt", bkpinfo->tmpdir);
    110110    if (!(fout = fopen(tempfile, "a"))) {
    111111        log_OS_error("Cannot append to biggielist");
     
    157157    }                           // no sense in trying to sort an empty file
    158158
    159     mr_asprintf(&tmp_fname, "%s/sortfile", bkpinfo->tmpdir);
    160 
    161     mr_asprintf(&command, "sort %s > %s 2>> %s", orig_fname, tmp_fname, MONDO_LOGFILE);
     159    mr_asprintf(tmp_fname, "%s/sortfile", bkpinfo->tmpdir);
     160
     161    mr_asprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname, MONDO_LOGFILE);
    162162    retval = system(command);
    163163    mr_free(command);
     
    167167    } else {
    168168        log_msg(5, "Sorted %s --> %s OK. Copying it back to %s now", orig_fname, tmp_fname, orig_fname);
    169         mr_asprintf(&command, "mv -f %s %s", tmp_fname, orig_fname);
     169        mr_asprintf(command, "mv -f %s %s", tmp_fname, orig_fname);
    170170        retval += run_program_and_log_output(command, 5);
    171171        mr_free(command);
     
    237237    curr_set_no = 0;
    238238    curr_set_size = 0;
    239     mr_asprintf(&outfname, "%s/filelist.%ld", outdir, curr_set_no);
    240     mr_asprintf(&biggie_fname, "%s/biggielist.txt", outdir);
     239    mr_asprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);
     240    mr_asprintf(biggie_fname, "%s/biggielist.txt", outdir);
    241241    log_it("outfname=%s; biggie_fname=%s", outfname, biggie_fname);
    242242    if (!(fbig = fopen(biggie_fname, "w"))) {
     
    255255    }
    256256
    257     mr_getline(&incoming, fin);
     257    mr_getline(incoming, fin);
    258258    while (!feof(fin)) {
    259259        lino++;
     
    288288                curr_set_size = 0;
    289289
    290                 mr_asprintf(&outfname, "%s/filelist.%ld", outdir, curr_set_no);
     290                mr_asprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);
    291291                if (!(fout = fopen(outfname, "w"))) {
    292292                    log_OS_error("Unable to openout outfname");
     
    301301        }
    302302        mr_free(incoming);
    303         mr_getline(&incoming, fin);
     303        mr_getline(incoming, fin);
    304304    }
    305305    mr_free(incoming);
     
    320320    mr_free(biggie_fname);
    321321
    322     mr_asprintf(&outfname, "%s/LAST-FILELIST-NUMBER", outdir);
    323     mr_asprintf(&tmp, "%ld", curr_set_no);
     322    mr_asprintf(outfname, "%s/LAST-FILELIST-NUMBER", outdir);
     323    mr_asprintf(tmp, "%ld", curr_set_no);
    324324    if (write_one_liner_data_file(outfname, tmp)) {
    325325        log_OS_error
     
    331331
    332332    if (curr_set_no == 0) {
    333         mr_asprintf(&tmp, "Only one fileset. Fine.");
     333        mr_asprintf(tmp, "Only one fileset. Fine.");
    334334    } else {
    335         mr_asprintf(&tmp, "Filelist divided into %ld sets", curr_set_no + 1);
     335        mr_asprintf(tmp, "Filelist divided into %ld sets", curr_set_no + 1);
    336336    }
    337337    log_msg(1, tmp);
     
    453453        return (1);
    454454    }
    455     mr_asprintf(&pout_command, "gzip -c1 > %s", auxlist_fname);
     455    mr_asprintf(pout_command, "gzip -c1 > %s", auxlist_fname);
    456456    if (!(pout = popen(pout_command, "w"))) {
    457457        log_msg(1, "Cannot openout auxlist_fname %s", auxlist_fname);
     
    471471        log_msg(8, "Analyzing %s", file_to_analyze);
    472472        tmp = mr_stresc(file_to_analyze, "'", '\\', '\'');
    473         mr_asprintf(&syscall, "%s '%s' 2>> /dev/null", syscall_sprintf, tmp);   // " MONDO_LOGFILE);
     473        mr_asprintf(syscall, "%s '%s' 2>> /dev/null", syscall_sprintf, tmp);    // " MONDO_LOGFILE);
    474474        paranoid_free(tmp);
    475475        log_msg(20,"calling %s\n",syscall);
     
    490490
    491491    if (g_getfacl != NULL) {
    492         mr_asprintf(&command, "touch \"%s\"", facl_fname);
     492        mr_asprintf(command, "touch \"%s\"", facl_fname);
    493493        run_program_and_log_output(command, 8);
    494494        mr_free(command);
     
    506506
    507507    if (g_getfattr != NULL) {
    508         mr_asprintf(&command, "touch \"%s\"", fattr_fname);
     508        mr_asprintf(command, "touch \"%s\"", fattr_fname);
    509509        run_program_and_log_output(command, 8);
    510510        mr_free(command);
     
    538538        if (strstr(executable,"acl")) {
    539539            /*  setfacl needs no additional option for physical walk */
    540             mr_asprintf(&tmp,"");
     540            mr_asprintf(tmp,"");
    541541        } else {
    542542            /*  setfattr needs option -h for physical walk */
    543             mr_asprintf(&tmp,"-h");
    544         }
    545         mr_asprintf(&command, "gzip -dc %s | %s %s --restore - 2>> %s", original_exat_fname, executable, tmp, MONDO_LOGFILE);
     543            mr_asprintf(tmp,"-h");
     544        }
     545        mr_asprintf(command, "gzip -dc %s | %s %s --restore - 2>> %s", original_exat_fname, executable, tmp, MONDO_LOGFILE);
    546546        mr_free(tmp);
    547547        log_msg(1, "command = %s", command);
     
    560560    malloc_string(current_subset_file);
    561561    malloc_string(current_master_file);
    562     mr_asprintf(&masklist, "%s/masklist", bkpinfo->tmpdir);
    563     mr_asprintf(&command, "cp -f %s %s", orig_msklist, masklist);
     562    mr_asprintf(masklist, "%s/masklist", bkpinfo->tmpdir);
     563    mr_asprintf(command, "cp -f %s %s", orig_msklist, masklist);
    564564    run_program_and_log_output(command, 1);
    565565    mr_free(command);
     
    568568    current_subset_file[0] = current_master_file[0] = '\0';
    569569
    570     mr_asprintf(&syscall_pout, "%s --restore - 2>> %s", executable, MONDO_LOGFILE);
     570    mr_asprintf(syscall_pout, "%s --restore - 2>> %s", executable, MONDO_LOGFILE);
    571571    log_msg(1, "syscall_pout = %s", syscall_pout);
    572572    pout = popen(syscall_pout, "w");
     
    579579    }
    580580
    581     mr_asprintf(&syscall_pin, "gzip -dc %s", original_exat_fname);
     581    mr_asprintf(syscall_pin, "gzip -dc %s", original_exat_fname);
    582582    log_msg(1, "syscall_pin = %s", syscall_pin);
    583583    pin = popen(syscall_pin, "r");
     
    720720
    721721    strcpy(val_sz,"");
    722     mr_asprintf(&cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir);
     722    mr_asprintf(cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir);
    723723    read_cfg_var(cfg_fname, "last-filelist-number", val_sz);
    724724    mr_free(cfg_fname);
     
    882882    }
    883883    log_to_screen("Loading filelist");
    884     mr_asprintf(&tmp1, "zcat %s | wc -l", filelist_fname);
     884    mr_asprintf(tmp1, "zcat %s | wc -l", filelist_fname);
    885885    log_msg(6, "tmp1 = %s", tmp1);
    886886    lines_in_filelist = atol(call_program_and_get_last_line_of_output(tmp1));
     
    902902    (filelist->down)->expanded = (filelist->down)->selected = FALSE;
    903903
    904     mr_asprintf(&command_to_open_fname, "gzip -dc %s", filelist_fname);
     904    mr_asprintf(command_to_open_fname, "gzip -dc %s", filelist_fname);
    905905    if (!(pin = popen(command_to_open_fname, "r"))) {
    906906        log_OS_error("Unable to openin filelist_fname");
     
    12841284    bool in_quotes = FALSE;
    12851285
    1286     mr_asprintf(&sz_res, "%s", incoming);
     1286    mr_asprintf(sz_res, "%s", incoming);
    12871287    p = sz_res;
    12881288    while ((*p != '|' || in_quotes) && *p != '\0') {
     
    13521352        }
    13531353    }
    1354     mr_asprintf(&find_excludes, " ");
     1354    mr_asprintf(find_excludes, " ");
    13551355
    13561356    if (!depth) {
     
    13701370#if linux
    13711371        // 2.6 has /sys as a proc-type thing -- must be excluded
    1372         mr_asprintf(&strtmp, "find '%s' -maxdepth %d -fstype mvfs -prune -o -fstype devpts -prune -o -fstype tmpfs -prune -o -fstype devtmpfs -prune -o -fstype proc -prune -o -fstype selinuxfs -prune -o -fstype securityfs -prune -o -fstype hugetlbfs -o -fstype cgroup -prune -prune -o -fstype mqueue -prune -o -fstype debugfs -prune -o -fstype sysfs -prune -o -fstype rpc_pipefs -prune -o -fstype none -prune -o %s -type d -print > %s 2> /dev/null", dir, MAX_SKEL_DEPTH, find_excludes, g_skeleton_filelist);
     1372        mr_asprintf(strtmp, "find '%s' -maxdepth %d -fstype mvfs -prune -o -fstype devpts -prune -o -fstype tmpfs -prune -o -fstype devtmpfs -prune -o -fstype proc -prune -o -fstype selinuxfs -prune -o -fstype securityfs -prune -o -fstype hugetlbfs -o -fstype cgroup -prune -prune -o -fstype mqueue -prune -o -fstype debugfs -prune -o -fstype sysfs -prune -o -fstype rpc_pipefs -prune -o -fstype none -prune -o %s -type d -print > %s 2> /dev/null", dir, MAX_SKEL_DEPTH, find_excludes, g_skeleton_filelist);
    13731373#else
    13741374        // On BSD, for example, /sys is the kernel sources -- don't exclude
    1375         mr_asprintf(&strtmp, "find '%s' -maxdepth %d -fstype mvfs -prune -o -path /proc -prune -o %s -type d -print > %s 2> /dev/null", dir, MAX_SKEL_DEPTH, find_excludes, g_skeleton_filelist);
     1375        mr_asprintf(strtmp, "find '%s' -maxdepth %d -fstype mvfs -prune -o -path /proc -prune -o %s -type d -print > %s 2> /dev/null", dir, MAX_SKEL_DEPTH, find_excludes, g_skeleton_filelist);
    13761376#endif
    13771377        paranoid_free(find_excludes);
     
    13791379        paranoid_system(strtmp);
    13801380        paranoid_free(strtmp);
    1381         mr_asprintf(&tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist);
     1381        mr_asprintf(tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist);
    13821382        g_skeleton_entries =
    13831383            1 + atol(call_program_and_get_last_line_of_output(tmp));
     
    14111411                    int cols, rows;
    14121412                    newtGetScreenSize(&cols, &rows);
    1413                     mr_asprintf(&tmp, "Reading %-*s", cols, dir1);
     1413                    mr_asprintf(tmp, "Reading %-*s", cols, dir1);
    14141414                    newtDrawRootText(0, g_noof_rows - 3, tmp);
    14151415                    mr_free(tmp);
     
    14241424
    14251425//  log_msg(0, "Cataloguing %s", dir);
    1426     mr_asprintf(&skip_these, "|%s|", sth);
     1426    mr_asprintf(skip_these, "|%s|", sth);
    14271427   
    1428     mr_asprintf(&new_with_pipe, "|%s|", dir1);
     1428    mr_asprintf(new_with_pipe, "|%s|", dir1);
    14291429    if ((dip = opendir(dir1)) == NULL) {
    1430         mr_asprintf(&tmp,"opendir %s", dir1);
     1430        mr_asprintf(tmp,"opendir %s", dir1);
    14311431        log_OS_error(tmp);
    14321432        paranoid_free(tmp);
     
    14401440            i++;
    14411441            if (strcmp(dir1, "/")) {
    1442                 mr_asprintf(&new,"%s/%s",dir1,dit->d_name);
     1442                mr_asprintf(new,"%s/%s",dir1,dit->d_name);
    14431443            } else {
    1444                 mr_asprintf(&new,"%s%s",dir1,dit->d_name);
     1444                mr_asprintf(new,"%s%s",dir1,dit->d_name);
    14451445            }
    14461446            paranoid_free(new_with_pipe);
    1447             mr_asprintf(&new_with_pipe, "|%s|", new);
     1447            mr_asprintf(new_with_pipe, "|%s|", new);
    14481448            if (strstr(skip_these, new_with_pipe)) {
    14491449                fprintf(fout, "%s\n", new);
     
    14671467                                counter = 0;
    14681468                                uberctr++;
    1469                                 mr_asprintf(&tmp, " %c ", special_dot_char(uberctr));
     1469                                mr_asprintf(tmp, " %c ", special_dot_char(uberctr));
    14701470#ifndef _XWIN
    14711471                                if (!g_text_mode) {
     
    15361536    malloc_string(tmp);
    15371537    malloc_string(g_skeleton_filelist);
    1538     mr_asprintf(&sz_datefile,MONDO_CACHE"/difflevel.%d" , 0);
     1538    mr_asprintf(sz_datefile,MONDO_CACHE"/difflevel.%d" , 0);
    15391539    if (!include_paths && !userdef_filelist) {
    15401540        fatal_error
     
    15421542    }
    15431543// make hole for filelist
    1544     mr_asprintf(&command, "mkdir -p %s/archives", scratchdir);
     1544    mr_asprintf(command, "mkdir -p %s/archives", scratchdir);
    15451545    paranoid_system(command);
    15461546    mr_free(command);
    15471547
    1548     mr_asprintf(&sz_filelist, "%s/tmpfs/filelist.full", tmpdir);
     1548    mr_asprintf(sz_filelist, "%s/tmpfs/filelist.full", tmpdir);
    15491549    make_hole_for_file(sz_filelist);
    15501550
    15511551    if (differential == 0) {
    15521552        // restore last good datefile if it exists
    1553         mr_asprintf(&command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);
     1553        mr_asprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);
    15541554        run_program_and_log_output(command, 3);
    15551555        mr_free(command);
     
    15571557        // backup last known good datefile just in case :)
    15581558        if (does_file_exist(sz_datefile)) {
    1559             mr_asprintf(&command, "mv -f %s %s.aborted", sz_datefile,
     1559            mr_asprintf(command, "mv -f %s %s.aborted", sz_datefile,
    15601560                    sz_datefile);
    15611561            paranoid_system(command);
     
    15821582                "Using the user-specified filelist - %s - instead of calculating one",
    15831583                userdef_filelist);
    1584         mr_asprintf(&command, "cp -f %s %s", userdef_filelist, sz_filelist);
     1584        mr_asprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);
    15851585        if (run_program_and_log_output(command, 3)) {
    15861586            mr_free(command);
     
    15911591        log_msg(2, "include_paths = '%s'", include_paths);
    15921592        log_msg(1, "Calculating filelist");
    1593         mr_asprintf(&tmp2, "%s", call_program_and_get_last_line_of_output("mount | grep -Ew 'ntfs|ntfs-3g|fat|vfat|dos' | awk '{print $3}'"));
     1593        mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output("mount | grep -Ew 'ntfs|ntfs-3g|fat|vfat|dos' | awk '{print $3}'"));
    15941594        if (strlen(tmp2) < 1) {
    1595             mr_asprintf(&tmp1," ");
     1595            mr_asprintf(tmp1," ");
    15961596        } else {
    15971597            log_msg(2, "Found windows FS: %s",tmp2);
    1598             mr_asprintf(&tmp1, "find %s -name '/win386.swp' -o -name '/hiberfil.sys' -o -name '/pagefile.sys' 2> /dev/null\n",tmp2);
     1598            mr_asprintf(tmp1, "find %s -name '/win386.swp' -o -name '/hiberfil.sys' -o -name '/pagefile.sys' 2> /dev/null\n",tmp2);
    15991599            paranoid_free(tmp2);
    1600             mr_asprintf(&tmp2, "%s", call_program_and_get_last_line_of_output(tmp1));
     1600            mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output(tmp1));
    16011601            log_msg(2, "Found windows files: %s",tmp2);
    16021602        }
    16031603        paranoid_free(tmp1);
    16041604
    1605         mr_asprintf(&exclude_paths, MONDO_CACHE"|%s|%s|%s|.|..|"MNT_CDROM"|"MNT_FLOPPY"|/media|/tmp|/proc|/sys|/run|/dev/shm|"MINDI_CACHE, tmp2, (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir);
     1605        mr_asprintf(exclude_paths, MONDO_CACHE"|%s|%s|%s|.|..|"MNT_CDROM"|"MNT_FLOPPY"|/media|/tmp|/proc|/sys|/run|/dev/shm|"MINDI_CACHE, tmp2, (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir);
    16061606        if (excp != NULL) {
    16071607            mr_strcat(exclude_paths,"|%s",excp);
     
    16401640    }
    16411641    log_msg(2, "Copying new filelist to scratchdir");
    1642     mr_asprintf(&command, "mkdir -p %s/archives", scratchdir);
     1642    mr_asprintf(command, "mkdir -p %s/archives", scratchdir);
    16431643    paranoid_system(command);
    16441644    mr_free(command);
    16451645
    1646     mr_asprintf(&command, "cp -f %s %s/archives/", sz_filelist, scratchdir);
     1646    mr_asprintf(command, "cp -f %s %s/archives/", sz_filelist, scratchdir);
    16471647    paranoid_system(command);
    16481648    mr_free(command);
    16491649
    1650     mr_asprintf(&command, "mv -f %s %s", sz_filelist, tmpdir);
     1650    mr_asprintf(command, "mv -f %s %s", sz_filelist, tmpdir);
    16511651    paranoid_system(command);
    16521652    mr_free(command);
Note: See TracChangeset for help on using the changeset viewer.