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-tools.c

    r2322 r2323  
    219219
    220220    uname(&utsn);
    221     mr_asprintf(&tmp, "%s", utsn.machine);
     221    mr_asprintf(tmp, "%s", utsn.machine);
    222222    return (tmp);
    223223}
     
    449449    if (bkpinfo->backup_media_type == tape) {
    450450        log_msg(1, "Bar");
    451         mr_asprintf(&tmp, "mt -f %s status", bkpinfo->media_device);
     451        mr_asprintf(tmp, "mt -f %s status", bkpinfo->media_device);
    452452        log_msg(1, "tmp = '%s'", tmp);
    453453        if (run_program_and_log_output(tmp, 3)) {
     
    501501        }
    502502        if (bkpinfo->nonbootable_backup) {
    503             mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);
     503            mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);
    504504        } else if
    505505#ifdef __FreeBSD__
     
    510510#ifdef __IA64__
    511511    {
    512         mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);
     512        mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);
    513513    }
    514514#else
    515515    {
    516         mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);
     516        mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);
    517517    }
    518518#endif
    519519        else
    520520        {
    521             mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
     521            mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
    522522        }
    523523        if (bkpinfo->manual_cd_tray) {
     
    533533        }
    534534        if (getenv ("SUDO_COMMAND")) {
    535             mr_asprintf(&command, "strings `which growisofs` | grep -c SUDO_COMMAND");
     535            mr_asprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND");
    536536            if (!strcmp(call_program_and_get_last_line_of_output(command), "1")) {
    537537                mr_free(command);
     
    549549        || bkpinfo->backup_media_type == cdr) {
    550550        if (!bkpinfo->manual_cd_tray) {
    551             mr_asprintf(&extra_cdrom_params, "-waiti ");
     551            mr_asprintf(extra_cdrom_params, "-waiti ");
    552552        }
    553553        if (bkpinfo->backup_media_type == cdrw) {
    554             mr_asprintf(&extra_cdrom_params, "blank=fast ");
     554            mr_asprintf(extra_cdrom_params, "blank=fast ");
    555555        }
    556556        if (find_home_of_exe("cdrecord")) {
     
    562562        }
    563563        if (bkpinfo->nonbootable_backup) {
    564             mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT);
     564            mr_asprintf(mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT);
    565565        } else if
    566566#ifdef __FreeBSD__
     
    571571#ifdef __IA64__
    572572    {
    573         mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);
     573        mr_asprintf(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);
    574574    }
    575575#else
    576576    {
    577         mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);
     577        mr_asprintf(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);
    578578    }
    579579#endif
    580580        else
    581581        {
    582             mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);
     582            mr_asprintf(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);
    583583        }
    584584        if (bkpinfo->manual_cd_tray) {
     
    621621
    622622        log_it("isodir = %s", bkpinfo->isodir);
    623         mr_asprintf(&command, "df -P %s | tail -n1 | cut -d' ' -f1", bkpinfo->isodir);
     623        mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1", bkpinfo->isodir);
    624624        log_it("command = %s", command);
    625625        log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    626         mr_asprintf(&iso_dev, "%s", call_program_and_get_last_line_of_output(command));
    627         mr_asprintf(&tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
     626        mr_asprintf(iso_dev, "%s", call_program_and_get_last_line_of_output(command));
     627        mr_asprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
    628628        write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
    629629        mr_free(tmp);
    630630        mr_free(command);
    631631
    632         mr_asprintf(&command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", iso_dev);
     632        mr_asprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", iso_dev);
    633633        mr_free(iso_dev);
    634634
    635635        log_it("command = %s", command);
    636636        log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    637         mr_asprintf(&iso_mnt, "%s", call_program_and_get_last_line_of_output(command));
    638         mr_asprintf(&tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
     637        mr_asprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command));
     638        mr_asprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
    639639        write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
    640640        mr_free(tmp);
     
    642642
    643643        log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt));
    644         mr_asprintf(&iso_tmp, "%s", bkpinfo->isodir);
     644        mr_asprintf(iso_tmp, "%s", bkpinfo->isodir);
    645645        if (strlen(iso_tmp) < strlen(iso_mnt)) {
    646             mr_asprintf(&iso_path, "%s", "");
     646            mr_asprintf(iso_path, "%s", "");
    647647        } else {
    648             mr_asprintf(&iso_path, "%s", iso_tmp + strlen(iso_mnt));
     648            mr_asprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt));
    649649        }
    650650        mr_free(iso_tmp);
    651651
    652         mr_asprintf(&tmp, "%s/ISODIR", bkpinfo->tmpdir);
     652        mr_asprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir);
    653653        write_one_liner_data_file(tmp, iso_path);
    654654        mr_free(tmp);
     
    657657        mr_free(iso_path);
    658658
    659         mr_asprintf(&tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
     659        mr_asprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
    660660        write_one_liner_data_file(tmp, bkpinfo->prefix);
    661661        mr_free(tmp);
     
    682682                retval++;
    683683            } else {
    684                 mr_asprintf(&ip_address, "%s", inet_ntoa((struct in_addr) *((struct in_addr *) hent->h_addr)));
     684                mr_asprintf(ip_address, "%s", inet_ntoa((struct in_addr) *((struct in_addr *) hent->h_addr)));
    685685                mr_strcat(ip_address, strchr(bkpinfo->nfs_mount, ':'));
    686686                strcpy(bkpinfo->nfs_mount, ip_address);
     
    696696    }
    697697    if (bkpinfo->include_paths == NULL) {
    698         mr_asprintf(&p, "/");
     698        mr_asprintf(p, "/");
    699699        bkpinfo->include_paths = p;
    700700    }
     
    732732
    733733    unlink(MONDO_TRACEFILE);
    734     mr_asprintf(&tmp,"rm -Rf %s/changed.files*",MONDO_CACHE);
     734    mr_asprintf(tmp,"rm -Rf %s/changed.files*",MONDO_CACHE);
    735735    run_program_and_log_output(tmp, FALSE);
    736736    paranoid_free(tmp);
     
    758758        /* purging a potential old tmpdir */
    759759        log_it("Purging old tmpdir %s", bkpinfo->tmpdir);
    760         mr_asprintf(&tmp,"rm -Rf %s",bkpinfo->tmpdir);
     760        mr_asprintf(tmp,"rm -Rf %s",bkpinfo->tmpdir);
    761761        mr_free(bkpinfo->tmpdir);
    762762        (void)system(tmp);
     
    765765
    766766    if (path != NULL) {
    767         mr_asprintf(&tmp, "%s/mondo.tmp.XXXXXX", path);
     767        mr_asprintf(tmp, "%s/mondo.tmp.XXXXXX", path);
    768768    } else if (getenv("TMPDIR")) {
    769         mr_asprintf(&tmp, "%s/mondo.tmp.XXXXXX", getenv("TMPDIR"));
     769        mr_asprintf(tmp, "%s/mondo.tmp.XXXXXX", getenv("TMPDIR"));
    770770    } else if (getenv("TMP")) {
    771         mr_asprintf(&tmp, "%s/mondo.tmp.XXXXXX", getenv("TMP"));
     771        mr_asprintf(tmp, "%s/mondo.tmp.XXXXXX", getenv("TMP"));
    772772    } else {
    773         mr_asprintf(&tmp, "/tmp/mondo.tmp.XXXXXX");
     773        mr_asprintf(tmp, "/tmp/mondo.tmp.XXXXXX");
    774774    }
    775775    p = mkdtemp(tmp);
     
    821821    bkpinfo->use_lzo = FALSE;
    822822    bkpinfo->use_gzip = FALSE;
    823     bkpinfo->do_not_compress_these[0] = '\0';
    824823    bkpinfo->verify_data = FALSE;
    825824    bkpinfo->backup_data = FALSE;
     
    829828    bkpinfo->disaster_recovery = (am_I_in_disaster_recovery_mode()? TRUE : FALSE);
    830829    if (bkpinfo->disaster_recovery) {
    831         strcpy(bkpinfo->isodir, "/");
     830        mr_asprintf(p, "%s", "/");
    832831    } else {
    833         strcpy(bkpinfo->isodir, MONDO_CACHE);
    834     }
    835     mr_asprintf(&p, "%s", STD_PREFIX);
     832        mr_asprintf(p, "%s", MONDO_CACHE);
     833    }
     834    bkpinfo->isodir = p;
     835    mr_asprintf(p, "%s", STD_PREFIX);
    836836    bkpinfo->prefix = p;
    837837    bkpinfo->scratchdir = NULL;
     
    882882    assert_string_is_neither_NULL_nor_zerolength(partition);
    883883
    884     mr_asprintf(&command, "df -m -P %s 1> /dev/null 2> /dev/null", partition);
     884    mr_asprintf(command, "df -m -P %s 1> /dev/null 2> /dev/null", partition);
    885885    if (system(command)) {
    886886        mr_free(command);
     
    889889    mr_free(command);
    890890
    891     mr_asprintf(&command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
     891    mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
    892892            partition);
    893     mr_asprintf(&out_sz, "%s", call_program_and_get_last_line_of_output(command));
     893    mr_asprintf(out_sz, "%s", call_program_and_get_last_line_of_output(command));
    894894    mr_free(command);
    895895
     
    935935            ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
    936936    }
    937     mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
     937    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
    938938    if (atol(tmp) < 35000) {
    939939        retval++;
     
    10061006    run_program_and_log_output
    10071007        ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
    1008     mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\""));
     1008    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\""));
    10091009    if (strcmp("", tmp)) {
    10101010        if (strstr(tmp, "autofs")) {
     
    10391039        fatal_error("Please reinstall Mondo and Mindi.");
    10401040    }
    1041     mr_asprintf(&tmp, "mindi --makemountlist %s/mountlist.txt.test", bkpinfo->tmpdir);
     1041    mr_asprintf(tmp, "mindi --makemountlist %s/mountlist.txt.test", bkpinfo->tmpdir);
    10421042    if (run_program_and_log_output(tmp, 5)) {
    10431043        mr_free(tmp);
    1044         mr_asprintf(&tmp, "mindi --makemountlist %s/mountlist.txt.test failed for some reason.", bkpinfo->tmpdir);
     1044        mr_asprintf(tmp, "mindi --makemountlist %s/mountlist.txt.test failed for some reason.", bkpinfo->tmpdir);
    10451045        log_to_screen(tmp);
    10461046        log_to_screen
     
    10871087    assert_string_is_neither_NULL_nor_zerolength(label);
    10881088    if (!does_file_exist(config_file)) {
    1089         mr_asprintf(&tmp, "(read_cfg_var) Cannot find %s config file", config_file);
     1089        mr_asprintf(tmp, "(read_cfg_var) Cannot find %s config file", config_file);
    10901090        log_to_screen(tmp);
    10911091        mr_free(tmp);
     
    10971097        return (0);
    10981098    } else {
    1099         mr_asprintf(&command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5", label, config_file);
     1099        mr_asprintf(command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5", label, config_file);
    11001100        strcpy(value, call_program_and_get_last_line_of_output(command));
    11011101        mr_free(command);
     
    11801180        log_msg(3, "%s --- autofs detected", g_autofs_exe);
    11811181        // FIXME -- only disable it if it's running ---  sprintf(tmp, "%s status", autofs_exe);
    1182         mr_asprintf(&tmp, "%s stop", g_autofs_exe);
     1182        mr_asprintf(tmp, "%s stop", g_autofs_exe);
    11831183        if (run_program_and_log_output(tmp, 2)) {
    11841184            log_it("Failed to stop autofs - I assume it wasn't running");
     
    12021202        return;
    12031203    }
    1204     mr_asprintf(&tmp, "%s start", g_autofs_exe);
     1204    mr_asprintf(tmp, "%s start", g_autofs_exe);
    12051205    if (run_program_and_log_output(tmp, 2)) {
    12061206        log_it("Failed to start autofs");
     
    12251225    g_boot_mountpt[0] = '\0';
    12261226    log_msg(4, "Done. Great. Seeting command to something");
    1227     mr_asprintf(&command, "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[    ]/boot[     ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
     1227    mr_asprintf(command, "%s", "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[   ]/boot[     ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
    12281228    log_msg(4, "Cool. Command = '%s'", command);
    1229     mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     1229    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    12301230    mr_free(command);
    12311231
     
    12331233    if (tmp[0]) {
    12341234        log_it("/boot is at %s according to /etc/fstab", tmp);
    1235         mr_asprintf(&command, "mount | grep -Ew '/boot'");
     1235        mr_asprintf(command, "mount | grep -Ew '/boot'");
    12361236        mr_free(tmp);
    1237         mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     1237        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    12381238        mr_free(command);
    12391239
     
    12471247                }
    12481248            } else {
    1249                 mr_asprintf(&command, "mount | grep -E '^%s'", tmp);
     1249                mr_asprintf(command, "mount | grep -E '^%s'", tmp);
    12501250                log_msg(3, "command = %s", command);
    12511251                if (run_program_and_log_output(command, 5)) {
    12521252                    strcpy(g_boot_mountpt, tmp);
    12531253                    mr_free(tmp);
    1254                     mr_asprintf(&tmp, "%s (your /boot partition) is not mounted. I'll mount it before backing up", g_boot_mountpt);
     1254                    mr_asprintf(tmp, "%s (your /boot partition) is not mounted. I'll mount it before backing up", g_boot_mountpt);
    12551255                    log_it(tmp);
    12561256                    mr_free(tmp);
    12571257
    1258                     mr_asprintf(&tmp, "mount %s", g_boot_mountpt);
     1258                    mr_asprintf(tmp, "mount %s", g_boot_mountpt);
    12591259                    if (run_program_and_log_output(tmp, 5)) {
    12601260                        g_boot_mountpt[0] = '\0';
     
    12871287    log_msg(3, "starting");
    12881288    if (g_boot_mountpt[0]) {
    1289         mr_asprintf(&tmp, "umount %s", g_boot_mountpt);
     1289        mr_asprintf(tmp, "umount %s", g_boot_mountpt);
    12901290        if (run_program_and_log_output(tmp, 5)) {
    12911291            log_it("WARNING - unable to unmount /boot");
     
    13191319    assert(value != NULL);
    13201320    if (!does_file_exist(config_file)) {
    1321         mr_asprintf(&tmp, "(write_cfg_file) Cannot find %s config file", config_file);
     1321        mr_asprintf(tmp, "(write_cfg_file) Cannot find %s config file", config_file);
    13221322        log_to_screen(tmp);
    13231323        mr_free(tmp);
    13241324        return (1);
    13251325    }
    1326     mr_asprintf(&tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir);
     1326    mr_asprintf(tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir);
    13271327    if (does_file_exist(config_file)) {
    1328         mr_asprintf(&command, "grep -vE '^%s .*$' %s > %s", label, config_file, tempfile);
     1328        mr_asprintf(command, "grep -vE '^%s .*$' %s > %s", label, config_file, tempfile);
    13291329        paranoid_system(command);
    13301330        mr_free(command);
    13311331    }
    1332     mr_asprintf(&command, "echo \"%s %s\" >> %s", label, value, tempfile);
     1332    mr_asprintf(command, "echo \"%s %s\" >> %s", label, value, tempfile);
    13331333    paranoid_system(command);
    13341334    mr_free(command);
    13351335
    1336     mr_asprintf(&command, "mv -f %s %s", tempfile, config_file);
     1336    mr_asprintf(command, "mv -f %s %s", tempfile, config_file);
    13371337    paranoid_system(command);
    13381338    mr_free(command);
     
    14631463
    14641464    if (g_magicdev_command && g_magicdev_command[0]) {
    1465         mr_asprintf(&tmp, "%s &", g_magicdev_command);
     1465        mr_asprintf(tmp, "%s &", g_magicdev_command);
    14661466        paranoid_system(tmp);
    14671467        mr_free(tmp);
Note: See TracChangeset for help on using the changeset viewer.