Changeset 3866 in MondoRescue


Ignore:
Timestamp:
Mar 7, 2024, 1:55:18 PM (2 months ago)
Author:
Bruno Cornec
Message:

Change find_my_editor and find_home_of_exe to return dynamically assigned stringsi - adapt whine_if_not_found

Location:
branches/3.3/mondo/src
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3/mondo/src/common/libmondo-archive.c

    r3860 r3866  
    344344    if (bkpinfo->backup_media_type == dvd) {
    345345#ifdef DVDRWFORMAT
    346         if (!find_home_of_exe("dvd+rw-format")) {
     346        if ((tmp = find_home_of_exe("dvd+rw-format")) == NULL) {
     347            mr_free(tmp);
    347348            fatal_error("Cannot find dvd+rw-format. Please install it or fix your PATH.");
    348349        }
     350        mr_free(tmp);
    349351#endif
    350         if (!find_home_of_exe("growisofs")) {
     352        if ((tmp = find_home_of_exe("growisofs")) == NULL) {
     353            mr_free(tmp);
    351354            fatal_error("Cannot find growisofs. Please install it or fix your PATH.");
    352355        }
     356        mr_free(tmp);
    353357    }
    354358
     
    16951699        mr_asprintf(result_sz, "Call to mkisofs to make ISO (%s #%d) ", mds,  g_current_media_number);
    16961700        mr_free(mds);
    1697         if (find_home_of_exe("xorriso")) {
    1698             mr_asprintf(isofs_cmd, "%s", MONDO_XORRISO_CMD);
    1699         } else if (find_home_of_exe("genisoimage")) {
    1700             mr_asprintf(isofs_cmd, "%s", MONDO_GENISOIMAGE_CMD);
     1701        if ((tmp = find_home_of_exe("xorriso")) != NULL) {
     1702            mr_asprintf(isofs_cmd, "%s %s", tmp, MONDO_XORRISO_OPT);
     1703        } else if ((tmp = find_home_of_exe("genisoimage")) != NULL) {
     1704            mr_asprintf(isofs_cmd, "%s %s", tmp, MONDO_GENISOIMAGE_OPT);
     1705        } else if ((tmp = find_home_of_exe("mkisofs")) != NULL) {
     1706            mr_asprintf(isofs_cmd, "%s %s", tmp, MONDO_MKISOFS_OPT);
     1707        } else if ((tmp = find_home_of_exe("wodim")) != NULL) {
     1708            mr_asprintf(isofs_cmd, "%s %s", tmp, MONDO_WODIM_OPT);
    17011709        } else {
    1702             mr_asprintf(isofs_cmd, "%s", MONDO_MKISOFS_CMD);
    1703         }
     1710            fatal_error("Unable to find a command to create ISO among xorriso, genisoimage, mksiofs or wodim, please install one");
     1711        }
     1712        mr_free(tmp);
    17041713        if (bkpinfo->nonbootable_backup) {
    17051714            log_msg(1, "Making nonbootable backup");
     
    27442753        mr_asprintf(checksum_line, "IGNORE");
    27452754        log_msg(2, "Not calculating checksum for %s: it would take too long", biggie_filename);
    2746         if ( !find_home_of_exe("ntfsresize")) {
     2755        if ((tmp = find_home_of_exe("ntfsresize")) == NULL) {
    27472756            fatal_error("ntfsresize not found");
    27482757        }
    2749         mr_asprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", biggie_filename);
     2758        mr_asprintf(command, "%s --force --info %s|grep '^You might resize at '|cut -d' ' -f5", tmp, biggie_filename);
     2759        mr_free(tmp);
    27502760        log_it("command = %s", command);
    27512761        tmp = call_program_and_get_last_line_of_output(command);
  • branches/3.3/mondo/src/common/libmondo-cli.c

    r3857 r3866  
    207207    }
    208208
    209     if (!find_home_of_exe("afio")) {
    210         if (find_home_of_exe("star")) {
     209    if ((tmp = find_home_of_exe("afio")) == NULL) {
     210        mr_free(tmp);
     211        if ((tmp = find_home_of_exe("star")) != NULL) {
     212            mr_free(tmp);
    211213            flag_set['R'] = TRUE;
    212214            log_msg(1, "Using star instead of afio");
    213215        } else {
     216            mr_free(tmp);
    214217            fatal_error("Neither afio nor star is installed. Please install at least one.");
    215218        }
     
    221224            fatal_error("You may not use star and lzop at the same time.");
    222225        }
    223         if (!find_home_of_exe("star")) {
    224             fatal_error("Please install 'star' RPM or tarball if you are going to use -R. Thanks.");
    225         }
     226        if ((tmp = find_home_of_exe("star")) == NULL) {
     227            mr_free(tmp);
     228            fatal_error("Please install 'star' if you are going to use -R. Thanks.");
     229        }
     230        mr_free(tmp);
    226231    }
    227232
     
    363368        }
    364369        if (! bkpinfo->restore_data) {
    365             if (!find_home_of_exe("growisofs")) {
    366                 fatal_error("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it.");
    367             }
    368             if (!find_home_of_exe("dvd+rw-format")) {
    369                 fatal_error("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it.");
    370             }
    371370            if (!flag_set['s']) {
    372371                sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE);    // 4.7 salesman's GB = 4.482 real GB = 4582 MB
     
    555554    }
    556555    if (flag_set['z']) {
    557         if (find_home_of_exe("getfattr")) {
     556        if ((tmp = find_home_of_exe("getfattr")) != NULL) {
    558557            mr_asprintf(g_getfattr,"getfattr");
    559558        }
    560         if (find_home_of_exe("getfacl")) {
    561             mr_asprintf(g_getfacl,"getfacl");
    562         }
     559        mr_free(tmp);
     560        if ((tmp = find_home_of_exe("getfacl")) != NULL) {
     561            mr_asprintf(g_getfattr,"getfaacl");
     562        }
     563        mr_free(tmp);
    563564    }
    564565
  • branches/3.3/mondo/src/common/libmondo-devices.c

    r3859 r3866  
    535535    }
    536536    run_program_and_log_output("insmod ide-scsi", -1);
    537     if (find_home_of_exe("cdrecord")) {
    538         mr_asprintf(cdr_exe, "cdrecord");
    539     } else {
    540         mr_asprintf(cdr_exe, "dvdrecord");
    541     }
    542     if (find_home_of_exe(cdr_exe)) {
     537    if ((cdr_exe = find_home_of_exe("cdrecord")) == NULL) {
     538        if ((cdr_exe = find_home_of_exe("wodim")) == NULL) {
     539            cdr_exe = find_home_of_exe("dvdrecord");
     540        }
     541    }
     542    if (cdr_exe != NULL) {
    543543        mr_asprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -E '[D|C][V|D]' | cut -d' ' -f2 | head -n1", cdr_exe);
    544544        tmp = call_program_and_get_last_line_of_output(command);
     
    594594    static char the_last_place_i_found_it[MAX_STR_LEN] = "";
    595595
    596     /*@ intialize *************************************************** */
    597     malloc_string(tmp);
    598     malloc_string(phrase_one);
    599     malloc_string(mountpoint);
    600 
     596    assert_string_is_neither_NULL_nor_zerolength(output);
    601597    output[0] = '\0';
    602     phrase_one[0] = '\0';
    603 
    604     /*@ end vars **************************************************** */
    605598
    606599    if (g_cdrom_drive_is_here[0] && !isdigit(g_cdrom_drive_is_here[0])) {
    607600        strcpy(output, g_cdrom_drive_is_here);
    608601        log_msg(3, "Been there, done that. Returning %s", output);
    609         retval = 0;
    610         goto end_of_find_cdrom_device;
     602        return(0);
    611603    }
    612604    if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) {
    613605        strcpy(output, the_last_place_i_found_it);
    614606        log_msg(3, "find_cdrom_device() --- returning last found location - '%s'", output);
    615         retval = 0;
    616         goto end_of_find_cdrom_device;
    617     }
    618 
    619     sprintf(mountpoint, "%s/cd.mnt", bkpinfo->tmpdir);
    620     make_hole_for_dir(mountpoint);
    621 
    622     if (find_home_of_exe("cdrecord")) {
    623         mr_asprintf(cdr_exe, "cdrecord");
    624     } else {
    625         mr_asprintf(cdr_exe, "dvdrecord");
    626     }
    627     tmp[0] = '\0';
    628     if (!find_home_of_exe(cdr_exe)) {
     607        return(0);
     608    }
     609
     610    if ((cdr_exe = find_home_of_exe("cdrecord")) == NULL) {
     611        if ((cdr_exe = find_home_of_exe("wodim")) == NULL) {
     612            cdr_exe = find_home_of_exe("dvdrecord");
     613        }
     614    }
     615
     616    if (cdr_exe == NULL) {
    629617        strcpy(output, "/dev/cdrom");
    630618        log_msg(4, "Can't find cdrecord; assuming %s", output);
    631619        if (!does_device_exist(output)) {
    632620            log_msg(4, "That didn't work. Sorry.");
    633             retval = 1;
    634             goto end_of_find_cdrom_device;
     621            return(1)
    635622        } else {
    636             retval = 0;
    637             goto end_of_find_cdrom_device;
     623            return(0)
    638624        }
    639625    }
     
    646632        mr_free(cdr_exe);
    647633        mr_free(command);
    648         return (1);
     634        return(1);
    649635    }
    650636    mr_free(command);
     637
     638    /*@ intialize *************************************************** */
     639    malloc_string(tmp);
     640    malloc_string(phrase_one);
     641
     642    phrase_one[0] = '\0';
     643    tmp[0] = '\0';
     644
     645    /*@ end vars **************************************************** */
     646
    651647
    652648    for (tmp1 = fgets(tmp, MAX_STR_LEN, fin); !feof(fin) && (tmp1 != NULL);
     
    810806#endif
    811807
     808    mr_asprintf(mountpoint, "%s/cd.mnt", bkpinfo->tmpdir);
     809    make_hole_for_dir(mountpoint);
     810
    812811    if (found_it && try_to_mount) {
    813812        if (mount_CDROM_here(output, mountpoint)) {
     
    829828    }
    830829    unlink(mountpoint);
     830    mr_free(mountpoint);
    831831
    832832    if (found_it) {
     
    865865    paranoid_free(tmp);
    866866    paranoid_free(phrase_one);
    867     paranoid_free(mountpoint);
    868867    return (retval);
    869868}
     
    28052804
    28062805        if (ask_me_yes_or_no("Do you want to backup extended attributes?")) {
    2807             if (find_home_of_exe("getfattr")) {
    2808                 mr_free(g_getfattr);
    2809                 mr_asprintf(g_getfattr,"getfattr");
    2810             }
    2811             if (find_home_of_exe("getfacl")) {
    2812                 mr_free(g_getfacl);
    2813                 mr_asprintf(g_getfacl,"getfacl");
    2814             }
     2806            mr_free(g_getfattr);
     2807            g_getfattr = find_home_of_exe("getfattr");
     2808            mr_free(g_getfacl);
     2809            g_getfacl = find_home_of_exe("getfacl");
    28152810            log_it("Backup of extended attributes");
    28162811        }
  • branches/3.3/mondo/src/common/libmondo-filelist.c

    r3753 r3866  
    654654
    655655
    656 int set_fattr_list(char *masklist, char *fattr_fname)
    657 {
    658     if (find_home_of_exe("setfattr")) {
    659         return (set_EXAT_list(masklist, fattr_fname, "setfattr"));
     656int set_fattr_list(char *masklist, char *fattr_fname) {
     657
     658    int i = 0;
     659    char * tmp = NULL;
     660
     661    if ((tmp = find_home_of_exe("setfattr")) != NULL) {
     662        i = set_EXAT_list(masklist, fattr_fname, tmp)
     663        mr_free(tmp);
    660664    } else {
    661665        log_msg(1, "ERROR: set_EXAT_list: setfattr doesn't exist");
    662         return(0);
    663     }
    664 }
    665 
    666 
    667 
    668 int set_acl_list(char *masklist, char *acl_fname)
    669 {
    670     if (find_home_of_exe("setfacl")) {
    671         return (set_EXAT_list(masklist, acl_fname, "setfacl"));
     666    }
     667    return(i);
     668}
     669
     670
     671
     672int set_acl_list(char *masklist, char *acl_fname) {
     673
     674    int i = 0;
     675    char * tmp = NULL;
     676
     677    if ((tmp = find_home_of_exe("setfacl")) != NULL) {
     678        i = set_EXAT_list(masklist, facl_fname, tmp)
     679        mr_free(tmp);
    672680    } else {
    673681        log_msg(1, "ERROR: set_EXAT_list: setfacl doesn't exist");
    674         return(0);
    675     }
     682    }
     683    return(i);
    676684}
    677685
  • branches/3.3/mondo/src/common/libmondo-files-EXT.h

    r3861 r3866  
    1111extern void exclude_nonexistent_files(char *inout);
    1212extern int figure_out_kernel_path_interactively_if_necessary(char *kernel);
    13 extern char *find_home_of_exe(char *fname);
     13extern char *find_home_of_exe(const char *fname);
    1414extern int get_trackno_from_logfile(char *logfile);
    1515extern int grab_percentage_from_last_line_of_file(char *filename);
  • branches/3.3/mondo/src/common/libmondo-files.c

    r3861 r3866  
    317317 * Find location of specified executable in user's PATH.
    318318 * @param fname The basename of the executable to search for (e.g. @c afio).
    319  * @return The full path to the executable, or "" if it does not exist, or NULL if @c file could not be found.
    320  * @note The returned string points to static storage that will be overwritten with each call.
     319 * @return The full path to the executable, or NULL if it does not exist, or if @c file could not be found.
     320 * @note The returned string points to an allocated string that needs to be freed by caller
    321321 * @bug The checks with @c file and @c dirname seem pointless. If @c incoming is "", then you're calling
    322322 * <tt>dirname 2\>/dev/null</tt> or <tt>file 2\>/dev/null | cut -d':' -f1 2\>/dev/null</tt>, which basically amounts
    323323 * to nothing.
    324324 */
    325 char *find_home_of_exe(char *fname)
     325char *find_home_of_exe(const char *fname)
    326326{
    327327    /*@ buffers ********************* */
    328     static char output[MAX_STR_LEN];
    329     char *incoming = NULL;
     328    char *output = NULL;
    330329    char *command = NULL;
    331330
     
    333332
    334333    assert_string_is_neither_NULL_nor_zerolength(fname);
    335     mr_asprintf(command, "which %s 2> /dev/null", fname);
    336     incoming = call_program_and_get_last_line_of_output(command);
     334
     335    mr_asprintf(command, "whereis %s 2>/dev/null | awk '{ print $2 }'", fname);
     336    /* either "" or the string  can't be NULL*/
     337    output = call_program_and_get_last_line_of_output(command);
    337338    mr_free(command);
    338339
    339     if (incoming[0] == '\0') {
    340         if (system("which file > /dev/null 2> /dev/null")) {
    341             mr_free(incoming);
    342             output[0] = '\0';
    343             return(NULL);       // forget it :)
    344         }
    345         mr_asprintf(command, "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", incoming);
    346         mr_free(incoming);
    347 
    348         incoming = call_program_and_get_last_line_of_output(command);
     340    if (output[0] == '\0') {
     341        mr_asprintf(command, "which %s 2> /dev/null", fname);
     342        /* either "" or the string  can't be NULL*/
     343        mr_free(output);
     344        output = call_program_and_get_last_line_of_output(command);
    349345        mr_free(command);
    350346    }
    351     if (incoming[0] == '\0') {
    352         mr_asprintf(command, "dirname %s 2> /dev/null", incoming);
    353         mr_free(incoming);
    354 
    355         incoming = call_program_and_get_last_line_of_output(command);
    356         mr_free(command);
    357     }
    358     strcpy(output, incoming);
     347
    359348    if (output[0] != '\0' && does_file_exist(output)) {
    360         log_msg(4, "find_home_of_exe --- Found %s at %s", fname, incoming);
     349        log_msg(4, "find_home_of_exe --- Found %s at %s", fname, output);
     350        return(output);
    361351    } else {
    362         output[0] = '\0';
    363352        log_msg(4, "find_home_of_exe --- Could not find %s", fname);
    364     }
    365     mr_free(incoming);
    366     if (!output[0]) {
    367353        return(NULL);
    368     } else {
    369         return(output);
    370354    }
    371355}
     
    777761            if (0 == strncmp(fname, "/dev/", 5)) {
    778762                if (is_dev_an_NTFS_dev(fname)) {
    779                     if ( !find_home_of_exe("ntfsresize")) {
     763                    if ((tmp = find_home_of_exe("ntfsresize")) == NULL) {
    780764                        mr_free(tmp);
    781765                        mr_free(fname);
    782766                        fatal_error("ntfsresize not found");
    783767                    }
     768                    mr_asprintf(command, "%s --force --info %s|grep '^You might resize at '|cut -d' ' -f5", tmp, fname);
    784769                    mr_free(tmp);
    785 
    786                     mr_asprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
    787770                    log_it("command = %s", command);
    788771                    tmp = call_program_and_get_last_line_of_output(command);
     
    903886{
    904887    /*@ buffers *** */
    905     char *command = NULL;
    906     int res = 0;
    907 
    908     mr_asprintf(command, "which %s > /dev/null 2> /dev/null", fname);
    909     res = system(command);
    910     mr_free(command);
    911 
    912     if (res) {
     888    char *tmp = NULL;
     889
     890    tmp = find_home_of_exe(fname);
     891    if (tmp == NULL) {
    913892        log_to_screen("Please install '%s'. I cannot find it on your system.", fname);
    914         log_to_screen("There may be hyperlink at http://www.mondorescue.org which");
    915         log_to_screen("will take you to the relevant (missing) package.");
    916893        return(1);
    917894    } else {
     895        mr_free(tmp);
    918896        return(0);
    919897    }
    920898}
    921 
    922 
    923 
    924899
    925900
  • branches/3.3/mondo/src/common/libmondo-files.h

    r3861 r3866  
    1212void exclude_nonexistent_files(char *inout);
    1313int figure_out_kernel_path_interactively_if_necessary(char *kernel);
    14 char *find_home_of_exe(char *fname);
    1514int get_trackno_from_logfile(char *logfile);
    1615int grab_percentage_from_last_line_of_file(char *filename);
  • branches/3.3/mondo/src/common/libmondo-fork.c

    r3863 r3866  
    608608    int res = -1;
    609609    char *command = NULL;
     610    char *tmp = NULL;
    610611
    611612    if (!does_file_exist(input_device)) {
    612613        fatal_error("input device does not exist");
    613614    }
    614     if ( !find_home_of_exe("ntfsclone")) {
     615    if ((tmp = find_home_of_exe("ntfsclone")) == NULL) {
    615616        fatal_error("ntfsclone not found");
    616617    }
    617     mr_asprintf(command, "ntfsclone --rescue --force --save-image --overwrite %s %s", output_fname, input_device);
     618    mr_asprintf(command, "%s --rescue --force --save-image --overwrite %s %s", tmp, output_fname, input_device);
     619    mr_free(tmp);
    618620    res = run_program_and_log_output(command, 5);
    619621    mr_free(command);
     
    717719    int res = -1;
    718720    char *command = NULL;
    719 
    720     if ( !find_home_of_exe("ntfsclone")) {
     721    char *tmp = NULL;
     722
     723    if ((tmp = find_home_of_exe("ntfsclone")) == NULL) {
    721724        fatal_error("ntfsclone not found");
    722725    }
    723     mr_asprintf(command, "ntfsclone --rescue --force --restore-image --overwrite %s %s", output_device, input_fifo);
     726    mr_asprintf(command, "%s --rescue --force --restore-image --overwrite %s %s", tmp, output_device, input_fifo);
     727    mr_free(tmp);
    724728    res = run_program_and_log_output(command, 5);
    725729    mr_free(command);
  • branches/3.3/mondo/src/common/libmondo-stream.c

    r3860 r3866  
    315315    log_to_screen("I am looking for your tape streamer. Please wait.");
    316316    mr_free(dev);
    317     if (find_home_of_exe("cdrecord")) {
    318         mr_asprintf(cdr_exe, "cdrecord");
    319     } else {
    320         mr_asprintf(cdr_exe, "dvdrecord");
     317    if ((cdr_exe = find_home_of_exe("cdrecord")) != NULL) {
     318        if ((cdr_exe = find_home_of_exe("wodim")) != NULL) {
     319            cdr_exe = find_home_of_exe("dvdrecord");
     320        }
    321321    }
    322322    mr_asprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l", cdr_exe);
  • branches/3.3/mondo/src/include/my-stuff.h

    r3754 r3866  
    177177
    178178#define MONDO_MKISOFS_CMD "mkisofs"
    179 #define MONDO_GENISOIMAGE_CMD "genisoimage"
    180 #define MONDO_XORRISO_CMD "xorriso -as mkisofs"
     179#define MONDO_MKISOFS_OPT ""
     180#define MONDO_WODIM_OPT ""
     181#define MONDO_GENISOIMAGE_OPT ""
     182#define MONDO_XORRISO_OPT "-as mkisofs"
    181183#define MONDO_MKISOFS " -J -r -v -p MondoRescue -publisher http://www.mondorescue.org -A MondoRescue -V _CD#_ "
    182184#define MONDO_MKISOFS_CMS " -b syslinux/isolinux.bin -c syslinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table "
  • branches/3.3/mondo/src/mondorestore/mondo-prep.c

    r3859 r3866  
    201201log_it("STARTING");
    202202log_msg(1, "OK, opened i-want-my-lvm. Shutting down LVM volumes...");
    203 if (find_home_of_exe("lvm")) {  // found it :) cool
    204     mr_asprintf(lvscan_sz, "lvm lvscan");
    205     mr_asprintf(lvremove_sz, "lvm lvremove");
    206     mr_asprintf(vgscan_sz, "lvm vgscan");
    207     mr_asprintf(pvscan_sz, "lvm pvscan");
    208     mr_asprintf(vgchange_sz, "lvm vgchange");
    209     mr_asprintf(vgremove_sz, "lvm vgremove -f");
     203if ((tmp = find_home_of_exe("lvm")) != NULL) {  // found it :) cool
     204    mr_asprintf(lvscan_sz, "%s lvscan", tmp);
     205    mr_asprintf(lvremove_sz, "%s lvremove", tmp);
     206    mr_asprintf(vgscan_sz, "%s vgscan", tmp);
     207    mr_asprintf(pvscan_sz, "%s pvscan", tmp);
     208    mr_asprintf(vgchange_sz, "%s vgchange", tmp);
     209    mr_asprintf(vgremove_sz, "%s vgremove -f", tmp);
    210210} else {
    211211    mr_asprintf(lvscan_sz, "lvscan");
     
    216216    mr_asprintf(vgremove_sz, "vgremove");
    217217}
     218mr_free(tmp);
     219
    218220mr_asprintf(cmd, "for i in `%s | cut -d\"'\" -f2 | sort -r` ; do echo \"Shutting down lv $i\" >> %s ; %s -f $i; done", lvscan_sz, MONDO_LOGFILE, lvremove_sz);
    219221mr_free(lvscan_sz);
  • branches/3.3/mondo/src/mondorestore/mondo-rstr-compare.c

    r3822 r3866  
    259259
    260260    if (compressor_exe) {
    261         mr_asprintf(tmp, "%s", compressor_exe);
    262         if (!find_home_of_exe(tmp)) {
     261        if ((tmp = find_home_of_exe(compressor_exe)) == NULL) {
    263262            mr_free(tmp);
    264263            mr_free(compressor_exe);
     
    266265            fatal_error("(compare_a_tarball) Compression program missing");
    267266        }
    268         mr_free(tmp);
    269267
    270268        if (use_star) {
     
    278276        } else {
    279277            // afio
    280             mr_asprintf(tmp, "%s", compressor_exe);
    281             mr_free(compressor_exe);
    282278            mr_asprintf(compressor_exe, "-P %s -Z", tmp);
    283             mr_free(tmp);
    284         }
     279        }
     280        mr_free(tmp);
    285281    }
    286282
     
    541537    if (g_text_mode) {
    542538        save_mountlist_to_disk(mountlist, g_mountlist_fname);
    543         sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname);
    544         res = system(tmp);
     539        tmp = find_my_editor();
     540        res = mr_system("%s %s", tmp, g_mountlist_fname);
     541        mr_free(tmp);
    545542        load_mountlist(mountlist, g_mountlist_fname);
    546543    } else {
  • branches/3.3/mondo/src/mondorestore/mondo-rstr-tools.c

    r3854 r3866  
    405405/** malloc **/
    406406char *tmp = NULL;
     407char *tmp1 = NULL;
    407408char *command = NULL;
    408409char *mountdir = NULL;
     
    437438            mr_strcat(additional_parameters, "-o ro");
    438439        }
    439         if (find_home_of_exe("setfattr")) {
     440        if ((tmp = find_home_of_exe("setfattr")) != NULL) {
    440441            mr_strcat(additional_parameters, ",user_xattr");
    441442        }
    442         if (find_home_of_exe("setfacl")) {
     443        mr_free(tmp);
     444        if ((tmp = find_home_of_exe("setfacl")) != NULL) {
    443445            mr_strcat(additional_parameters, ",acl");
    444446        }
     447        mr_free(tmp);
    445448    }
    446449
     
    780783read_cfg_var(cfg_file, "acl", value);
    781784if (strstr(value, "TRUE")) {
    782     mr_asprintf(g_getfacl,"setfacl");
    783     log_msg(1, "We will restore ACLs");
    784     if (! find_home_of_exe("setfacl")) {
     785    if ((tmp = find_home_of_exe("setfacl")) == NULL) {
    785786        log_msg(1, "Unable to restore ACLs as no setfacl found");
    786     }
     787    } else {
     788        mr_asprintf(g_getfacl,"%s", tmp);
     789        log_msg(1, "We will restore ACLs");
     790    }
     791    mr_free(tmp);
    787792}
    788793read_cfg_var(cfg_file, "xattr", value);
    789794if (strstr(value, "TRUE")) {
    790     mr_asprintf(g_getfattr,"setfattr");
    791     log_msg(1, "We will restore XATTRs");
    792     if (! find_home_of_exe("setfattr")) {
     795    if ((tmp = find_home_of_exe("setfattr")) == NULL) {
    793796        log_msg(1, "Unable to restore XATTRs as no setfattr found");
    794     }
     797    } else {
     798        mr_asprintf(g_getfattr,"%s", tmp);
     799        log_msg(1, "We will restore XATTRs");
     800    }
     801    mr_free(tmp);
    795802}
    796803
     
    13901397 * Attempt to find the user's editor.
    13911398 * @return The editor found ("vi" if none could be found).
    1392  * @note The returned string points to static storage that will be overwritten with each call.
     1399 * @note The returned string points to an allocated storage that needs to be freed by caller
    13931400 */
    13941401char *find_my_editor(void) {
    13951402
    1396     static char output[MAX_STR_LEN];
    1397     if (find_home_of_exe("pico")) {
    1398         strcpy(output, "pico");
    1399     } else if (find_home_of_exe("nano")) {
    1400         strcpy(output, "nano");
    1401     } else if (find_home_of_exe("e3em")) {
    1402         strcpy(output, "e3em");
    1403     } else if (find_home_of_exe("e3vi")) {
    1404         strcpy(output, "e3vi");
    1405     } else {
    1406         strcpy(output, "vi");
    1407     }
    1408     if (!find_home_of_exe(output)) {
    1409         log_msg(2, " (find_my_editor) --- warning - %s not found", output);
     1403    char *output = NULL ;
     1404
     1405    if ((output = find_home_of_exe("pico")) == NULL) {
     1406        if ((output = find_home_of_exe("nano")) == NULL) {
     1407            if ((output = find_home_of_exe("e3em")) == NULL) {
     1408                if ((output = find_home_of_exe("e3vi")) == NULL) {
     1409                    if ((output = find_home_of_exe("vim")) == NULL) {
     1410                        output = find_home_of_exe("vi");
     1411                    }
     1412                }
     1413            }
     1414        }
     1415    }
     1416    if (output == NULL) {
     1417        log_msg(2, " (find_my_editor) --- warning - no editor found, even vi");
    14101418    }
    14111419    return (output);
     
    14591467                    popup_and_OK("The mountlist was changed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install");
    14601468                }
    1461                 if (!g_text_mode) {
    1462                     newtSuspend();
     1469                editor = find_my_editor());
     1470                if (editor == NULL) {
     1471                    popup_and_OK("No editor found. You won't be able to edit conf files");
     1472                } else {
     1473                    if (!g_text_mode) {
     1474                        newtSuspend();
     1475                    }
     1476                    mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
     1477                    paranoid_system(tmp);
     1478                    mr_free(tmp);
     1479   
     1480                    mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor);
     1481                    paranoid_system(tmp);
     1482                    mr_free(tmp);
     1483       
     1484                    if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) {
     1485                        mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor);
     1486                    } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) {
     1487                        mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor);
     1488                    } else if (does_file_exist(MNT_RESTORING"/boot/grub2/grub.cfg")) {
     1489                        mr_asprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor);
     1490                    }
     1491                    paranoid_system(tmp);
     1492                    mr_free(tmp);
     1493       
     1494                    if (does_file_exist(MNT_RESTORING"/boot/grub/device.map")) {
     1495                        mr_asprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);
     1496                    } else if (does_file_exist(MNT_RESTORING"/boot/grub2/device.map")) {
     1497                        mr_asprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor);
     1498                    }
     1499                    paranoid_system(tmp);
     1500                    mr_free(tmp);
     1501                    if (!g_text_mode) {
     1502                        newtResume();
     1503                    }
    14631504                }
    1464                 mr_asprintf(editor, "%s", find_my_editor());
    1465                 mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
    1466                 paranoid_system(tmp);
    1467                 mr_free(tmp);
    1468 
    1469                 mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor);
    1470                 paranoid_system(tmp);
    1471                 mr_free(tmp);
    1472    
    1473                 if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) {
    1474                     mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor);
    1475                 } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) {
    1476                     mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor);
    1477                 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/grub.cfg")) {
    1478                     mr_asprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor);
    1479                 }
    1480                 paranoid_system(tmp);
    1481                 mr_free(tmp);
    1482    
    1483                 if (does_file_exist(MNT_RESTORING"/boot/grub/device.map")) {
    1484                     mr_asprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);
    1485                 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/device.map")) {
    1486                     mr_asprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor);
    1487                 }
    1488                 paranoid_system(tmp);
    1489                 mr_free(tmp);
    14901505                mr_free(editor);
    14911506
    1492                 if (!g_text_mode) {
    1493                     newtResume();
    1494                 }
    14951507                mr_asprintf(command, "mr-stabgrub-me %s", boot_device);
    14961508                res = run_program_and_log_output(command, 1);
     
    15871599
    15881600        if (res) {
    1589             popup_and_OK
    1590                 ("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.");
     1601            popup_and_OK("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.");
    15911602            for (done = FALSE; !done;) {
    1592                 if (!g_text_mode) {
    1593                     newtSuspend();
     1603                editor = find_my_editor();
     1604                if (editor == NULL) {
     1605                    popup_and_OK("No editor found. You won't be able to edit conf files");
     1606                    done = TRUE;
     1607                } else {
     1608
     1609                    if (!g_text_mode) {
     1610                        newtSuspend();
     1611                    }
     1612                    mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
     1613                    paranoid_system(tmp);
     1614                    mr_free(tmp);
     1615   
     1616                    mr_asprintf(tmp, "chroot %s %s /etc/elilo.conf", MNT_RESTORING, editor);
     1617                    paranoid_system(tmp);
     1618                    mr_free(tmp);
     1619                    mr_free(editor);
     1620
     1621                    if (!g_text_mode) {
     1622                        newtResume();
     1623                    }
     1624//              newtCls();
     1625                    if (ask_me_yes_or_no("Edit them again?")) {
     1626                        continue;
     1627                    }
     1628                    done = TRUE;
    15941629                }
    1595                 mr_asprintf(editor, "%s", find_my_editor());
    1596 
    1597                 mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
    1598                 paranoid_system(tmp);
    1599                 mr_free(tmp);
    1600 
    1601                 mr_asprintf(tmp, "chroot %s %s /etc/elilo.conf", MNT_RESTORING, editor);
    1602                 paranoid_system(tmp);
    1603                 mr_free(tmp);
    16041630                mr_free(editor);
    1605 
    1606                 if (!g_text_mode) {
    1607                     newtResume();
    1608                 }
    1609 //              newtCls();
    1610                 if (ask_me_yes_or_no("Edit them again?")) {
    1611                     continue;
    1612                 }
    1613                 done = TRUE;
    16141631            }
    16151632        } else {
     
    16661683                ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.");
    16671684            for (done = FALSE; !done;) {
    1668                 if (!g_text_mode) {
    1669                     newtSuspend();
     1685                editor = find_my_editor();
     1686                if (editor == NULL) {
     1687                    popup_and_OK("No editor found. You won't be able to edit conf files");
     1688                } else {
     1689                    if (!g_text_mode) {
     1690                        newtSuspend();
     1691                    }
     1692                    mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1693                    paranoid_system(tmp);
     1694                    mr_free(tmp);
     1695   
     1696                    mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
     1697                    paranoid_system(tmp);
     1698                    mr_free(tmp);
     1699                    mr_free(editor);
     1700   
     1701                    if (!g_text_mode) {
     1702                        newtResume();
     1703                    }
     1704//              newtCls();
     1705                    if (ask_me_yes_or_no("Edit them again?")) {
     1706                        continue;
     1707                    }
    16701708                }
    1671                 mr_asprintf(editor, "%s", find_my_editor());
    1672 
    1673                 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
    1674                 paranoid_system(tmp);
    1675                 mr_free(tmp);
    1676 
    1677                 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
    1678                 paranoid_system(tmp);
    1679                 mr_free(tmp);
    16801709                mr_free(editor);
    16811710
    1682                 if (!g_text_mode) {
    1683                     newtResume();
    1684                 }
    1685 //              newtCls();
    1686                 if (ask_me_yes_or_no("Edit them again?")) {
    1687                     continue;
    1688                 }
    1689                 res =
    1690                     run_program_and_log_output("chroot " MNT_RESTORING
    1691                                                " lilo -L", 3);
     1711                res = run_program_and_log_output("chroot " MNT_RESTORING " lilo -L", 3);
    16921712                if (res) {
    1693                     res =
    1694                         run_program_and_log_output("chroot " MNT_RESTORING
    1695                                                    " lilo", 3);
     1713                    res = run_program_and_log_output("chroot " MNT_RESTORING " lilo", 3);
    16961714                }
    16971715                if (res) {
    1698                     done =
    1699                         ask_me_yes_or_no
    1700                         ("LILO failed. Re-edit system files?");
     1716                    done = ask_me_yes_or_no("LILO failed. Re-edit system files?");
    17011717                } else {
    17021718                    done = TRUE;
     
    17681784        mvaddstr_and_log_it(g_currentY, 0, "Modifying fstab and restoring MBR...                           ");
    17691785        for (done = FALSE; !done;) {
    1770             if (!run_program_and_log_output("which vi", FALSE)) {
    1771                 popup_and_OK("You will now edit fstab");
     1786            popup_and_OK("You will now edit fstab");
     1787            editor = find_my_editor());
     1788            if (editor == NULL) {
     1789                popup_and_OK("No editor found. You won't be able to edit conf files");
     1790            } else {
    17721791                if (!g_text_mode) {
    17731792                    newtSuspend();
    17741793                }
    1775                 mr_asprintf(editor, "%s", find_my_editor());
    17761794                mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
    1777                 mr_free(editor);
    17781795
    17791796                paranoid_system(tmp);
     
    17831800                }
    17841801            }
     1802            mr_free(editor);
     1803
    17851804            popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/hda", boot_device, MAX_STR_LEN / 4);
    17861805            mr_asprintf(command, "mr-stabraw-me %s", boot_device);
  • branches/3.3/mondo/src/mondorestore/mondo-rstr-tools.h

    r2682 r3866  
    2020int run_elilo(bool);
    2121int run_raw_mbr(bool offer_to_hack_scripts, char *bd);
    22 char *find_my_editor(void);
    2322void streamline_changes_file(char *, char *);
    2423void set_signals(int on);
  • branches/3.3/mondo/src/mondorestore/mondorestore.c

    r3862 r3866  
    207207    mr_asprintf(tmp1,"%s/var/lib/multipath/bindings",bkpinfo->restore_path);
    208208    (void)unlink(tmp1);
    209     paranoid_free(tmp1);
     209    mr_free(tmp1);
    210210
    211211    /* Edit multipath.conf if needed to adapt wwid */
     
    214214        log_msg(2, "We may need to clean /etc/multipath.conf");
    215215    } else {
    216         paranoid_free(tmp1);
     216        mr_free(tmp1);
    217217        return;
    218218    }
    219     paranoid_free(tmp1);
     219    mr_free(tmp1);
    220220
    221221    if (bkpinfo->restore_mode != nuke) {
    222         mr_asprintf(editor, "%s", find_my_editor());
     222        editor = find_my_editor();
    223223        mr_asprintf(tmp1,"chroot %s %s /etc/multipath.conf", MNT_RESTORING, editor);
    224224        popup_and_OK("You will now edit multipath.conf");
     
    230230            newtResume();
    231231        }
    232         paranoid_free(tmp1);
    233         paranoid_free(editor);
     232        mr_free(tmp1);
     233        mr_free(editor);
    234234    } else {
    235235        log_to_screen("Non-interactive mode: no way to give you the keyboard so that you edit your multipath.conf. Hope it's OK");
     
    17671767
    17681768    log_msg(1, "restoring everything");
    1769     if (!find_home_of_exe("petris") && !g_text_mode) {
     1769    if (((tmp = find_home_of_exe("petris")) != NULL) && !g_text_mode) {
    17701770        newtDrawRootText(0, g_noof_rows - 2,
    17711771                         "Press ALT-<left cursor> twice to play Petris :-) ");
    17721772        newtRefresh();
    17731773    }
     1774    mr_free(tmp);
    17741775    mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
    17751776    mount_media();
     
    18421843
    18431844  /** needs malloc **********/
     1845    char *tmp = NULL;
    18441846    char *tmp1 = NULL;
    18451847    char *fstab_fname = NULL;
     
    18811883        if (g_text_mode) {
    18821884            save_mountlist_to_disk(mountlist, g_mountlist_fname);
    1883             mr_asprintf(tmp1, "%s %s", find_my_editor(), g_mountlist_fname);
     1885            tmp = find_my_editor();
     1886            mr_asprintf(tmp1, "%s %s", tmp, g_mountlist_fname);
     1887            mr_free(tmp);
    18841888            res = system(tmp1);
    18851889            mr_free(tmp1);
Note: See TracChangeset for help on using the changeset viewer.