Ignore:
Timestamp:
Sep 29, 2013, 9:31:34 AM (11 years ago)
Author:
Bruno Cornec
Message:
  • Finish with backports from 3.1 for now. Still some work to do, but we will now make that version compile and work again and serve as a base

so the gettext patch can be added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mondo/src/mondorestore/mondorestore.c

    r3185 r3193  
    253253              struct raidlist_itself *raidlist)
    254254{
    255     char c, *tmp;
     255    char c;
     256    char *tmp = NULL;
    256257    int retval = 0;
    257258
     
    260261    assert(mountlist != NULL);
    261262    assert(raidlist != NULL);
    262     malloc_string(tmp);
    263263    log_it("pre wrm");
    264264    c = which_restore_mode();
     
    274274        }
    275275        if (g_ISO_restore_mode) {
    276             sprintf(tmp, "umount -d %s", bkpinfo->isodir);
     276            mr_asprintf(tmp, "umount -d %s", bkpinfo->isodir);
    277277            run_program_and_log_output(tmp, FALSE);
     278            mr_free(tmp);
    278279        }
    279280        paranoid_MR_finish(0);
     
    284285    if (bkpinfo->backup_media_type == iso) {
    285286        if (iso_fiddly_bits((c == 'N') ? TRUE : FALSE)) {
    286             log_msg(2, "catchall_mode --- iso_fiddly_bits returned w/ error");
     287            log_msg(2,
     288                    "catchall_mode --- iso_fiddly_bits returned w/ error");
    287289            return (1);
    288290        } else {
     
    301303        retval += compare_mode(mountlist, raidlist);
    302304    }
    303     paranoid_free(tmp);
    304305    return (retval);
    305306}
     
    418419 * @return 0 for success, or the number of errors encountered.
    419420 */
    420 int
    421 interactive_mode(struct mountlist_itself *mountlist,
    422                  struct raidlist_itself *raidlist)
     421int interactive_mode(struct mountlist_itself *mountlist, struct raidlist_itself *raidlist)
    423422{
    424423    int retval = 0;
     
    432431  /** needs malloc **********/
    433432    char *tmp;
    434     char *fstab_fname;
    435     char *old_restpath;
     433    char *p = NULL;
     434    char *tmp1 = NULL;
     435    char *fstab_fname = NULL;
     436    char *old_restpath = NULL;
    436437
    437438    struct s_node *filelist;
     
    442443
    443444    malloc_string(tmp);
    444     malloc_string(fstab_fname);
    445     malloc_string(old_restpath);
    446445    assert(bkpinfo != NULL);
    447446    assert(mountlist != NULL);
     
    451450
    452451    if (g_text_mode) {
    453         if (!ask_me_yes_or_no
    454             ("Interactive Mode + textonly = experimental! Proceed anyway?"))
    455         {
     452        if (!ask_me_yes_or_no("Interactive Mode + textonly = experimental! Proceed anyway?")) {
    456453            fatal_error("Wise move.");
    457454        }
     
    463460    log_it("Done loading config file; resizing ML");
    464461
    465 #ifdef __FreeBSD__
    466     if (strstr
    467         (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
    468          "noresize"))
    469 #else
    470     if (strstr
    471         (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
    472          "noresize"))
    473 #endif
    474     {
     462    mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output("cat " CMDLINE);
     463    if (strstr(tmp1, "noresize")) {
    475464        log_msg(1, "Not resizing mountlist.");
    476465    } else {
    477466        resize_mountlist_proportionately_to_suit_new_drives(mountlist);
    478467    }
     468    mr_free(tmp1);
     469
    479470    for (done = FALSE; !done;) {
    480471        log_it("About to edit mountlist");
    481472        if (g_text_mode) {
    482473            save_mountlist_to_disk(mountlist, g_mountlist_fname);
    483             sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname);
    484             res = system(tmp);
     474            mr_asprintf(tmp1, "%s %s", find_my_editor(), g_mountlist_fname);
     475            res = system(tmp1);
     476            mr_free(tmp1);
    485477            load_mountlist(mountlist, g_mountlist_fname);
    486478        } else {
     
    571563    }
    572564    /* restore */
    573     if ((restore_all =
    574          ask_me_yes_or_no("Do you want me to restore all of your data?")))
    575     {
     565    if ((restore_all = ask_me_yes_or_no("Do you want me to restore all of your data?"))) {
    576566        log_msg(1, "Restoring all data");
    577567        retval += restore_everything(NULL);
    578     } else
    579         if ((restore_all =
    580              ask_me_yes_or_no
    581              ("Do you want me to restore _some_ of your data?"))) {
    582         strcpy(old_restpath, bkpinfo->restore_path);
     568    } else if ((restore_all = ask_me_yes_or_no("Do you want me to restore _some_ of your data?"))) {
     569        mr_asprintf(old_restpath, "%s", bkpinfo->restore_path);
    583570        for (done = FALSE; !done;) {
    584571            unlink("/tmp/filelist.full");
     
    590577              gotos_suck:
    591578                strcpy(tmp, old_restpath);
    592 // (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING);
     579                // (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING);
    593580                if (popup_and_get_string
    594581                    ("Restore path", "Restore files to where?", tmp,
     
    608595                    free_filelist(filelist);
    609596                }
    610                 if (!ask_me_yes_or_no
    611                     ("Restore another subset of your backup?")) {
     597                if (!ask_me_yes_or_no("Restore another subset of your backup?")) {
    612598                    done = TRUE;
    613599                }
     
    616602            }
    617603        }
    618         strcpy(old_restpath, bkpinfo->restore_path);
    619     } else {
    620         mvaddstr_and_log_it(g_currentY++,
    621                             0,
    622                             "User opted not to restore any data.                                  ");
     604        mr_free(old_restpath);
     605    } else {
     606        mvaddstr_and_log_it(g_currentY++, 0, "User opted not to restore any data.                                  ");
    623607    }
    624608    if (retval) {
    625         mvaddstr_and_log_it(g_currentY++,
    626                             0,
    627                             "Errors occurred during the restore phase.            ");
     609        mvaddstr_and_log_it(g_currentY++, 0, "Errors occurred during the restore phase.            ");
    628610    }
    629611
     
    647629                            "Using tune2fs/tune4fs to identify your ext2,3,4 partitions");
    648630        if (does_file_exist("/tmp/fstab.new")) {
    649             strcpy(fstab_fname, "/tmp/fstab.new");
     631            mr_asprintf(fstab_fname, "/tmp/fstab.new");
    650632        } else {
    651             strcpy(fstab_fname, "/tmp/fstab");
    652         }
    653         sprintf(tmp,
    654                 "label-partitions-as-necessary %s < %s >> %s 2>> %s",
    655                 g_mountlist_fname, fstab_fname, MONDO_LOGFILE,
    656                 MONDO_LOGFILE);
    657         res = system(tmp);
     633            mr_asprintf(fstab_fname, "/tmp/fstab");
     634        }
     635        mr_asprintf(tmp1, "label-partitions-as-necessary %s < %s >> %s 2>> %s", g_mountlist_fname, fstab_fname, MONDO_LOGFILE, MONDO_LOGFILE);
     636        mr_free(fstab_fname);
     637
     638        res = system(tmp1);
     639        mr_free(tmp1);
    658640        if (res) {
    659641            log_to_screen
     
    674656  end_of_func:
    675657    paranoid_free(tmp);
    676     paranoid_free(fstab_fname);
    677     paranoid_free(old_restpath);
    678658    log_it("Leaving interactive_mode()");
    679659    return (retval);
     
    759739    int retval = 0;
    760740    int res = 0;
    761   /** malloc **/
    762     char tmp[MAX_STR_LEN];
     741    char *tmp = NULL;
     742    char *tmp1 = NULL;
    763743    char *flaws_str = NULL;
    764744
     
    772752    load_mountlist(mountlist, g_mountlist_fname);   // in case read_cfg_file_into_bkpinfo updated the mountlist
    773753#ifdef __FreeBSD__
    774     if (strstr
    775         (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
    776          "noresize"))
     754    if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "noresize"))
    777755#else
    778     if (strstr
    779         (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
    780          "noresize"))
     756    if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "noresize"))
    781757#endif
    782758    {
     
    812788            twenty_seconds_til_yikes();
    813789            g_fprep = fopen("/tmp/prep.sh", "w");
    814 #ifdef __FreeBSD__
    815             if (strstr
    816                 (call_program_and_get_last_line_of_output
    817                  ("cat /tmp/cmdline"), "nopart"))
    818 #else
    819             if (strstr
    820                 (call_program_and_get_last_line_of_output
    821                  ("cat /proc/cmdline"), "nopart"))
    822 #endif
    823             {
    824                 log_msg(2,
    825                         "Not partitioning drives due to 'nopart' option.");
     790            mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output("cat " CMDLINE,TRUE));
     791            if (strstr(tmp1, "nopart")) {
     792                log_msg(2, "Not partitioning drives due to 'nopart' option.");
    826793                res = 0;
    827794            } else {
    828795                res = partition_everything(mountlist);
    829796                if (res) {
    830                     log_to_screen
    831                         ("Warning. Errors occurred during partitioning.");
     797                    log_to_screen("Warning. Errors occurred during partitioning.");
    832798                    res = 0;
    833799                }
    834800            }
     801            mr_free(tmp1);
     802
    835803            retval += res;
    836804            if (!res) {
    837805                log_to_screen("Preparing to format your disk(s)");
    838806                sleep(1);
    839                 paranoid_system("sync");
     807                sync();
    840808                log_to_screen("Please wait. This may take a few minutes.");
    841809                res += format_everything(mountlist, FALSE, raidlist);
     
    880848                        "Using tune2fs/tune4fs to identify your ext2,3,4 partitions");
    881849
    882     sprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab >> %s 2>> %s", g_mountlist_fname, MONDO_LOGFILE, MONDO_LOGFILE);
     850    mr_asprintf(tmp1, "label-partitions-as-necessary %s < /tmp/fstab >> %s 2>> %s", MINDI_CACHE"/mountlist.txt", MONDO_LOGFILE, MONDO_LOGFILE);
    883851    res = run_program_and_log_output(tmp, TRUE);
     852    mr_free(tmp1);
    884853    if (res) {
    885854        log_to_screen("label-partitions-as-necessary returned an error");
     
    891860
    892861  after_the_nuke:
     862    mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output("cat " CMDLINE,TRUE));
    893863    if (retval) {
    894864        log_to_screen("Errors occurred during the nuke phase.");
    895     } else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE")) {
    896         log_to_screen
    897             ("PC was restored successfully. Thank you for using Mondo Rescue.");
    898         log_to_screen
    899             ("Please visit our website at http://www.mondorescue.org for more information.");
    900     } else {
    901         strcpy(tmp,"Mondo has restored your system.\n\nPlease wait for the command prompt. Then remove the backup media and reboot.\n\nPlease visit our website at http://www.mondorescue.org for more information.");
    902             popup_and_OK(tmp);
    903         log_to_screen
    904           ("Mondo has restored your system. Please wait for the command prompt.");
    905         log_to_screen
    906             ("Then remove the backup media and reboot.");
    907         log_to_screen
    908             ("Please visit our website at http://www.mondorescue.org for more information.");
    909     }
     865    } else if (strstr(tmp1, "RESTORE")) {
     866        log_to_screen("PC was restored successfully. Thank you for using Mondo Rescue.");
     867        log_to_screen("Please visit our website at http://www.mondorescue.org for more information.");
     868    } else {
     869        mr_asprintf(tmp,"%s","Mondo has restored your system.\n\nPlease wait for the command prompt. Then remove the backup media and reboot.\n\nPlease visit our website at http://www.mondorescue.org for more information.");
     870        popup_and_OK(tmp);
     871        mr_free(tmp);
     872        log_to_screen("Mondo has restored your system. Please wait for the command prompt.");
     873        log_to_screen("Then remove the backup media and reboot.");
     874        log_to_screen("Please visit our website at http://www.mondorescue.org for more information.");
     875    }
     876    mr_free(tmp1);
     877
    910878    g_I_have_just_nuked = TRUE;
    911879    return (retval);
     
    928896    int retval = 0;
    929897
    930   /** malloc **/
    931     char *old_restpath;
     898    char *old_restpath = NULL;
    932899
    933900    struct mountlist_itself *mountlist = NULL;
    934 //  static
    935901    struct raidlist_itself *raidlist = NULL;
    936902    struct s_node *filelist = NULL;
     
    938904    log_msg(1, "restore_to_live_filesystem() - starting");
    939905    assert(bkpinfo != NULL);
    940     malloc_string(old_restpath);
    941906    mountlist = malloc(sizeof(struct mountlist_itself));
    942907    raidlist = malloc(sizeof(struct raidlist_itself));
     
    974939    if (!g_restoring_live_from_netfs && (filelist = process_filelist_and_biggielist())) {
    975940        save_filelist(filelist, "/tmp/selected-files.txt");
    976         strcpy(old_restpath, bkpinfo->restore_path);
     941        mr_asprintf(old_restpath, "%s", bkpinfo->restore_path);
    977942        if (popup_and_get_string("Restore path",
    978943                                 "Restore files to where? )",
     
    986951        }
    987952        strcpy(bkpinfo->restore_path, old_restpath);
     953        mr_free(old_restpath);
    988954    } else {
    989955        if (filelist != NULL) {
     
    1004970        eject_device(bkpinfo->media_device);
    1005971    }
    1006     paranoid_free(old_restpath);
    1007972    free(mountlist);
    1008973    free(raidlist);
     
    10431008
    10441009  /** malloc ***/
    1045     char *checksum, *outfile_fname, *tmp, *bzip2_command,
    1046         *ntfsprog_command, *suffix, *sz_devfile;
     1010    char *checksum = NULL;
     1011    char *outfile_fname = NULL;
     1012    char *tmp = NULL;
     1013    char *bzip2_command = NULL;
     1014    char *suffix = NULL;
     1015    char *sz_devfile = NULL;
    10471016    char *bigblk;
    10481017    char *mds = NULL;
     
    10511020    long sliceno;
    10521021    long siz;
    1053     char ntfsprog_fifo[MAX_STR_LEN];
     1022    char *ntfsprog_fifo = NULL;
    10541023    char *file_to_openout = NULL;
    10551024    struct s_filename_and_lstat_info biggiestruct;
     
    10591028    int res = 0;
    10601029    int old_loglevel;
    1061     char sz_msg[MAX_STR_LEN];
    10621030    struct s_node *node;
    10631031
     
    10651033    ubuf = &the_utime_buf;
    10661034    assert(bkpinfo != NULL);
    1067 
    1068     malloc_string(checksum);
    1069     malloc_string(outfile_fname);
    1070     malloc_string(tmp);
    1071     malloc_string(bzip2_command);
    1072     malloc_string(ntfsprog_command);
    1073     malloc_string(suffix);
    1074     malloc_string(sz_devfile);
    10751035
    10761036    pathname_of_last_file_restored[0] = '\0';
     
    10921052    paranoid_fclose(fin);
    10931053
    1094     strcpy(checksum, biggiestruct.checksum);
    1095 
     1054    mr_asprintf(checksum, "%s", biggiestruct.checksum);
    10961055    if (!checksum[0]) {
    1097         sprintf(tmp, "Warning - bigfile %ld does not have a checksum",
    1098                 bigfileno + 1);
    1099         log_msg(3, tmp);
    1100     }
     1056        log_msg(3, "Warning - bigfile %ld does not have a checksum", bigfileno + 1);
     1057    }
     1058    mr_free(checksum);
    11011059
    11021060    if (!strncmp(biggiestruct.filename, "/dev/", 5))    // Whether NTFS or not :)
    11031061    {
    1104         strcpy(outfile_fname, biggiestruct.filename);
    1105     } else {
    1106         sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
    1107                 biggiestruct.filename);
     1062        mr_asprintf(outfile_fname, "%s", biggiestruct.filename);
     1063    } else {
     1064        mr_asprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, biggiestruct.filename);
    11081065    }
    11091066
     
    11121069        node = find_string_at_node(filelist, biggiestruct.filename);
    11131070        if (!node) {
    1114             log_msg(0, "Skipping %s (name isn't in filelist)",
    1115                     biggiestruct.filename);
     1071            log_msg(0, "Skipping %s (name isn't in filelist)", biggiestruct.filename);
    11161072            pathname_of_last_file_restored[0] = '\0';
    11171073            return (0);
    11181074        } else if (!(node->selected)) {
    1119             log_msg(1, "Skipping %s (name isn't in biggielist subset)",
    1120                     biggiestruct.filename);
     1075            log_msg(1, "Skipping %s (name isn't in biggielist subset)", biggiestruct.filename);
    11211076            pathname_of_last_file_restored[0] = '\0';
    11221077            return (0);
    11231078        }
    11241079    }
     1080
    11251081    /* otherwise, continue */
    1126 
    11271082    log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
    11281083    if (biggiestruct.use_ntfsprog) {
    11291084        if (strncmp(biggiestruct.filename, "/dev/", 5)) {
    1130             log_msg(1,
    1131                     "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
     1085            log_msg(1, "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
    11321086            log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
    11331087            biggiestruct.use_ntfsprog = FALSE;
     
    11361090
    11371091    if (biggiestruct.use_ntfsprog)  // if it's an NTFS device
    1138 //  if (!strncmp ( biggiestruct.filename, "/dev/", 5))
    11391092    {
    11401093        g_loglevel = 4;
    11411094        use_ntfsprog_hack = TRUE;
    1142         log_msg(2,
    1143                 "Calling ntfsclone in background because %s is an NTFS /dev entry",
    1144                 outfile_fname);
    1145         sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
    1146                 (int) (random() % 32768));
     1095        log_msg(2, "Calling ntfsclone in background because %s is an NTFS /dev entry", outfile_fname);
     1096        mr_asprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), (int) (random() % 32768));
    11471097        mkfifo(sz_devfile, 0x770);
    1148         strcpy(ntfsprog_fifo, sz_devfile);
     1098        mr_asprintf(ntfsprog_fifo, "%s", sz_devfile);
     1099        mr_free(sz_devfile);
    11491100        file_to_openout = ntfsprog_fifo;
    11501101        switch (pid = fork()) {
     
    11521103            fatal_error("Fork failure");
    11531104        case 0:
    1154             log_msg(3,
    1155                     "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
    1156                     biggiestruct.filename, ntfsprog_fifo);
    1157             res =
    1158                 feed_outfrom_ntfsprog(biggiestruct.filename,
    1159                                        ntfsprog_fifo);
    1160 //          log_msg(3, "CHILD - fip - exiting");
     1105            log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", biggiestruct.filename, ntfsprog_fifo);
     1106            res = feed_outfrom_ntfsprog(biggiestruct.filename, ntfsprog_fifo);
     1107            mr_free(ntfsprog_fifo);
    11611108            exit(res);
    11621109            break;
    11631110        default:
    1164             log_msg(3,
    1165                     "feed_into_ntfsprog() called in background --- pid=%ld",
    1166                     (long int) (pid));
    1167         }
     1111            log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
     1112        }
     1113        mr_free(ntfsprog_fifo);
    11681114    } else {
    11691115        use_ntfsprog_hack = FALSE;
    1170         ntfsprog_fifo[0] = '\0';
    11711116        file_to_openout = outfile_fname;
    11721117        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
     
    11761121    }
    11771122
    1178     sprintf(tmp, "Reassembling big file %ld (%s)", bigfileno + 1,
    1179             outfile_fname);
    1180     log_msg(2, tmp);
     1123    log_msg(2, "Reassembling big file %ld (%s)", bigfileno + 1, outfile_fname);
    11811124
    11821125    /*
     
    11861129     */
    11871130
    1188     strncpy(pathname_of_last_file_restored, biggiestruct.filename,
    1189             MAX_STR_LEN - 1);
     1131    strncpy(pathname_of_last_file_restored, biggiestruct.filename, MAX_STR_LEN - 1);
    11901132    pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
    11911133
     
    11981140
    11991141    for (sliceno = 1, finished = FALSE; !finished;) {
    1200         if (!does_file_exist
    1201             (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))
    1202             &&
    1203             !does_file_exist(slice_fname
    1204                              (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))
    1205             &&
    1206             !does_file_exist(slice_fname
    1207                              (bigfileno, sliceno, ARCHIVES_PATH, "gz"))
    1208             &&
    1209             !does_file_exist(slice_fname
    1210                              (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
    1211             log_msg(3,
    1212                     "Cannot find a data slice or terminator slice on CD %d",
    1213                     g_current_media_number);
     1142        if (!does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")) &&
     1143            !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo")) &&
     1144            !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "gz")) &&
     1145            !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzma")) &&
     1146            !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
     1147            log_msg(3, "Cannot find a data slice or terminator slice on CD %d", g_current_media_number);
    12141148            g_current_media_number++;
    12151149            mds = media_descriptor_string(bkpinfo->backup_media_type);
    1216             sprintf(tmp,
    1217                     "Asking for %s #%d so that I may read slice #%ld\n", mds,
    1218                     g_current_media_number, sliceno);
    1219             log_msg(2, tmp);
    1220             sprintf(tmp, "Restoring from %s #%d", mds, g_current_media_number);
     1150            log_msg(2, "Asking for %s #%d so that I may read slice #%ld\n", mds, g_current_media_number, sliceno);
    12211151            mr_free(mds);
    12221152
    1223             log_to_screen(tmp);
     1153            log_to_screen("Restoring from %s #%d", mds, g_current_media_number);
     1154
    12241155            insist_on_this_cd_number(g_current_media_number);
    12251156            log_to_screen("Continuing to restore.");
    12261157        } else {
    1227             strcpy(tmp,
    1228                    slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
     1158            mr_asprintf(tmp, "%s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
    12291159            if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
    1230                 log_msg(2,
    1231                         "End of bigfile # %ld (slice %ld is the terminator)",
    1232                         bigfileno + 1, sliceno);
     1160                log_msg(2, "End of bigfile # %ld (slice %ld is the terminator)", bigfileno + 1, sliceno);
    12331161                finished = TRUE;
     1162                mr_free(tmp);
    12341163                continue;
    12351164            } else {
    1236                 if (does_file_exist
    1237                     (slice_fname
    1238                      (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
    1239                     strcpy(bzip2_command, "lzop");
    1240                     strcpy(suffix, "lzo");
     1165                if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
     1166                    mr_asprintf(bzip2_command, "lzop");
     1167                    mr_asprintf(suffix, "lzo");
    12411168                } else
    1242                     if (does_file_exist
    1243                         (slice_fname
    1244                          (bigfileno, sliceno, ARCHIVES_PATH, "gz"))) {
    1245                     strcpy(bzip2_command, "gzip");
    1246                     strcpy(suffix, "gz");
     1169                    if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "gz"))) {
     1170                    mr_asprintf(bzip2_command, "gzip");
     1171                    mr_asprintf(suffix, "gz");
    12471172                } else
    1248                     if (does_file_exist
    1249                         (slice_fname
    1250                          (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
    1251                     strcpy(bzip2_command, "bzip2");
    1252                     strcpy(suffix, "bz2");
     1173                    if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzma"))) {
     1174                    mr_asprintf(bzip2_command, "lzma");
     1175                    mr_asprintf(suffix, "lzma");
    12531176                } else
    1254                     if (does_file_exist
    1255                         (slice_fname
    1256                          (bigfileno, sliceno, ARCHIVES_PATH, ""))) {
    1257                     strcpy(bzip2_command, "");
    1258                     strcpy(suffix, "");
     1177                    if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
     1178                    mr_asprintf(bzip2_command, "bzip2");
     1179                    mr_asprintf(suffix, "bz2");
     1180                } else
     1181                    if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))) {
     1182                    mr_asprintf(bzip2_command, "");
     1183                    mr_asprintf(suffix, "");
    12591184                } else {
    12601185                    log_to_screen("OK, that's pretty fsck0red...");
     1186                    mr_free(tmp);
    12611187                    return (1);
    12621188                }
    12631189            }
    1264             if (bzip2_command[0] != '\0') {
    1265                 sprintf(bzip2_command + strlen(bzip2_command),
    1266                         " -dc %s 2>> %s",
    1267                         slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
    1268                                     suffix), MONDO_LOGFILE);
     1190            mr_free(tmp);
     1191            if (bzip2_command != NULL) {
     1192                mr_strcat(bzip2_command, " -dc %s 2>> %s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix), MONDO_LOGFILE);
    12691193            } else {
    1270                 sprintf(bzip2_command, "cat %s 2>> %s",
    1271                         slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
    1272                                     suffix), MONDO_LOGFILE);
    1273             }
     1194                mr_asprintf(bzip2_command, "cat %s 2>> %s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix), MONDO_LOGFILE);
     1195            }
     1196            mr_free(suffix);
     1197
    12741198            mds = media_descriptor_string(bkpinfo->backup_media_type);
    1275             sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld    ", mds,
    1276                     g_current_media_number, bigfileno + 1, sliceno);
     1199            mr_asprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld    ", mds, g_current_media_number, bigfileno + 1, sliceno);
    12771200            mr_free(mds);
    12781201            log_msg(2, tmp);
     
    12841207                update_progress_form(tmp);
    12851208            }
     1209            mr_free(tmp);
     1210
    12861211            if (!(fbzip2 = popen(bzip2_command, "r"))) {
    12871212                fatal_error("Can't run popen command");
    12881213            }
     1214            mr_free(bzip2_command);
     1215
    12891216            while (!feof(fbzip2)) {
    12901217                siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2);
    12911218                if (siz > 0) {
    1292                     sprintf(sz_msg, "Read %ld from fbzip2", siz);
    12931219                    siz = fwrite(bigblk, 1, siz, fout);
    1294                     sprintf(sz_msg + strlen(sz_msg),
    1295                             "; written %ld to fout", siz);
    1296 //        log_msg(2. sz_msg);
    12971220                }
    12981221            }
     
    13041227        }
    13051228    }
    1306 /*
    1307   memset(bigblk, TAPE_BLOCK_SIZE, 1); // This all looks very fishy...
    1308   fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
    1309   fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
    1310   fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
    1311   fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
    1312 */
    13131229    paranoid_fclose(fout);
    13141230    g_loglevel = old_loglevel;
     
    13161232    if (use_ntfsprog_hack) {
    13171233        log_msg(3, "Waiting for ntfsclone to finish");
    1318         sprintf(tmp,
    1319                 " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
     1234        mr_asprintf(tmp, " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
    13201235        while (system(tmp) == 0) {
    13211236            sleep(1);
    13221237        }
     1238        mr_free(tmp);
    13231239        log_it("OK, ntfsclone has really finished");
    13241240    }
    13251241
    13261242    if (strcmp(outfile_fname, "/dev/null")) {
    1327         if (chown(outfile_fname, biggiestruct.properties.st_uid,
    1328               biggiestruct.properties.st_gid)) {
     1243        if (chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid)) {
    13291244            // FIXME
    13301245        }
     
    13341249        utime(outfile_fname, ubuf);
    13351250    }
     1251    mr_free(outfile_fname);
    13361252    paranoid_free(bigblk);
    1337     paranoid_free(checksum);
    1338     paranoid_free(outfile_fname);
    1339     paranoid_free(tmp);
    1340     paranoid_free(bzip2_command);
    1341     paranoid_free(ntfsprog_command);
    1342     paranoid_free(suffix);
    1343     paranoid_free(sz_devfile);
    13441253
    13451254    return (retval);
     
    13761285
    13771286  /** mallocs ********/
    1378     char *tmp;
    1379     char *command;
    1380     char *outfile_fname;
    1381     char *ntfsprog_command;
    1382     char *sz_devfile;
    1383     char *ntfsprog_fifo;
     1287    char *tmp = NULL;
     1288    char *tmp1 = NULL;
     1289    char *command = NULL;
     1290    char *outfile_fname = NULL;
     1291    char *sz_devfile = NULL;
     1292    char *ntfsprog_fifo = NULL;
    13841293    char *file_to_openout = NULL;
    13851294
     
    14001309
    14011310    malloc_string(tmp);
    1402     malloc_string(ntfsprog_fifo);
    1403     malloc_string(outfile_fname);
    1404     malloc_string(command);
    1405     malloc_string(sz_devfile);
    1406     malloc_string(ntfsprog_command);
    14071311    old_loglevel = g_loglevel;
    14081312    assert(bkpinfo != NULL);
     
    14551359    if (use_ntfsprog) {
    14561360        g_loglevel = 4;
    1457         strcpy(outfile_fname, orig_bf_fname);
     1361        mr_asprintf(outfile_fname, "%s", orig_bf_fname);
    14581362        use_ntfsprog_hack = TRUE;
    1459         log_msg(2,
    1460                 "Calling ntfsclone in background because %s is a /dev entry",
    1461                 outfile_fname);
    1462         sprintf(sz_devfile, "%s/%d.%d.000",
    1463                 bkpinfo->tmpdir,
    1464                 (int) (random() % 32768),
    1465                 (int) (random() % 32768));
     1363        log_msg(2, "Calling ntfsclone in background because %s is a /dev entry", outfile_fname);
     1364        mr_asprintf(sz_devfile, "%s/%d.%d.000", bkpinfo->tmpdir, (int) (random() % 32768), (int) (random() % 32768));
    14661365        mkfifo(sz_devfile, 0x770);
    1467         strcpy(ntfsprog_fifo, sz_devfile);
     1366        mr_asprintf(ntfsprog_fifo, "%s", sz_devfile);
     1367        mr_free(sz_devfile);
     1368
    14681369        file_to_openout = ntfsprog_fifo;
    14691370        switch (pid = fork()) {
     
    14711372            fatal_error("Fork failure");
    14721373        case 0:
    1473             log_msg(3,
    1474                     "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
    1475                     outfile_fname, ntfsprog_fifo);
    1476             res =
    1477                 feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
    1478 //          log_msg(3, "CHILD - fip - exiting");
     1374            log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", outfile_fname, ntfsprog_fifo);
     1375            res = feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
     1376            mr_free(ntfsprog_fifo);
    14791377            exit(res);
    14801378            break;
    14811379        default:
    1482             log_msg(3,
    1483                     "feed_into_ntfsprog() called in background --- pid=%ld",
    1484                     (long int) (pid));
    1485         }
    1486     } else {
    1487         if (!strncmp(orig_bf_fname, "/dev/", 5))    // non-NTFS partition
    1488         {
    1489             strcpy(outfile_fname, orig_bf_fname);
    1490         } else                  // biggiefile
    1491         {
    1492             sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
    1493                     orig_bf_fname);
     1380            log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
     1381        }
     1382        mr_free(ntfsprog_fifo);
     1383    } else {
     1384        if (!strncmp(orig_bf_fname, "/dev/", 5))    {
     1385            // non-NTFS partition
     1386            mr_asprintf(outfile_fname, "%s", orig_bf_fname);
     1387        } else {
     1388            // biggiefile
     1389            mr_asprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, orig_bf_fname);
    14941390        }
    14951391        use_ntfsprog_hack = FALSE;
    1496         ntfsprog_fifo[0] = '\0';
    14971392        file_to_openout = outfile_fname;
    14981393        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
     
    15001395            make_hole_for_file(outfile_fname);
    15011396        }
    1502         sprintf(tmp, "Reassembling big file %ld (%s)",
    1503                 biggiefile_number + 1, orig_bf_fname);
    1504         log_msg(2, tmp);
     1397        log_msg(2, "Reassembling big file %ld (%s)", biggiefile_number + 1, orig_bf_fname);
    15051398    }
    15061399
    15071400    if (dummy_restore) {
    1508         sprintf(outfile_fname, "/dev/null");
     1401        mr_free(outfile_fname);
     1402        mr_asprintf(outfile_fname, "/dev/null");
    15091403    }
    15101404
    15111405    if (!bkpinfo->zip_exe[0]) {
    1512         sprintf(command, "cat > \"%s\"", file_to_openout);
    1513     } else {
    1514         sprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe,
    1515                 file_to_openout, MONDO_LOGFILE);
     1406        mr_asprintf(command, "cat > \"%s\"", file_to_openout);
     1407    } else {
     1408        mr_asprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe, file_to_openout, MONDO_LOGFILE);
    15161409        if (strcmp(bkpinfo->zip_exe, "gzip") == 0) {
    15171410            /* Ignore SIGPIPE for gzip as it causes errors on big files
    1518              * Cf: http://trac.mondorescue.org/ticket/244
    1519              */
     1411             * Cf: http://trac.mondorescue.org/ticket/244 */
    15201412            signal(SIGPIPE,SIG_IGN);
    15211413        }
    15221414    }
    1523     sprintf(tmp, "Pipe command = '%s'", command);
    1524     log_msg(3, tmp);
     1415    log_msg(3, "Pipe command = '%s'", command);
    15251416
    15261417    /* restore biggiefile, one slice at a time */
     
    15281419        fatal_error("Cannot pipe out");
    15291420    }
     1421    mr_free(command);
     1422
    15301423    for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
    15311424         ctrl_chr != BLK_STOP_A_BIGGIE;
     
    15341427            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
    15351428        }
    1536         sprintf(tmp, "Working on file #%ld, slice #%ld    ",
    1537                 biggiefile_number + 1, current_slice_number);
    1538         log_msg(2, tmp);
     1429        log_msg(2, "Working on file #%ld, slice #%ld    ", biggiefile_number + 1, current_slice_number);
    15391430        if (!g_text_mode) {
    15401431            newtDrawRootText(0, g_noof_rows - 2, tmp);
     
    15751466    if (bkpinfo->zip_exe[0]) {
    15761467        if (strcmp(bkpinfo->zip_exe, "gzip") == 0) {
    1577             /* Re-enable SIGPIPE for gzip
    1578              */
     1468            /* Re-enable SIGPIPE for gzip */
    15791469            signal(SIGPIPE, terminate_daemon);
    15801470        }
     
    15861476    if (use_ntfsprog_hack) {
    15871477        log_msg(3, "Waiting for ntfsclone to finish");
    1588         sprintf(tmp,
    1589                 " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
    1590         while (system(tmp) == 0) {
     1478        mr_asprintf(tmp1, " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
     1479        while (system(tmp1) == 0) {
    15911480            sleep(1);
    15921481        }
     1482        mr_free(tmp1);
    15931483        log_msg(3, "OK, ntfsclone has really finished");
    15941484    }
     
    15981488    if (strcmp(outfile_fname, "/dev/null")) {
    15991489        chmod(outfile_fname, biggiestruct.properties.st_mode);
    1600         if (chown(outfile_fname, biggiestruct.properties.st_uid,
    1601               biggiestruct.properties.st_gid)) {
     1490        if (chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid)) {
    16021491            // FIXME
    16031492        }
     
    16061495        utime(outfile_fname, ubuf);
    16071496    }
     1497    mr_free(outfile_fname);
    16081498
    16091499    paranoid_free(tmp);
    1610     paranoid_free(outfile_fname);
    1611     paranoid_free(command);
    1612     paranoid_free(ntfsprog_command);
    1613     paranoid_free(sz_devfile);
    1614     paranoid_free(ntfsprog_fifo);
    16151500    g_loglevel = old_loglevel;
    16161501    return (retval);
     
    16451530  /** malloc **/
    16461531    char *command = NULL;
    1647     char *tmp;
    1648     char *filelist_name;
    1649     char *filelist_subset_fname;
    1650     char *executable;
    1651     char *temp_log;
    1652     char screen_message[100];
     1532    char *tmp = NULL;
     1533    char *filelist_name = NULL;
     1534    char *filelist_subset_fname = NULL;
     1535    char *executable = NULL;
     1536    char *temp_log = NULL;
    16531537    long matches = 0;
    16541538    bool use_star;
    1655     char *xattr_fname;
    1656     char *acl_fname;
    1657 //  char files_to_restore_this_time_fname[MAX_STR_LEN];
     1539    char *xattr_fname = NULL;
     1540    char *acl_fname = NULL;
    16581541
    16591542    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    1660     malloc_string(tmp);
    1661     malloc_string(filelist_name);
    1662     malloc_string(filelist_subset_fname);
    1663     malloc_string(executable);
    1664     malloc_string(temp_log);
    1665     malloc_string(xattr_fname);
    1666     malloc_string(acl_fname);
    16671543
    16681544    log_msg(5, "Entering");
    1669     filelist_subset_fname[0] = '\0';
    16701545    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
    1671 //  sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random());
    16721546    mr_asprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
    16731547    run_program_and_log_output(command, 9);
    16741548    paranoid_free(command);
    16751549
    1676     sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768),
    1677             (int) (random() % 32768));
    1678 
    1679     sprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld",
    1680             current_tarball_number);
     1550    mr_asprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld", current_tarball_number);
    16811551    if (length_of_file(filelist_name) <= 2) {
    1682         log_msg(2, "There are _zero_ files in filelist '%s'",
    1683                 filelist_name);
    1684         log_msg(2,
    1685                 "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)");
    1686         log_msg(2,
    1687                 "but it's non-critical. It's cosmetic. Don't worry about it.");
     1552        log_msg(2, "There are _zero_ files in filelist '%s'", filelist_name);
     1553        log_msg(2, "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)");
     1554        log_msg(2, "but it's non-critical. It's cosmetic. Don't worry about it.");
    16881555        retval = 0;
    1689         goto leave_sub;
    1690     }
    1691     if (count_lines_in_file(filelist_name) <= 0
    1692         || length_of_file(tarball_fname) <= 0) {
     1556        mr_free(filelist_name);
     1557        log_msg(5, "Leaving");
     1558        return(0);
     1559    }
     1560    if (count_lines_in_file(filelist_name) <= 0 || length_of_file(tarball_fname) <= 0) {
    16931561        log_msg(3, "length_of_file(%s) = %llu", tarball_fname, length_of_file(tarball_fname));
    16941562        log_msg(3, "count_lines_in_file(%s) = %llu", tarball_fname, count_lines_in_file(tarball_fname));
    1695         sprintf(tmp, "Unable to restore fileset #%ld (CD I/O error)",
    1696                 current_tarball_number);
    1697         log_to_screen(tmp);
    1698         retval = 1;
    1699         goto leave_sub;
     1563        log_to_screen("Unable to restore fileset #%ld (CD I/O error)", current_tarball_number);
     1564        mr_free(filelist_name);
     1565        log_msg(5, "Leaving");
     1566        return(1);
    17001567    }
    17011568
    17021569    if (filelist) {
    1703         sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp",
    1704                 current_tarball_number);
     1570        mr_asprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", current_tarball_number);
    17051571        if ((matches =
    17061572             save_filelist_entries_in_common(filelist_name, filelist,
    17071573                                             filelist_subset_fname,
    1708                                              use_star))
    1709             <= 0) {
    1710             sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
    1711             log_msg(1, tmp);
     1574                                             use_star)) <= 0) {
     1575            log_msg(1, "Skipping fileset %ld", current_tarball_number);
    17121576        } else {
    1713             log_msg(3, "Saved fileset %ld's subset to %s",
    1714                     current_tarball_number, filelist_subset_fname);
    1715         }
    1716         sprintf(screen_message, "Tarball #%ld --- %ld matches",
    1717                 current_tarball_number, matches);
    1718         log_to_screen(screen_message);
    1719     } else {
    1720         filelist_subset_fname[0] = '\0';
    1721     }
     1577            log_msg(3, "Saved fileset %ld's subset to %s", current_tarball_number, filelist_subset_fname);
     1578        }
     1579        log_to_screen("Tarball #%ld --- %ld matches", current_tarball_number, matches);
     1580    }
     1581    mr_free(filelist_name);
    17221582
    17231583    if (filelist == NULL || matches > 0) {
    17241584        if (g_getfattr) {
    1725             sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ,
    1726                 MNT_CDROM "/archives", current_tarball_number);
     1585            mr_asprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", current_tarball_number);
    17271586        }
    17281587        if (g_getfacl) {
    1729             sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",
    1730                 current_tarball_number);
     1588            mr_asprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", current_tarball_number);
    17311589        }
    17321590        if (strstr(tarball_fname, ".bz2")) {
    1733             strcpy(executable, "bzip2");
     1591            mr_asprintf(executable, "bzip2");
     1592        } else if (strstr(tarball_fname, ".lzma")) {
     1593            mr_asprintf(executable, "lzma");
    17341594        } else if (strstr(tarball_fname, ".gz")) {
    1735             strcpy(executable, "gzip");
     1595            mr_asprintf(executable, "gzip");
    17361596        } else if (strstr(tarball_fname, ".lzo")) {
    1737             strcpy(executable, "lzop");
    1738         } else {
    1739             executable[0] = '\0';
    1740         }
    1741         if (executable[0]) {
    1742             sprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);
    1743             if (run_program_and_log_output(tmp, FALSE)) {
    1744                 log_to_screen
    1745                     ("(compare_a_tarball) Compression program %s not found - oh no!", executable);
     1597            mr_asprintf(executable, "lzop");
     1598        }
     1599        if (executable) {
     1600            mr_asprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);
     1601            res = run_program_and_log_output(tmp, FALSE);
     1602            mr_free(tmp);
     1603
     1604            if (res) {
     1605                log_to_screen("(compare_a_tarball) Compression program %s not found - oh no!", executable);
    17461606                paranoid_MR_finish(1);
    17471607            }
    1748             strcpy(tmp, executable);
    1749             sprintf(executable, "-P %s -Z", tmp);
     1608            tmp = executable;
     1609            mr_asprintf(executable, "-P %s -Z", tmp);
     1610            mr_free(tmp);
    17501611        }
    17511612#ifdef __FreeBSD__
     
    17551616#endif
    17561617
    1757 //      if (strstr(tarball_fname, ".star."))
    17581618        if (use_star) {
    17591619            mr_asprintf(command, "star -x -force-remove -sparse -U " STAR_ACL_SZ " file=%s", tarball_fname);
     
    17621622            }
    17631623        } else {
    1764             if (filelist_subset_fname[0] != '\0') {
    1765                 mr_asprintf(command, "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, filelist_subset_fname, tarball_fname);
     1624            if (! executable) {
     1625                log_msg(2, "Mo executable, this shouldn't happen !");
    17661626            } else {
    1767                 mr_asprintf(command, "afio -i -b %ld -c %ld -M 8m %s %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, tarball_fname);
    1768             }
    1769         }
     1627                if (filelist_subset_fname != NULL) {
     1628                    mr_asprintf(command, "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, filelist_subset_fname, tarball_fname);
     1629                } else {
     1630                    mr_asprintf(command, "afio -i -b %ld -c %ld -M 8m %s %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, tarball_fname);
     1631                }
     1632            }
     1633        }
     1634        mr_free(executable);
    17701635
    17711636#undef BUFSIZE
     1637        mr_asprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768), (int) (random() % 32768));
     1638
    17721639        mr_strcat(command, " 2>> %s >> %s", temp_log, temp_log);
    17731640        log_msg(1, "command = '%s'", command);
     
    18281695            log_msg(2, "Fileset #%d processed OK", current_tarball_number);
    18291696        }
     1697        unlink(temp_log);
     1698        mr_free(temp_log);
    18301699    }
    18311700    if (does_file_exist("/PAUSE")) {
     
    18341703    }
    18351704    unlink(filelist_subset_fname);
    1836     unlink(xattr_fname);
    1837     unlink(acl_fname);
    1838     unlink(temp_log);
    1839 
    1840   leave_sub:
    1841     paranoid_free(tmp);
    1842     paranoid_free(filelist_name);
    1843     paranoid_free(filelist_subset_fname);
    1844     paranoid_free(executable);
    1845     paranoid_free(temp_log);
    1846     paranoid_free(xattr_fname);
    1847     paranoid_free(acl_fname);
     1705    mr_free(filelist_subset_fname);
     1706    if (g_getfattr) {
     1707        unlink(xattr_fname);
     1708        mr_free(xattr_fname);
     1709    }
     1710    if (g_getfacl) {
     1711        unlink(acl_fname);
     1712        mr_free(acl_fname);
     1713    }
     1714
    18481715    log_msg(5, "Leaving");
    18491716    return (retval);
     
    18811748
    18821749  /** malloc add ***/
    1883     char *tmp;
    18841750    char *mds = NULL;
    1885     char *command;
    1886     char *afio_fname;
    1887     char *filelist_fname;
    1888     char *filelist_subset_fname;
    1889     char *executable;
     1751    char *command = NULL;
     1752    char *afio_fname = NULL;
     1753    char *filelist_fname = NULL;
     1754    char *filelist_subset_fname = NULL;
     1755    char *executable = NULL;
    18901756    long matches = 0;
    18911757    bool restore_this_fileset = FALSE;
     
    18941760    assert(bkpinfo != NULL);
    18951761    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    1896     malloc_string(filelist_subset_fname);
    1897     malloc_string(filelist_fname);
    1898     malloc_string(afio_fname);
    1899     malloc_string(executable);
    1900     malloc_string(command);
    1901     malloc_string(tmp);
    1902     filelist_subset_fname[0] = '\0';
     1762
    19031763    /* to do it with a file... */
    19041764    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
    19051765    mds = media_descriptor_string(bkpinfo->backup_media_type);
    1906     sprintf(tmp,
    1907             "Restoring from fileset #%ld (%ld KB) on %s #%d",
     1766    log_msg(2, "Restoring from fileset #%ld (%ld KB) on %s #%d",
    19081767            current_tarball_number, (long) size >> 10, mds, g_current_media_number);
    19091768    mr_free(mds);
    19101769
    1911     log_msg(2, tmp);
    19121770    run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
    19131771
     
    19171775   * in afio or someting; oh darn.. OK, use tmpfs :-)                         *
    19181776   ****************************************************************************/
    1919     filelist_fname[0] = filelist_subset_fname[0] = '\0';
    1920     sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld",
    1921             current_tarball_number);
    1922     sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,
    1923             current_tarball_number);
    1924     sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp",
    1925             bkpinfo->tmpdir, current_tarball_number);
    1926 //  sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number);
     1777    mr_asprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", current_tarball_number);
     1778    mr_asprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, current_tarball_number);
     1779    mr_asprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", bkpinfo->tmpdir, current_tarball_number);
     1780
    19271781    res = read_file_from_stream_to_file(afio_fname, size);
    19281782    if (strstr(tarball_fname, ".star")) {
     
    19331787    }
    19341788    if (bkpinfo->compression_level == 0) {
    1935         executable[0] = '\0';
     1789        mr_asprintf(executable, "%s", "");
    19361790    } else {
    19371791        if (bkpinfo->use_star) {
    1938             strcpy(executable, " -bz");
     1792            mr_asprintf(executable, "%s", " -bz");
    19391793        } else {
    1940             sprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
     1794            mr_asprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
    19411795        }
    19421796    }
     
    19491803        if (strstr(tarball_fname, ".star.")) {
    19501804            use_star = TRUE;
    1951             sprintf(command, "star -sparse -t file=%s %s", afio_fname, executable);
     1805            mr_asprintf(command, "star -sparse -t file=%s %s", afio_fname, executable);
    19521806        } else {
    19531807            use_star = FALSE;
    1954             sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
    1955                     executable, afio_fname);
    1956         }
    1957         sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname,
    1958                 MONDO_LOGFILE);
     1808            mr_asprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, executable, afio_fname);
     1809        }
     1810        mr_strcat(command, " > %s 2>> %s", filelist_fname, MONDO_LOGFILE);
    19591811        log_msg(1, "command = %s", command);
    19601812        if (system(command)) {
    19611813            log_msg(4, "Warning - error occurred while retrieving TOC");
    19621814        }
     1815        mr_free(command);
     1816
    19631817        if ((matches =
    19641818             save_filelist_entries_in_common(filelist_fname, filelist,
     
    19701824                        current_tarball_number);
    19711825            }
    1972             sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
    1973             log_msg(2, tmp);
     1826            log_msg(2, "Skipping fileset %ld", current_tarball_number);
    19741827            restore_this_fileset = FALSE;
    19751828        } else {
     
    19821835
    19831836// Concoct the call to star/afio to restore files
    1984     if (strstr(tarball_fname, ".star."))    // star
    1985     {
    1986         sprintf(command, "star -sparse -x file=%s %s", afio_fname, executable);
     1837    if (strstr(tarball_fname, ".star.")) {
     1838        // star
     1839        mr_asprintf(command, "star -sparse -x file=%s %s", afio_fname, executable);
    19871840        if (filelist) {
    1988             sprintf(command + strlen(command), " list=%s",
    1989                     filelist_subset_fname);
    1990         }
    1991     } else                      // afio
    1992     {
    1993         sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE,
    1994                 executable);
     1841            mr_strcat(command, " list=%s", filelist_subset_fname);
     1842        }
     1843    } else {
     1844        // afio
     1845        mr_asprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, executable);
    19951846        if (filelist) {
    1996             sprintf(command + strlen(command), " -w %s",
    1997                     filelist_subset_fname);
    1998         }
    1999         sprintf(command + strlen(command), " %s", afio_fname);
    2000     }
    2001     sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);
     1847            mr_strcat(command, " -w %s", filelist_subset_fname);
     1848        }
     1849        mr_strcat(command, " %s", afio_fname);
     1850    }
     1851    mr_strcat(command, " 2>> %s", MONDO_LOGFILE);
     1852    mr_free(executable);
    20021853
    20031854// Call if IF there are files to restore (selectively/unconditionally)
     
    20311882        log_msg(1, "NOT CALLING '%s'", command);
    20321883    }
     1884    mr_free(command);
    20331885
    20341886    if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
     
    20381890
    20391891    unlink(filelist_subset_fname);
     1892    mr_free(filelist_subset_fname);
    20401893    unlink(filelist_fname);
     1894    mr_free(filelist_fname);
    20411895    unlink(afio_fname);
    2042 
    2043     paranoid_free(filelist_subset_fname);
    2044     paranoid_free(filelist_fname);
    2045     paranoid_free(afio_fname);
    2046     paranoid_free(command);
    2047     paranoid_free(tmp);
     1896    mr_free(afio_fname);
     1897
    20481898    return (retval);
    20491899}
     
    20651915 * @return 0 for success, nonzero for failure.
    20661916 */
    2067 int
    2068 restore_all_biggiefiles_from_CD(struct s_node *filelist)
    2069 {
     1917int restore_all_biggiefiles_from_CD(struct s_node *filelist) {
     1918
    20701919    int retval = 0;
    20711920    int res = 0;
    20721921    long noof_biggiefiles, bigfileno = 0, total_slices;
    20731922  /** malloc **/
    2074     char *tmp;
     1923    char *tmp = NULL;
     1924    char *tmp1 = NULL;
    20751925    char *mds = NULL;
    20761926    bool just_changed_cds = FALSE;
    2077     char *xattr_fname;
    2078     char *acl_fname;
    2079     char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
     1927    char *xattr_fname = NULL;
     1928    char *acl_fname = NULL;
     1929    char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
    20801930    char *pathname_of_last_biggie_restored;
    20811931    FILE *fbw = NULL;
    20821932
    2083     malloc_string(xattr_fname);
    2084     malloc_string(acl_fname);
     1933    malloc_string(pathname_of_last_biggie_restored);
    20851934    malloc_string(tmp);
    2086     malloc_string(biggies_whose_EXATs_we_should_set);
    2087     malloc_string(pathname_of_last_biggie_restored);
    20881935    assert(bkpinfo != NULL);
    20891936
    2090     sprintf(biggies_whose_EXATs_we_should_set,
    2091             "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
     1937    mr_asprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
    20921938    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
    2093         log_msg(1, "Warning - cannot openout %s",
    2094                 biggies_whose_EXATs_we_should_set);
     1939        log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set);
    20951940    }
    20961941
    20971942    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
    20981943    total_slices = atol(tmp);
    2099     sprintf(tmp, "Reassembling large files      ");
    2100     mvaddstr_and_log_it(g_currentY, 0, tmp);
     1944    mr_free(tmp);
     1945
     1946    mr_asprintf(tmp1, "Reassembling large files      ");
     1947    mvaddstr_and_log_it(g_currentY, 0, tmp1);
     1948    mr_free(tmp1);
     1949
    21011950    if (length_of_file(BIGGIELIST) < 6) {
    21021951        log_msg(1, "OK, no biggielist; not restoring biggiefiles");
     
    21051954    noof_biggiefiles = count_lines_in_file(BIGGIELIST);
    21061955    if (noof_biggiefiles <= 0) {
    2107         log_msg(2,
    2108                 "OK, no biggiefiles in biggielist; not restoring biggiefiles");
     1956        log_msg(2, "OK, no biggiefiles in biggielist; not restoring biggiefiles");
    21091957        return (0);
    21101958    }
    2111     sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
    2112             noof_biggiefiles);
    2113     log_msg(2, tmp);
     1959    log_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
    21141960
    21151961    open_progress_form("Reassembling large files",
     
    21201966        log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
    21211967        if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
    2122             log_msg(3,
    2123                     "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
     1968            log_msg(3, "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
    21241969            mds = media_descriptor_string(bkpinfo->backup_media_type);
    2125             log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d",
    2126                     bigfileno + 1, mds,
    2127                     g_current_media_number);
     1970            log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", bigfileno + 1, mds, g_current_media_number);
    21281971            log_msg(3, "Slicename would have been %s",
    21291972                    slice_fname(bigfileno, 0, ARCHIVES_PATH, ""));
     
    21311974            if (just_changed_cds) {
    21321975                just_changed_cds = FALSE;
    2133                 log_msg(3,
    2134                         "I'll continue to scan this CD for bigfiles to be restored.");
     1976                log_msg(3, "I'll continue to scan this CD for bigfiles to be restored.");
    21351977            } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
    21361978                insist_on_this_cd_number(++g_current_media_number);
    2137                 sprintf(tmp, "Restoring from %s #%d", mds,
    2138                         g_current_media_number);
    2139                 log_to_screen(tmp);
     1979                log_to_screen("Restoring from %s #%d", mds, g_current_media_number);
    21401980                just_changed_cds = TRUE;
    21411981            } else {
    21421982                /* That big file doesn't exist, but the followings may */
    21431983                /* So we need to continue looping */
    2144                 log_msg(2, "There was no bigfile #%ld. That's OK.",
    2145                     bigfileno + 1);
     1984                log_msg(2, "There was no bigfile #%ld. That's OK.", bigfileno + 1);
    21461985                log_msg(2, "I'm going to stop restoring bigfiles now.");
    21471986                retval++;
     
    21511990        } else {
    21521991            just_changed_cds = FALSE;
    2153             sprintf(tmp, "Restoring big file %ld", bigfileno + 1);
    2154             update_progress_form(tmp);
    2155             res =
    2156                 restore_a_biggiefile_from_CD(bigfileno, filelist, pathname_of_last_biggie_restored);
     1992            mr_asprintf(tmp1, "Restoring big file %ld", bigfileno + 1);
     1993            update_progress_form(tmp1);
     1994            mr_free(tmp1);
     1995            res = restore_a_biggiefile_from_CD(bigfileno, filelist, pathname_of_last_biggie_restored);
    21571996            log_it("%s",pathname_of_last_biggie_restored);
    21581997            if (fbw && pathname_of_last_biggie_restored[0]) {
     
    21682007        fclose(fbw);
    21692008        if (g_getfattr) {
    2170             sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
     2009            mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
    21712010            if (length_of_file(xattr_fname) > 0) {
    21722011                set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
    21732012            }
     2013            mr_free(xattr_fname);
    21742014        }
    21752015        if (g_getfacl) {
    2176             sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
     2016            mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
    21772017            if (length_of_file(acl_fname) > 0) {
    21782018                set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
    21792019            }
    2180         }
    2181     }
     2020            mr_free(acl_fname);
     2021        }
     2022    }
     2023    mr_free(biggies_whose_EXATs_we_should_set);
     2024
    21822025    if (does_file_exist("/PAUSE")) {
    2183         popup_and_OK
    2184             ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
     2026        popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
    21852027    }
    21862028    close_progress_form();
     
    21902032        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    21912033    }
    2192     paranoid_free(xattr_fname);
    2193     paranoid_free(acl_fname);
    2194     paranoid_free(tmp);
    2195     paranoid_free(biggies_whose_EXATs_we_should_set);
    21962034    paranoid_free(pathname_of_last_biggie_restored);
    21972035    return (retval);
     
    22202058    int res;
    22212059    int attempts;
    2222     long current_tarball_number = 0;
     2060    long current_tarball_number = 0L;
    22232061    long max_val;
    22242062  /**malloc ***/
     2063    char *mds = NULL;
    22252064    char *tmp = NULL;
    2226     char *mds = NULL;
    22272065    char *tmp1 = NULL;
    2228     char *tarball_fname;
    2229     char *progress_str;
    2230     char *comment;
     2066    char *tarball_fname = NULL;
     2067    char *progress_str = NULL;
     2068
     2069    assert(bkpinfo != NULL);
    22312070
    22322071    malloc_string(tmp);
    2233     malloc_string(tarball_fname);
    2234     malloc_string(progress_str);
    2235     malloc_string(comment);
    2236 
    2237     assert(bkpinfo != NULL);
    2238 
    22392072    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
    2240     log_msg(2,
    2241             "Insisting on 1st media, so that I can have a look at LAST-FILELIST-NUMBER");
     2073    log_msg(2, "Insisting on 1st media, so that I can have a look at LAST-FILELIST-NUMBER");
    22422074    if (g_current_media_number != 1) {
    22432075        log_msg(3, "OK, that's jacked up.");
     
    22502082
    22512083    mds = media_descriptor_string(bkpinfo->backup_media_type);
    2252     sprintf(progress_str, "Restoring from %s #%d", mds, g_current_media_number);
     2084    mr_asprintf(progress_str, "Restoring from %s #%d", mds, g_current_media_number);
    22532085
    22542086    log_to_screen(progress_str);
     
    22602092        insist_on_this_cd_number(g_current_media_number);
    22612093        update_progress_form(progress_str);
    2262         sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2",
    2263                 current_tarball_number);
     2094        mr_free(progress_str);
     2095
     2096        mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2", current_tarball_number);
    22642097        if (!does_file_exist(tarball_fname)) {
    2265             sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.gz",
    2266                 current_tarball_number);
     2098            mr_free(tarball_fname);
     2099            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.gz", current_tarball_number);
    22672100        }
    22682101        if (!does_file_exist(tarball_fname)) {
    2269             sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
    2270                     current_tarball_number);
     2102            mr_free(tarball_fname);
     2103            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzma", current_tarball_number);
    22712104        }
    22722105        if (!does_file_exist(tarball_fname)) {
    2273             sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.",
    2274                     current_tarball_number);
     2106            mr_free(tarball_fname);
     2107            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo", current_tarball_number);
    22752108        }
    22762109        if (!does_file_exist(tarball_fname)) {
    2277             sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
    2278                     current_tarball_number);
     2110            mr_free(tarball_fname);
     2111            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.", current_tarball_number);
    22792112        }
    22802113        if (!does_file_exist(tarball_fname)) {
    2281             sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.",
    2282                     current_tarball_number);
     2114            mr_free(tarball_fname);
     2115            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2", current_tarball_number);
     2116        }
     2117        if (!does_file_exist(tarball_fname)) {
     2118            mr_free(tarball_fname);
     2119            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.", current_tarball_number);
    22832120        }
    22842121        if (!does_file_exist(tarball_fname)) {
     
    22862123                log_to_screen
    22872124                    ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
     2125                mr_free(tarball_fname);
    22882126                return (0);
    22892127            }
     
    22952133            }
    22962134            g_current_media_number++;
    2297             sprintf(progress_str, "Restoring from %s #%d",
    2298                     media_descriptor_string(bkpinfo->backup_media_type),
    2299                     g_current_media_number);
     2135            mr_asprintf(progress_str, "Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    23002136            log_to_screen(progress_str);
    23012137        } else {
    2302             sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
    2303                     current_tarball_number, mds, g_current_media_number);
    2304 //    log_msg(3, "progress_str = %s", progress_str);
    2305             for (res = 999, attempts = 0; attempts < 3 && res != 0;
    2306                  attempts++) {
    2307                 res =
    2308                     restore_a_tarball_from_CD(tarball_fname,
    2309                                               current_tarball_number,
    2310                                               filelist);
    2311             }
    2312             mr_asprintf(tmp1, "%s #%d, fileset #%ld - restore ",
    2313                     mds, g_current_media_number, current_tarball_number);
     2138            mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_tarball_number, mds, g_current_media_number);
     2139            for (res = 999, attempts = 0; attempts < 3 && res != 0; attempts++) {
     2140                res = restore_a_tarball_from_CD(tarball_fname, current_tarball_number, filelist);
     2141            }
     2142            mr_asprintf(tmp1, "%s #%d, fileset #%ld - restore ", mds, g_current_media_number, current_tarball_number);
    23142143            if (res) {
    23152144                mr_strcat(tmp1, "reported errors");
     
    23222151                mr_strcat(tmp1, " (%d attempts) - review logs", attempts);
    23232152            }
    2324             strcpy(comment, tmp1);
    2325             paranoid_free(tmp1);
    23262153            if (attempts > 1) {
    2327                 log_to_screen(comment);
    2328             }
     2154                log_to_screen(tmp1);
     2155            }
     2156            mr_free(tmp1);
    23292157
    23302158            retval += res;
     
    23322160            g_current_progress++;
    23332161        }
     2162        mr_free(tarball_fname);
     2163
    23342164        /* Now we need to umount the current media to have the next mounted by insist_on_this_cd_number */
    23352165        /*   run_program_and_log_output("umount " MNT_CDROM, FALSE); */
    23362166    }
    23372167    mr_free(mds);
     2168    mr_free(progress_str);
    23382169
    23392170    close_progress_form();
     
    23432174        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    23442175    }
    2345     paranoid_free(tarball_fname);
    2346     paranoid_free(progress_str);
    2347     paranoid_free(comment);
    23482176
    23492177    return (retval);
     
    23752203
    23762204  /** malloc add ****/
    2377     char *tmp;
     2205    char *tmp = NULL;
    23782206    char *biggie_fname;
    23792207    char *biggie_cksum;
    2380     char *xattr_fname;
    2381     char *acl_fname;
     2208    char *xattr_fname = NULL;
     2209    char *acl_fname = NULL;
    23822210    char *p;
    23832211    char *pathname_of_last_biggie_restored;
    2384     char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
     2212    char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
    23852213    long long biggie_size;
    23862214    FILE *fbw = NULL;
     
    23892217    malloc_string(biggie_fname);
    23902218    malloc_string(biggie_cksum);
    2391     malloc_string(xattr_fname);
    2392     malloc_string(acl_fname);
    2393     malloc_string(biggies_whose_EXATs_we_should_set);
    23942219    malloc_string(pathname_of_last_biggie_restored);
    23952220    assert(bkpinfo != NULL);
     
    23982223
    23992224    total_slices = atol(tmp);
    2400     sprintf(tmp, "Reassembling large files      ");
     2225
    24012226    if (g_getfattr) {
    2402         sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2227        mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    24032228    }
    24042229    if (g_getfacl) {
    2405         sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    2406     }
    2407     mvaddstr_and_log_it(g_currentY, 0, tmp);
    2408     sprintf(biggies_whose_EXATs_we_should_set,
    2409             "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
     2230        mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2231    }
     2232    mr_asprintf(tmp1, "Reassembling large files      ");
     2233    mvaddstr_and_log_it(g_currentY, 0, tmp1);
     2234    mr_free(tmp1);
     2235
     2236    mr_asprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
    24102237    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
    2411         log_msg(1, "Warning - cannot openout %s",
    2412                 biggies_whose_EXATs_we_should_set);
    2413     }
    2414 // get xattr and acl files if they're there
    2415     res =
    2416         read_header_block_from_stream(&biggie_size, biggie_fname,
    2417                                       &ctrl_chr);
     2238        log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set);
     2239    }
     2240
     2241    // get xattr and acl files if they're there
     2242    res = read_header_block_from_stream(&biggie_size, biggie_fname, &ctrl_chr);
    24182243    if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
    2419         res = read_EXAT_files_from_tape(&biggie_size, biggie_fname,
    2420                                       &ctrl_chr, xattr_fname, acl_fname);
     2244        res = read_EXAT_files_from_tape(&biggie_size, biggie_fname, &ctrl_chr, xattr_fname, acl_fname);
    24212245    }
    24222246
    24232247    noof_biggiefiles = atol(biggie_fname);
    2424     sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
    2425             noof_biggiefiles);
    2426     log_msg(2, tmp);
     2248    log_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
    24272249    open_progress_form("Reassembling large files",
    24282250                       "I am now reassembling all the large files.",
     
    24472269            p++;
    24482270        }
    2449         sprintf(tmp, "Restoring big file %ld (%lld K)",
    2450                 current_bigfile_number + 1, biggie_size / 1024);
    2451         update_progress_form(tmp);
     2271        mr_asprintf(tmp1, "Restoring big file %ld (%lld K)", current_bigfile_number + 1, biggie_size / 1024);
     2272        update_progress_form(tmp1);
     2273        mr_free(tmp1);
    24522274        res = restore_a_biggiefile_from_stream(biggie_fname,
    24532275                                               current_bigfile_number,
     
    24672289    if (current_bigfile_number != noof_biggiefiles
    24682290        && noof_biggiefiles != 0) {
    2469         sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
    2470                 current_bigfile_number, noof_biggiefiles);
    2471     } else {
    2472         sprintf(tmp,
    2473                 "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
    2474                 noof_biggiefiles, current_bigfile_number);
    2475     }
    2476     log_msg(1, tmp);
     2291        log_msg(1, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n", current_bigfile_number, noof_biggiefiles);
     2292    } else {
     2293        log_msg(1, "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", noof_biggiefiles, current_bigfile_number);
     2294    }
    24772295
    24782296    if (fbw) {
     
    24822300            if (g_getfattr) {
    24832301                if (length_of_file(xattr_fname) > 0) {
    2484                     log_msg(1, "set_fattr_List(%s,%s)",
    2485                         biggies_whose_EXATs_we_should_set, xattr_fname);
    2486                     set_fattr_list(biggies_whose_EXATs_we_should_set,
    2487                                xattr_fname);
     2302                    log_msg(1, "set_fattr_List(%s,%s)", biggies_whose_EXATs_we_should_set, xattr_fname);
     2303                    set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
    24882304                }
    24892305            }
    24902306            if (g_getfacl) {
    24912307                if (length_of_file(acl_fname) > 0) {
    2492                     log_msg(1, "set_acl_list(%s,%s)",
    2493                             biggies_whose_EXATs_we_should_set, acl_fname);
     2308                    log_msg(1, "set_acl_list(%s,%s)", biggies_whose_EXATs_we_should_set, acl_fname);
    24942309                    set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
    24952310                }
     
    24992314        }
    25002315    }
     2316    mr_free(xattr_fname);
     2317    mr_free(acl_fname);
     2318    mr_free(biggies_whose_EXATs_we_should_set);
     2319
    25012320    if (does_file_exist("/PAUSE")) {
    25022321        popup_and_OK
     
    25102329        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    25112330    }
    2512     paranoid_free(biggies_whose_EXATs_we_should_set);
    25132331    paranoid_free(pathname_of_last_biggie_restored);
    25142332    paranoid_free(biggie_fname);
    25152333    paranoid_free(biggie_cksum);
    2516     paranoid_free(xattr_fname);
    2517     paranoid_free(acl_fname);
    25182334    paranoid_free(tmp);
    25192335    return (retval);
     
    25392355 * @return 0 for success, or the number of filesets that failed.
    25402356 */
    2541 int
    2542 restore_all_tarballs_from_stream(struct s_node *filelist)
     2357int restore_all_tarballs_from_stream(struct s_node *filelist)
    25432358{
    25442359    int retval = 0;
     
    25492364
    25502365  /** malloc **/
    2551     char *tmp;
     2366    char *tmp = NULL;
    25522367    char *mds = NULL;
    2553     char *progress_str;
     2368    char *progress_str = NULL;
    25542369    char *tmp_fname;
    2555     char *xattr_fname;
    2556     char *acl_fname;
     2370    char *xattr_fname = NULL;
     2371    char *acl_fname = NULL;
    25572372
    25582373    long long tmp_size;
    25592374
    25602375    malloc_string(tmp);
    2561     malloc_string(progress_str);
    25622376    malloc_string(tmp_fname);
    25632377    assert(bkpinfo != NULL);
    2564     malloc_string(xattr_fname);
    2565     malloc_string(acl_fname);
    25662378    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
    25672379    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
     
    25742386    run_program_and_log_output("pwd", 5);
    25752387
    2576     sprintf(progress_str, "Restoring from media #%d",
    2577             g_current_media_number);
     2388    mr_asprintf(progress_str, "Restoring from media #%d", g_current_media_number);
    25782389    log_to_screen(progress_str);
    25792390    open_progress_form("Restoring from archives",
     
    25972408        update_progress_form(progress_str);
    25982409        if (g_getfattr) {
    2599             sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
    2600                 current_afioball_number);
     2410            mr_asprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
    26012411            unlink(xattr_fname);
    26022412        }
    26032413        if (g_getfacl) {
    2604             sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
    2605                 current_afioball_number);
     2414            mr_asprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
    26062415            unlink(acl_fname);
    26072416        }
    26082417        if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
    26092418            log_it("Reading EXAT files from tape");
    2610             res = read_EXAT_files_from_tape(&tmp_size, tmp_fname,
    2611                                           &ctrl_chr, xattr_fname,
    2612                                           acl_fname);
     2419            res = read_EXAT_files_from_tape(&tmp_size, tmp_fname, &ctrl_chr, xattr_fname, acl_fname);
    26132420        }
    26142421        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
    26152422            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
    26162423        }
    2617         sprintf(tmp,
    2618                 "Restoring from fileset #%ld (name=%s, size=%ld K)",
    2619                 current_afioball_number, tmp_fname, (long) tmp_size >> 10);
    2620         res =
    2621             restore_a_tarball_from_stream(tmp_fname,
    2622                                           current_afioball_number,
    2623                                           filelist, tmp_size, xattr_fname,
    2624                                           acl_fname);
     2424        log_msg(4, "Restoring from fileset #%ld (name=%s, size=%ld K)", current_afioball_number, tmp_fname, (long) tmp_size >> 10);
     2425        res = restore_a_tarball_from_stream(tmp_fname, current_afioball_number, filelist, tmp_size, xattr_fname, acl_fname);
    26252426        retval += res;
    26262427        if (res) {
    2627             sprintf(tmp, "Fileset %ld - errors occurred",
    2628                     current_afioball_number);
    2629             log_to_screen(tmp);
     2428            log_to_screen("Fileset %ld - errors occurred", current_afioball_number);
    26302429        }
    26312430        res =
     
    26382437        g_current_progress++;
    26392438        mds = media_descriptor_string(bkpinfo->backup_media_type),
    2640         sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
    2641                 current_afioball_number, mds,
    2642                 g_current_media_number);
     2439
     2440        mr_free(progress_str);
     2441        mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_afioball_number, mds, g_current_media_number);
    26432442        mr_free(mds);
    2644         res =
    2645             read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
     2443        res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
    26462444        if (g_getfattr) {
    26472445            unlink(xattr_fname);
     
    26512449        }
    26522450    }                           // next
     2451    mr_free(progress_str);
     2452    if (g_getfattr) {
     2453        mr_free(xattr_fname);
     2454    }
     2455    if (g_getfacl) {
     2456        mr_free(acl_fname);
     2457    }
     2458
    26532459    log_msg(1, "All done with afioballs");
    26542460    close_progress_form();
     
    26592465    }
    26602466    paranoid_free(tmp);
    2661     paranoid_free(progress_str);
    26622467    paranoid_free(tmp_fname);
    2663     paranoid_free(xattr_fname);
    2664     paranoid_free(acl_fname);
    26652468    return (retval);
    26662469}
     
    26892492    char *cwd;
    26902493    char *newpath;
    2691     char *tmp;
     2494    char *tmp = NULL;
    26922495    assert(bkpinfo != NULL);
    26932496
    26942497    malloc_string(cwd);
    26952498    malloc_string(newpath);
    2696     malloc_string(tmp);
    26972499    log_msg(2, "restore_everything() --- starting");
    26982500    g_current_media_number = 1;
     
    27002502        // FIXME
    27012503    }
    2702     sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
     2504    mr_asprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
    27032505    run_program_and_log_output(tmp, FALSE);
     2506    mr_free(tmp);
     2507
    27042508    log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
    27052509    if (chdir(bkpinfo->restore_path)) {
     
    27552559    paranoid_free(cwd);
    27562560    paranoid_free(newpath);
    2757     paranoid_free(tmp);
    27582561    return (resA + resB);
    27592562}
     
    27762579{
    27772580    log_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
    2778     log_msg(0,
    2779             "DON'T PANIC! Mondorestore logs almost everything, so please ");
    2780     log_msg(0,
    2781             "don't break out in a cold sweat just because you see a few  ");
    2782     log_msg(0,
    2783             "error messages in the log. Read them; analyze them; see if  ");
    2784     log_msg(0,
    2785             "they are significant; above all, verify your backups! Please");
    2786     log_msg(0,
    2787             "attach a compressed copy of this log to any e-mail you send ");
    2788     log_msg(0,
    2789             "to the Mondo mailing list when you are seeking technical    ");
    2790     log_msg(0,
    2791             "support. Without it, we can't help you.            - DevTeam");
    2792     log_msg(0,
    2793             "------------------------------------------------------------");
    2794     log_msg(0,
    2795             "BTW, despite (or perhaps because of) the wealth of messages,");
    2796     log_msg(0,
    2797             "some users are inclined to stop reading this log.  If Mondo ");
    2798     log_msg(0,
    2799             "stopped for some reason, chances are it's detailed here.    ");
    2800     log_msg(0,
    2801             "More than likely there's a message at the very end of this  ");
    2802     log_msg(0,
    2803             "log that will tell you what is wrong.  Please read it!      ");
    2804     log_msg(0,
    2805             "------------------------------------------------------------");
     2581    log_msg(0, "DON'T PANIC! Mondorestore logs almost everything, so please ");
     2582    log_msg(0, "don't break out in a cold sweat just because you see a few  ");
     2583    log_msg(0, "error messages in the log. Read them; analyze them; see if  ");
     2584    log_msg(0, "they are significant; above all, verify your backups! Please");
     2585    log_msg(0, "attach a compressed copy of this log to any e-mail you send ");
     2586    log_msg(0, "to the Mondo mailing list when you are seeking technical    ");
     2587    log_msg(0, "support. Without it, we can't help you.            - DevTeam");
     2588    log_msg(0, "------------------------------------------------------------");
     2589    log_msg(0, "BTW, despite (or perhaps because of) the wealth of messages,");
     2590    log_msg(0, "some users are inclined to stop reading this log.  If Mondo ");
     2591    log_msg(0, "stopped for some reason, chances are it's detailed here.    ");
     2592    log_msg(0, "More than likely there's a message at the very end of this  ");
     2593    log_msg(0, "log that will tell you what is wrong.  Please read it!      ");
     2594    log_msg(0, "------------------------------------------------------------");
    28062595}
    28072596
     
    28182607    int retval = 0;
    28192608    int res;
    2820 //  int c;
    2821     char *tmp;
     2609    char *tmp = NULL;
    28222610
    28232611    struct mountlist_itself *mountlist;
    28242612    struct raidlist_itself *raidlist;
    28252613    struct s_node *filelist;
    2826     char *a, *b;
     2614    char *tmp1 = NULL;
     2615    char *tmp2 = NULL;
    28272616    bool run_postnuke = FALSE;
    28282617
     
    28382627
    28392628    g_loglevel = DEFAULT_MR_LOGLEVEL;
    2840     malloc_string(tmp);
    28412629
    28422630/* Configure global variables */
     
    28632651    }
    28642652
     2653    /* Init GUI */
     2654    setup_newt_stuff();         /* call newtInit and setup screen log */
     2655
    28652656    malloc_libmondo_global_strings();
    28662657
    28672658    strcpy(g_mondo_home,
    28682659           call_program_and_get_last_line_of_output("which mondorestore"));
    2869     /*
    2870     sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
    2871     make_hole_for_dir(g_tmpfs_mountpt);
    2872     */
    28732660    g_current_media_number = 1; // precaution
    28742661
    28752662    run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
    28762663
    2877     malloc_string(a);
    2878     malloc_string(b);
    28792664    setup_MR_global_filenames();    // malloc() and set globals, using bkpinfo->tmpdir etc.
    28802665    bkpinfo->backup_media_type = none;  // in case boot disk was made for one backup type but user wants to restore from another backup type
     
    28972682
    28982683    /* Backup original mountlist.txt */
    2899     sprintf(tmp, "%s.orig", g_mountlist_fname);
     2684    mr_asprintf(tmp, "%s.orig", g_mountlist_fname);
    29002685    if (!does_file_exist(g_mountlist_fname)) {
    2901         log_msg(2,
    2902                 "%ld: Warning - g_mountlist_fname (%s) does not exist yet",
    2903                 __LINE__, g_mountlist_fname);
     2686        log_msg(2, "%ld: Warning - g_mountlist_fname (%s) does not exist yet", __LINE__, g_mountlist_fname);
    29042687    } else if (!does_file_exist(tmp)) {
    2905         sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,
    2906                 g_mountlist_fname);
     2688        mr_free(tmp);
     2689        mr_asprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname, g_mountlist_fname);
    29072690        run_program_and_log_output(tmp, FALSE);
    29082691    }
     2692    mr_free(tmp);
    29092693
    29102694    /* Init directories */
     
    29122696    make_hole_for_dir("/tmp/tmpfs");    /* just in case... */
    29132697    run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
    2914     /*
    2915     run_program_and_log_output("ln -sf /var/log/mondo-archive.log /tmp/mondorestore.log",
    2916          FALSE);
    2917          */
    29182698
    29192699    run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
    29202700
    2921     /* Init GUI */
    2922     setup_newt_stuff();         /* call newtInit and setup screen log */
    29232701    welcome_to_mondorestore();
    29242702    if (bkpinfo->disaster_recovery) {
     
    29542732    }
    29552733
    2956     if (argc >= 2 && strcmp(argv[1], "--pih") == 0) {
    2957         if (system("mount | grep cdrom 2> /dev/null > /dev/null")) {
    2958             paranoid_system("mount " MNT_CDROM);
    2959         }
    2960         bkpinfo->compression_level = 1;
    2961         g_current_media_number = 2;
    2962         strcpy(bkpinfo->restore_path, "/tmp/TESTING");
    2963         bkpinfo->backup_media_type = dvd;
    2964         open_progress_form("Reassembling /dev/hda1",
    2965                            "Shark is a bit of a silly person.",
    2966                            "Please wait. This may take some time.",
    2967                            "", 1999);
    2968         paranoid_system("rm -Rf /tmp/*pih*");
    2969 
    2970         restore_a_biggiefile_from_CD(42, NULL, tmp);
    2971     }
    2972 
    29732734    if (argc == 5 && strcmp(argv[1], "--common") == 0) {
    29742735        g_loglevel = 6;
     
    29812742        // BERLIOS: /usr/lib ???
    29822743        toggle_path_selection(filelist, "/usr/share", TRUE);
    2983 //      show_filelist(filelist);
    29842744        save_filelist(filelist, "/tmp/out.txt");
    2985 //      finish(0);
    2986 //      toggle_path_selection (filelist, "/root/stuff", TRUE);
    2987         strcpy(a, argv[3]);
    2988         strcpy(b, argv[4]);
    2989 
    2990         res = save_filelist_entries_in_common(a, filelist, b, FALSE);
     2745        mr_asprintf(tmp1, "%s", argv[3]);
     2746        mr_asprintf(tmp2, "%s", argv[4]);
     2747
     2748        res = save_filelist_entries_in_common(tmp1, filelist, tmp2, FALSE);
     2749        mr_free(tmp1);
     2750        mr_free(tmp2);
     2751
    29912752        free_filelist(filelist);
    29922753        printf("res = %d", res);
     
    30962857        log_msg(2, "Still here. Yay.");
    30972858        if ((strlen(bkpinfo->tmpdir) > 0) && (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL)) {
    3098             sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
     2859            mr_asprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
    30992860            run_program_and_log_output(tmp, FALSE);
     2861            mr_free(tmp);
    31002862        }
    31012863        unmount_boot_if_necessary();    /* for Gentoo users */
     
    31152877        // BCO:To be reviewed
    31162878        if ((bkpinfo->restore_mode == compare) || (bkpinfo->restore_mode == nuke)) {
    3117             if (bkpinfo->backup_media_type == netfs
    3118                 && !is_this_device_mounted(bkpinfo->netfs_mount)) {
     2879            if ((bkpinfo->backup_media_type == netfs) && bkpinfo->netfs_mount && !is_this_device_mounted(bkpinfo->netfs_mount)) {
    31192880                log_msg(1, "Mounting remote %s dir", bkpinfo->netfs_proto);
    31202881                sprintf(bkpinfo->isodir, "/tmp/isodir");
     
    31222883                if (strstr(bkpinfo->netfs_proto, "sshfs")) {
    31232884                    if (bkpinfo->netfs_user) {
    3124                         sprintf(tmp, "sshfs -o ro %s@%s /tmp/isodir",
    3125                             bkpinfo->netfs_user,bkpinfo->netfs_mount);
     2885                        mr_asprintf(tmp, "sshfs -o ro %s@%s /tmp/isodir", bkpinfo->netfs_user,bkpinfo->netfs_mount);
    31262886                    } else {
    3127                         sprintf(tmp, "sshfs -o ro %s /tmp/isodir",
    3128                             bkpinfo->netfs_mount);
     2887                        mr_asprintf(tmp, "sshfs -o ro %s /tmp/isodir", bkpinfo->netfs_mount);
    31292888                    }
    31302889                } else  {
    31312890                    if (strstr(bkpinfo->netfs_proto, "smbfs")) {
    31322891                        if (bkpinfo->netfs_user) {
    3133                             sprintf(tmp, "mount -t cifs %s /tmp/isodir -o user=%s,nolock,ro ",
    3134                                 bkpinfo->netfs_mount,bkpinfo->netfs_user);
     2892                            mr_asprintf(tmp, "mount -t cifs %s /tmp/isodir -o user=%s,nolock,ro ", bkpinfo->netfs_mount,bkpinfo->netfs_user);
    31352893                        } else {
    3136                             sprintf(tmp, "mount -t cifs %s /tmp/isodir -o nolock,ro ",
    3137                                 bkpinfo->netfs_mount);
     2894                            mr_asprintf(tmp, "mount -t cifs %s /tmp/isodir -o nolock,ro ", bkpinfo->netfs_mount);
    31382895                        }
    31392896                    } else {
    31402897                        if (bkpinfo->netfs_user) {
    3141                             sprintf(tmp, "mount %s@%s -o nolock,ro /tmp/isodir",
    3142                                 bkpinfo->netfs_user,bkpinfo->netfs_mount);
     2898                            mr_asprintf(tmp, "mount %s@%s -o nolock,ro /tmp/isodir", bkpinfo->netfs_user,bkpinfo->netfs_mount);
    31432899                        } else {
    3144                             sprintf(tmp, "mount %s -o nolock,ro /tmp/isodir",
    3145                                 bkpinfo->netfs_mount);
     2900                            mr_asprintf(tmp, "mount %s -o nolock,ro /tmp/isodir", bkpinfo->netfs_mount);
    31462901                        }
    31472902                    }
    31482903                }
    31492904                run_program_and_log_output(tmp, 1);
     2905                mr_free(tmp);
    31502906            }
    31512907        }
    31522908
    31532909        if (retval) {
    3154             log_to_screen
    3155                 ("Warning - load_raidtab_into_raidlist returned an error");
     2910            log_to_screen("Warning - load_raidtab_into_raidlist returned an error");
    31562911        }
    31572912
     
    32052960                                "Run complete. Please remove media and reboot.");
    32062961        } else {
    3207             run_program_and_log_output("sync", FALSE);
     2962            sync();
    32082963            if (is_this_device_mounted(MNT_CDROM)) {
    32092964                run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
     
    32422997      } else {
    32432998        log_msg(1, "Re-mounted partitions for post-nuke stuff");
    3244         sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path,
    3245             retval);
     2999        mr_asprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, retval);
    32463000        log_msg(2, "Calling '%s'", tmp);
    32473001        if ((res = run_program_and_log_output(tmp, 0))) {
    32483002          log_OS_error(tmp);
    32493003        }
     3004        mr_free(tmp);
    32503005        log_msg(1, "post-nuke returned w/ res=%d", res);
    32513006      }
     
    32633018    set_signals(FALSE);
    32643019    log_to_screen("Restore log (%s) copied to /var/log on your hard disk", MONDO_LOGFILE);
    3265     sprintf(tmp,
    3266             "Mondo-restore is exiting (retval=%d)                                      ",
    3267             retval);
    3268     log_to_screen(tmp);
    3269     sprintf(tmp, "umount -d %s", bkpinfo->isodir);
     3020    log_to_screen("Mondo-restore is exiting (retval=%d)                                      ", retval);
     3021
     3022    mr_asprintf(tmp, "umount -d %s", bkpinfo->isodir);
    32703023    run_program_and_log_output(tmp, 5);
     3024    mr_free(tmp);
     3025
    32713026    paranoid_free(mountlist);
    32723027    paranoid_free(raidlist);
     
    32753030    }                           // for b0rken distros
    32763031    if (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL) {
    3277         sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
     3032        mr_asprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
    32783033        paranoid_system(tmp);
     3034        mr_free(tmp);
    32793035    }
    32803036    paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
    32813037    free_libmondo_global_strings(); // it's fine to have this here :) really :)
    3282     paranoid_free(a);
    3283     paranoid_free(b);
    3284     paranoid_free(tmp);
    32853038
    32863039    unlink("/tmp/filelist.full");
Note: See TracChangeset for help on using the changeset viewer.