Ignore:
Timestamp:
Aug 18, 2009, 3:05:43 PM (15 years ago)
Author:
Bruno Cornec
Message:

r3334@localhost: bruno | 2009-08-08 12:17:37 +0200

  • Change mr_asprintf interface to pass only the char * (makes bkpinfo usage more easy)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.10/mondo/src/common/libmondo-files.c

    r2321 r2323  
    6262    assert_string_is_neither_NULL_nor_zerolength(filename);
    6363    if (does_file_exist(filename)) {
    64         mr_asprintf(&command, "md5sum \"%s\"", filename);
     64        mr_asprintf(command, "md5sum \"%s\"", filename);
    6565        fin = popen(command, "r");
    6666        if (fin) {
     
    7171        mr_free(command);
    7272    } else {
    73         mr_asprintf(&tmp, "File '%s' not found; cannot calc checksum", filename);
     73        mr_asprintf(tmp, "File '%s' not found; cannot calc checksum", filename);
    7474        log_it(tmp);
    7575        mr_free(tmp);
     
    142142    assert_string_is_neither_NULL_nor_zerolength(filename);
    143143    if (!does_file_exist(filename)) {
    144         mr_asprintf(&tmp, "%s does not exist, so I cannot found the number of lines in it", filename);
     144        mr_asprintf(tmp, "%s does not exist, so I cannot found the number of lines in it", filename);
    145145        log_it(tmp);
    146146        mr_free(tmp);
    147147        return (0);
    148148    }
    149     mr_asprintf(&command, "cat %s | wc -l", filename);
     149    mr_asprintf(command, "cat %s | wc -l", filename);
    150150    if (!does_file_exist(filename)) {
    151151        mr_free(command);
     
    224224
    225225    assert_string_is_neither_NULL_nor_zerolength(inout);
    226     mr_asprintf(&infname, "%s.in", inout);
    227     mr_asprintf(&outfname, "%s", inout);
    228     mr_asprintf(&tmp, "cp -f %s %s", inout, infname);
     226    mr_asprintf(infname, "%s.in", inout);
     227    mr_asprintf(outfname, "%s", inout);
     228    mr_asprintf(tmp, "cp -f %s %s", inout, infname);
    229229    run_program_and_log_output(tmp, FALSE);
    230230    mr_free(tmp);
     
    251251            fprintf(fout, "%s\n", incoming);
    252252        } else {
    253             mr_asprintf(&tmp, "Excluding '%s'-nonexistent\n", incoming);
     253            mr_asprintf(tmp, "Excluding '%s'-nonexistent\n", incoming);
    254254            log_it(tmp);
    255255            mr_free(tmp);
     
    289289    // If we didn't get anything back, check whether mindi raised a fatal error
    290290    if (!kernel[0]) {
    291         mr_asprintf(&command, "%s", "grep 'Fatal error' /var/log/mindi.log");
    292         mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     291        mr_asprintf(command, "%s", "grep 'Fatal error' /var/log/mindi.log");
     292        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    293293        if (strlen(tmp) > 1) {
    294294            popup_and_OK(tmp);
     
    344344
    345345    assert_string_is_neither_NULL_nor_zerolength(fname);
    346     mr_asprintf(&command, "which %s 2> /dev/null", fname);
     346    mr_asprintf(command, "which %s 2> /dev/null", fname);
    347347    strcpy(incoming, call_program_and_get_last_line_of_output(command));
    348348    mr_free(command);
     
    353353            return (NULL);      // forget it :)
    354354        }
    355         mr_asprintf(&command, "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", incoming);
     355        mr_asprintf(command, "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", incoming);
    356356        strcpy(incoming,
    357357               call_program_and_get_last_line_of_output(command));
     
    360360    if (incoming[0] == '\0')    // yes, it is == '\0' twice, not once :)
    361361    {
    362         mr_asprintf(&command, "dirname %s 2> /dev/null", incoming);
     362        mr_asprintf(command, "dirname %s 2> /dev/null", incoming);
    363363        strcpy(incoming,
    364364               call_program_and_get_last_line_of_output(command));
     
    452452         && !strstr(err_log_lines[i], "% done"); i--);
    453453    if (i < 0) {
    454         mr_asprintf(&command, "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'", filename, '%');
     454        mr_asprintf(command, "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'", filename, '%');
    455455        strcpy(lastline,
    456456               call_program_and_get_last_line_of_output(command));
     
    503503
    504504    if (!does_file_exist(filename)) {
    505         mr_asprintf(&tmp, "Tring to get last line of nonexistent file (%s)", filename);
     505        mr_asprintf(tmp, "Tring to get last line of nonexistent file (%s)", filename);
    506506        log_it(tmp);
    507507        mr_free(tmp);
     
    509509        return (output);
    510510    }
    511     mr_asprintf(&command, "tail -n1 %s", filename);
     511    mr_asprintf(command, "tail -n1 %s", filename);
    512512    fin = popen(command, "r");
    513513    mr_free(command);
     
    602602            stub_fname[i] = '\0';
    603603        }
    604         mr_asprintf(&tmp, "%s%s", comppath, stub_fname);
     604        mr_asprintf(tmp, "%s%s", comppath, stub_fname);
    605605        strcpy(curr_fname, tmp + 1);
    606606        mr_free(tmp);
     
    620620                time_remaining =
    621621                    time_taken * 100 / (long) (percentage) - time_taken;
    622                 mr_asprintf(&tmp, "%02d%% done   %02d:%02d taken   %02d:%02d remaining  %-37s\r", percentage, (int) (time_taken / 60), (int) (time_taken % 60), (int) (time_remaining / 60), (int) (time_remaining % 60), curr_fname);
     622                mr_asprintf(tmp, "%02d%% done   %02d:%02d taken   %02d:%02d remaining  %-37s\r", percentage, (int) (time_taken / 60), (int) (time_taken % 60), (int) (time_remaining / 60), (int) (time_remaining % 60), curr_fname);
    623623                log_to_screen(tmp);
    624624                mr_free(tmp);
     
    645645
    646646    assert_string_is_neither_NULL_nor_zerolength(outdir_fname);
    647     mr_asprintf(&tmp, "mkdir -p %s", outdir_fname);
     647    mr_asprintf(tmp, "mkdir -p %s", outdir_fname);
    648648    res = system(tmp);
    649649    mr_free(tmp);
     
    671671    assert(!strstr(outfile_fname, MNT_CDROM));
    672672    assert(!strstr(outfile_fname, "/dev/cdrom"));
    673     mr_asprintf(&command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
     673    mr_asprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
    674674    res += system(command);
    675675    mr_free(command);
    676676
    677     mr_asprintf(&command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
     677    mr_asprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
    678678    res += system(command);
    679679    mr_free(command);
    680680
    681     mr_asprintf(&command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
     681    mr_asprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
    682682    res += system(command);
    683683    mr_free(command);
     
    742742    long file_len_K;
    743743
    744     mr_asprintf(&mountlist, "%s/mountlist.txt", tmpdir);
    745     mr_asprintf(&command, "grep \"%s \" %s/mountlist.txt | head -n1 | awk '{print $4}'", dev, tmpdir);
     744    mr_asprintf(mountlist, "%s/mountlist.txt", tmpdir);
     745    mr_asprintf(command, "grep \"%s \" %s/mountlist.txt | head -n1 | awk '{print $4}'", dev, tmpdir);
    746746    mr_free(mountlist);
    747747
     
    782782    malloc_string(fname);
    783783    log_it("Calculating size of all biggiefiles (in total)");
    784     mr_asprintf(&biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
     784    mr_asprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
    785785    log_it("biggielist = %s", biggielist);
    786786    fin = fopen(biggielist, "r");
     
    801801                        fatal_error("ntfsresize not found");
    802802                    }
    803                     mr_asprintf(&command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
     803                    mr_asprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
    804804                    log_it("command = %s", command);
    805                     mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     805                    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    806806                    mr_free(command);
    807807
     
    820820                log_msg(4, "%s --> %ld K", fname, file_len_K);
    821821            }
    822             mr_asprintf(&comment, "After adding %s, scratchL+%ld now equals %ld", fname, file_len_K, scratchL);
     822            mr_asprintf(comment, "After adding %s, scratchL+%ld now equals %ld", fname, file_len_K, scratchL);
    823823            log_msg(4, comment);
    824824            mr_free(comment);
     
    853853    /*@ end vars *************************************************** */
    854854
    855     mr_asprintf(&command, "du -sk %s", mountpt);
     855    mr_asprintf(command, "du -sk %s", mountpt);
    856856    errno = 0;
    857857    fin = popen(command, "r");
     
    923923    int res = 0;
    924924
    925     mr_asprintf(&command, "which %s > /dev/null 2> /dev/null", fname);
     925    mr_asprintf(command, "which %s > /dev/null 2> /dev/null", fname);
    926926    res = system(command);
    927927    mr_free(command);
    928928
    929929    if (res) {
    930         mr_asprintf(&errorstr, "Please install '%s'. I cannot find it on your system.", fname);
     930        mr_asprintf(errorstr, "Please install '%s'. I cannot find it on your system.", fname);
    931931        log_to_screen(errorstr);
    932932        mr_free(errorstr);
     
    10411041        find_and_store_mondoarchives_home(g_mondo_home);
    10421042    }
    1043     mr_asprintf(&command, CP_BIN " --parents -pRdf %s %s", g_mondo_home, bkpinfo->scratchdir);
     1043    mr_asprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home, bkpinfo->scratchdir);
    10441044
    10451045    log_msg(4, "command = %s", command);
     
    10511051    }
    10521052
    1053     mr_asprintf(&command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir, bkpinfo->scratchdir);
     1053    mr_asprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir, bkpinfo->scratchdir);
    10541054    res = run_program_and_log_output(command, FALSE);
    10551055    mr_free(command);
     
    10651065            ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?");
    10661066    }
    1067     mr_asprintf(&command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
     1067    mr_asprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
    10681068    res = run_program_and_log_output(command, FALSE);
    10691069    mr_free(command);
     
    10731073    }
    10741074
    1075     mr_asprintf(&command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);
     1075    mr_asprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);
    10761076    paranoid_system(command);
    10771077    mr_free(command);
    10781078
    10791079    if (bkpinfo->postnuke_tarball[0]) {
    1080         mr_asprintf(&command, "cp -f %s %s/post-nuke.tgz", bkpinfo->postnuke_tarball, bkpinfo->tmpdir);
     1080        mr_asprintf(command, "cp -f %s %s/post-nuke.tgz", bkpinfo->postnuke_tarball, bkpinfo->tmpdir);
    10811081        res = run_program_and_log_output(command, FALSE);
    10821082        mr_free(command);
     
    11211121
    11221122    log_it("Storing NFS configuration");
    1123     mr_asprintf(&tmp, "%s", bkpinfo->nfs_mount);
     1123    mr_asprintf(tmp, "%s", bkpinfo->nfs_mount);
    11241124    p = strchr(tmp, ':');
    11251125    if (!p) {
     
    11281128    }
    11291129    *(p++) = '\0';
    1130     mr_asprintf(&nfs_server_ipaddr, "%s", tmp);
    1131     mr_asprintf(&nfs_mount, "%s", p);
     1130    mr_asprintf(nfs_server_ipaddr, "%s", tmp);
     1131    mr_asprintf(nfs_mount, "%s", p);
    11321132    mr_free(tmp);
    11331133
    11341134    /* BERLIOS : there is a bug #67 here as it only considers the first NIC */
    1135     mr_asprintf(&command, "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");
    1136     mr_asprintf(&nfs_dev, "%s", call_program_and_get_last_line_of_output(command));
    1137     mr_free(command);
    1138 
    1139     mr_asprintf(&command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");
    1140     mr_asprintf(&nfs_client_ipaddr, "%s", call_program_and_get_last_line_of_output(command));
    1141     mr_free(command);
    1142 
    1143     mr_asprintf(&command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2");
    1144     mr_asprintf(&nfs_client_netmask, "%s", call_program_and_get_last_line_of_output(command));
    1145     mr_free(command);
    1146 
    1147     mr_asprintf(&command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2");
    1148     mr_asprintf(&nfs_client_broadcast, "%s", call_program_and_get_last_line_of_output(command));
    1149     mr_free(command);
    1150 
    1151     mr_asprintf(&command, "%s", "route -n | grep '^0.0.0.0' | awk '{print $2}'");
    1152     mr_asprintf(&nfs_client_defgw, "%s", call_program_and_get_last_line_of_output(command));
     1135    mr_asprintf(command, "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");
     1136    mr_asprintf(nfs_dev, "%s", call_program_and_get_last_line_of_output(command));
     1137    mr_free(command);
     1138
     1139    mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");
     1140    mr_asprintf(nfs_client_ipaddr, "%s", call_program_and_get_last_line_of_output(command));
     1141    mr_free(command);
     1142
     1143    mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2");
     1144    mr_asprintf(nfs_client_netmask, "%s", call_program_and_get_last_line_of_output(command));
     1145    mr_free(command);
     1146
     1147    mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2");
     1148    mr_asprintf(nfs_client_broadcast, "%s", call_program_and_get_last_line_of_output(command));
     1149    mr_free(command);
     1150
     1151    mr_asprintf(command, "%s", "route -n | grep '^0.0.0.0' | awk '{print $2}'");
     1152    mr_asprintf(nfs_client_defgw, "%s", call_program_and_get_last_line_of_output(command));
    11531153    mr_free(command);
    11541154
     
    11681168    if (!strncmp(nfs_dev, "bond", 4) || !strncmp(nfs_dev, "alb", 3) || !strncmp(nfs_dev, "aft", 3)) {
    11691169        log_to_screen("Found bonding device %s; looking for corresponding ethN slave device\n", nfs_dev);
    1170         mr_asprintf(&command, "%s", "ifconfig %s | awk '{print $5}' | head -n1", nfs_dev);
    1171         mr_asprintf(&mac_addr, "%s", call_program_and_get_last_line_of_output(command));
     1170        mr_asprintf(command, "%s", "ifconfig %s | awk '{print $5}' | head -n1", nfs_dev);
     1171        mr_asprintf(mac_addr, "%s", call_program_and_get_last_line_of_output(command));
    11721172        mr_free(command);
    11731173
    1174         mr_asprintf(&command, "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1", mac_addr,nfs_dev);
     1174        mr_asprintf(command, "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1", mac_addr,nfs_dev);
    11751175        mr_free(mac_addr);
    11761176        mr_free(nfs_dev);
    11771177
    1178         mr_asprintf(&nfs_dev, "%s", call_program_and_get_last_line_of_output(command));
     1178        mr_asprintf(nfs_dev, "%s", call_program_and_get_last_line_of_output(command));
    11791179        mr_free(command);
    11801180
     
    11821182    }
    11831183
    1184     mr_asprintf(&tmp, "%s/NFS-DEV", bkpinfo->tmpdir);
     1184    mr_asprintf(tmp, "%s/NFS-DEV", bkpinfo->tmpdir);
    11851185    write_one_liner_data_file(tmp, nfs_dev);
    11861186    mr_free(nfs_dev);
    11871187    mr_free(tmp);
    11881188
    1189     mr_asprintf(&tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir);
     1189    mr_asprintf(tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir);
    11901190    write_one_liner_data_file(tmp, nfs_client_ipaddr);
    11911191    mr_free(nfs_client_ipaddr);
    11921192    mr_free(tmp);
    11931193
    1194     mr_asprintf(&tmp, "%s/NFS-CLIENT-NETMASK", bkpinfo->tmpdir);
     1194    mr_asprintf(tmp, "%s/NFS-CLIENT-NETMASK", bkpinfo->tmpdir);
    11951195    write_one_liner_data_file(tmp, nfs_client_netmask);
    11961196    mr_free(nfs_client_netmask);
    11971197    mr_free(tmp);
    11981198
    1199     mr_asprintf(&tmp, "%s/NFS-CLIENT-BROADCAST", bkpinfo->tmpdir);
     1199    mr_asprintf(tmp, "%s/NFS-CLIENT-BROADCAST", bkpinfo->tmpdir);
    12001200    write_one_liner_data_file(tmp, nfs_client_broadcast);
    12011201    mr_free(nfs_client_broadcast);
    12021202    mr_free(tmp);
    12031203
    1204     mr_asprintf(&tmp, "%s/NFS-CLIENT-DEFGW", bkpinfo->tmpdir);
     1204    mr_asprintf(tmp, "%s/NFS-CLIENT-DEFGW", bkpinfo->tmpdir);
    12051205    write_one_liner_data_file(tmp, nfs_client_defgw);
    12061206    mr_free(nfs_client_defgw);
    12071207    mr_free(tmp);
    12081208
    1209     mr_asprintf(&tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir);
     1209    mr_asprintf(tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir);
    12101210    write_one_liner_data_file(tmp, nfs_server_ipaddr);
    12111211    mr_free(tmp);
    12121212    mr_free(nfs_server_ipaddr);
    12131213
    1214     mr_asprintf(&tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir);
     1214    mr_asprintf(tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir);
    12151215    write_one_liner_data_file(tmp, bkpinfo->nfs_mount);
    12161216    mr_free(tmp);
    12171217    mr_free(nfs_mount);
    12181218
    1219     mr_asprintf(&tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir);
     1219    mr_asprintf(tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir);
    12201220    write_one_liner_data_file(tmp, bkpinfo->nfs_remote_dir);
    12211221    mr_free(tmp);
    12221222
    1223     mr_asprintf(&tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
     1223    mr_asprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
    12241224    write_one_liner_data_file(tmp, bkpinfo->prefix);
    12251225    mr_free(tmp);
     
    12821282    if (scratchLL <= 1) {
    12831283        mds = media_descriptor_string(bkpinfo->backup_media_type);
    1284         mr_asprintf(&tmp, "Your backup will probably occupy a single %s. Maybe two.", mds);
     1284        mr_asprintf(tmp, "Your backup will probably occupy a single %s. Maybe two.", mds);
    12851285        mr_free(mds);
    12861286    } else if (scratchLL > 4) {
    1287         mr_asprintf(&tmp, "Your backup will occupy one meeeeellion media! (maybe %s)", number_to_text((int) (scratchLL + 1)));
     1287        mr_asprintf(tmp, "Your backup will occupy one meeeeellion media! (maybe %s)", number_to_text((int) (scratchLL + 1)));
    12881288    } else {
    1289         mr_asprintf(&tmp, "Your backup will occupy approximately %s media.", number_to_text((int) (scratchLL + 1)));
     1289        mr_asprintf(tmp, "Your backup will occupy approximately %s media.", number_to_text((int) (scratchLL + 1)));
    12901290    }
    12911291    if (!bkpinfo->image_devs[0] && (scratchLL < 50)) {
     
    13361336    }
    13371337
    1338     mr_asprintf(&tmp, "%s/do-not-compress-these", g_mondo_home);
     1338    mr_asprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
    13391339    if (!does_file_exist(tmp)) {
    13401340        mr_free(tmp);
     
    13461346
    13471347    for (p = do_not_compress_these; p != NULL; p++) {
    1348         mr_asprintf(&tmp, "%s", p);
     1348        mr_asprintf(tmp, "%s", p);
    13491349        if (strchr(tmp, ' ')) {
    13501350            *(strchr(tmp, ' ')) = '\0';
     
    13941394        paranoid_fclose(fout);
    13951395        log_msg(2, "Created %s", outfile);
    1396         mr_asprintf(&tmp, "chmod +x %s", outfile);
     1396        mr_asprintf(tmp, "chmod +x %s", outfile);
    13971397        paranoid_system(tmp);
    13981398        mr_free(tmp);
Note: See TracChangeset for help on using the changeset viewer.