Ignore:
Timestamp:
Mar 7, 2024, 1:55:18 PM (3 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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        }
Note: See TracChangeset for help on using the changeset viewer.