Ignore:
Timestamp:
Mar 3, 2015, 1:21:55 PM (9 years ago)
Author:
Bruno Cornec
Message:
  • Remove a usage of a full path for parted2fdisk. Using path allows mondoarchive to use either /sbin or /usr/sbin as an install path for it, depending on the distribution used (Philippe Lefevre)
  • Fix some statically allocated strings making them dynamic and solve a potential allocation issue as well
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mondo/src/common/libmondo-devices.c

    r3350 r3352  
    868868int find_dvd_device(char *output, bool try_to_mount)
    869869{
    870     char *tmp;
     870    char *tmp = NULL;
    871871    int retval = 0, devno = -1;
    872872
     
    877877    }
    878878
    879     malloc_string(tmp);
    880879    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep -E '\)\ \'' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1"));
    881880    log_msg(5, "tmp = '%s'", tmp);
     
    901900    return (retval);
    902901}
    903 
    904 
    905 
    906902
    907903
     
    28722868void make_fifo(char *store_name_here, char *stub)
    28732869{
    2874     char *tmp;
    2875 
    2876     malloc_string(tmp);
     2870    char *tmp = NULL;
     2871
    28772872    assert_string_is_neither_NULL_nor_zerolength(stub);
    28782873
     
    28812876    make_hole_for_file(store_name_here);
    28822877    mkfifo(store_name_here, S_IRWXU | S_IRWXG);
    2883     sprintf(tmp, "chmod 770 %s", store_name_here);
     2878    mr_asprintf(tmp, "chmod 770 %s", store_name_here);
    28842879    paranoid_system(tmp);
    2885     paranoid_free(tmp);
     2880    mr_free(tmp);
    28862881}
    28872882
     
    29012896bool set_dev_to_this_if_rx_OK(char *output, char *dev)
    29022897{
    2903     char *command;
    2904 
    2905     malloc_string(command);
     2898    char *command = NULL;
     2899    bool ret=FALSE;
     2900
    29062901    if (!dev || dev[0] == '\0') {
    29072902        output[0] = '\0';
    2908         return (FALSE);
     2903        return(ret);
    29092904    }
    29102905//  assert_string_is_neither_NULL_nor_zerolength(dev);
     
    29152910    if (!does_file_exist(dev)) {
    29162911        log_msg(10, "%s doesn't exist. Returning FALSE.", dev);
    2917         return (FALSE);
    2918     }
    2919     sprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null",
    2920             512L, dev);
    2921     if (!run_program_and_log_output(command, FALSE)
    2922         && !run_program_and_log_output(command, FALSE)) {
     2912        return(ret);
     2913    }
     2914    mr_asprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 512L, dev);
     2915    if (!run_program_and_log_output(command, FALSE) && !run_program_and_log_output(command, FALSE)) {
    29232916        strcpy(output, dev);
    29242917        log_msg(4, "Found it - %s", dev);
    2925         return (TRUE);
     2918        ret = TRUE;
    29262919    } else {
    29272920        output[0] = '\0';
    29282921        log_msg(4, "It's not %s", dev);
    2929         return (FALSE);
    2930     }
     2922    }
     2923    mr_free(command);
     2924    return(ret);
    29312925}
    29322926
     
    29792973    return (cd_number);
    29802974}
    2981 
    2982 
    2983 
    2984 
    2985 
    29862975
    29872976
     
    32183207{
    32193208    static char output[MAX_STR_LEN];
    3220     char *command;
    3221     char *curr_fname;
     3209    char *command = NULL;
     3210    char *curr_fname = NULL;
    32223211    char *scratch = NULL;
    32233212    char *tmp = NULL;
     
    32253214
    32263215    struct stat statbuf;
    3227     command = malloc(1000);
    32283216    malloc_string(curr_fname);
    32293217    if (!does_file_exist(incoming)) {
     
    32363224        while (S_ISLNK(statbuf.st_mode)) {
    32373225            log_msg(1, "curr_fname = %s", curr_fname);
    3238             sprintf(command, "file %s", curr_fname);
     3226            mr_asprintf(command, "file %s", curr_fname);
    32393227            mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     3228            mr_free(command);
    32403229            for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' ';
    32413230                 p--);
     
    32653254        log_it("resolved %s to %s", incoming, output);
    32663255    }
    3267     paranoid_free(command);
    32683256    paranoid_free(curr_fname);
    32693257    return (output);
     
    32793267    char *output = NULL;
    32803268    char *tmp = NULL;
    3281     char *command;
    3282     char *fdisk;
     3269    char *command = NULL;
    32833270#ifdef __IA64__
    32843271    struct stat buf;
    32853272#endif
    3286     malloc_string(command);
    3287     malloc_string(fdisk);
    3288     sprintf(fdisk, "/sbin/parted2fdisk");
    3289     sprintf(command, "%s -l %s 2>/dev/null | grep 'EFI GPT'", fdisk, drive);
     3273    mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | grep 'EFI GPT'", drive);
    32903274    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     3275    mr_free(command);
     3276
    32913277    if (strstr(tmp, "GPT") == NULL) {
    32923278        mr_asprintf(output, "%s", "MBR");
     
    32973283
    32983284    log_msg(0, "Found %s partition table format type on %s", output, drive);
    3299     paranoid_free(command);
    3300     paranoid_free(fdisk);
    33013285    return (output);
    33023286}
Note: See TracChangeset for help on using the changeset viewer.