Changeset 94 in MondoRescue for trunk/mondo/mondo/common/libmondo-tools.c


Ignore:
Timestamp:
Oct 29, 2005, 1:08:39 AM (18 years ago)
Author:
bcornec
Message:

x86_64 support (begining)
find_and_store_mondoarchives_home interface change
libmondo-tools.c modified with asprintf

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/common/libmondo-tools.c

    r89 r94  
    4141
    4242/**
    43  * The place where /boot is mounted.
    44  */
    45 char *g_boot_mountpt = NULL;
     43 * The place where /boot is mounted. - Used locally only
     44 */
     45static char *g_boot_mountpt = NULL;
    4646
    4747/**
     
    167167    char *tmp;
    168168
    169     malloc_string(tmp);
    170     strcpy(tmp,
     169    asprintf(&tmp,
    171170           "for i in `find /root /home -type d -name Desktop -maxdepth 2`; do \
    172171file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \
     
    185184 * @return 0 for success, nonzero for failure.
    186185 */
    187 int find_and_store_mondoarchives_home(char *home_sz)
    188 {
    189     assert(home_sz != NULL);
    190     strcpy(home_sz,
     186char *find_and_store_mondoarchives_home()
     187{
     188    char *home_sz = NULL;
     189
     190    asprintf(&home_sz,
    191191           call_program_and_get_last_line_of_output
    192192           ("find /usr/lib/ /usr/local/ /usr/share/ /usr/local/share/ /opt/ /ramdisk/usr/share/ -type d -maxdepth 2 -name include -prune -o -type d -maxdepth 2 -path '*/mondo/restore-scripts' -printf '%h\n' 2> /dev/null"));
    193193
    194194    if (home_sz[0] == '\0') {
    195         strcpy(home_sz,
     195        paranoid_free(home_sz);
     196        asprintf(&home_sz,
    196197               call_program_and_get_last_line_of_output
    197198               ("find /usr -type d -path '*/mondo/restore-scripts' -follow -maxdepth 3 -printf '%h\n' 2> /dev/null"));
    198199    }
    199200    if (home_sz[0] == '\0') {
    200         return (1);
     201        paranoid_free(home_sz);
     202        home_sz = NULL;
    201203    } else {
    202         return (0);
    203     }
     204        log_it("mondoarchive home found at %s", home_sz);
     205    }
     206    return (home_sz);
    204207}
    205208
     
    210213    return ("i386");
    211214#endif
     215#ifdef __X86_64__
     216    return ("x86-64");
     217#endif
    212218#ifdef __IA64__
    213219    return ("ia64");
     
    220226double get_kernel_version()
    221227{
    222     char *p, tmp[200];
     228    char *p, *tmp;
    223229    double d;
    224230#ifdef __FreeBSD__
     
    226232    d = 5.2;                    // :-)
    227233#else
    228     strcpy(tmp, call_program_and_get_last_line_of_output("uname -r"));
     234    asprintf(&tmp, call_program_and_get_last_line_of_output("uname -r"));
    229235    p = strchr(tmp, '.');
    230236    if (p) {
     
    254260long get_time()
    255261{
    256 
    257 #if 0
    258 
    259     /*@ pointers **************************************************** */
    260     FILE *fin;
    261 
    262     /*@ buffers ***************************************************** */
    263     char incoming[MAX_STR_LEN];
    264 
    265     /*@ end vars **************************************************** */
    266 
    267     if (!(fin = popen("date +%s", "r"))) {
    268         log_OS_error("Cannot popen date");
    269         return (0);
    270     }
    271     fgets(incoming, MAX_STR_LEN - 1, fin);
    272     paranoid_pclose(fin);
    273     return (atol(incoming));
    274 #else
    275262    return (long) time((void *) 0);
    276 #endif
    277263}
    278264
     
    335321    system("kldstat | grep ext2fs  || kldload ext2fs 2> /dev/null");
    336322#else
    337     system("modprobe dos &> /dev/null");
    338     system("modprobe fat &> /dev/null");
    339     system("modprobe vfat &> /dev/null");
    340     //  system("modprobe osst &> /dev/null");
    341 #endif
    342 }
    343 
    344 
    345 /**
    346  * Log a trace message to the trace file.
    347  * @bug This function seems orphaned. Please remove.
    348  */
    349 void log_trace(char *o)
    350 {
    351     /*@ pointers **************************************************** */
    352     FILE *fout;
    353 
    354     /*@ buffers ***************************************************** */
    355     char output[MAX_STR_LEN];
    356 
    357     /*@ int    ****************************************************** */
    358     int i;
    359 
    360     /*@ end vars *************************************************** */
    361 
    362     if (o[0] == '\0') {
    363         return;
    364     }
    365     strcpy(output, o);
    366     i = (int) strlen(output);
    367     if (i <= 0) {
    368         return;
    369     }
    370     if (output[i - 1] < 32) {
    371         output[i - 1] = '\0';
    372     }
    373     if (g_text_mode
    374         /* && !strstr(last_line_of_file(MONDO_LOGFILE),output) */ ) {
    375         printf("%s\n", output);
    376     }
    377 
    378     fout = fopen(MONDO_TRACEFILE, "a");
    379     if (fout) {
    380         fprintf(fout, "%s\n", output);
    381         paranoid_fclose(fout);
    382     } else {
    383         log_OS_error("Cannot write to tracefile");
    384     }
    385 }
    386 
    387 
    388 
     323    system("modprobe -a dos fat vfat loop &> /dev/null");
     324#endif
     325}
    389326
    390327
     
    422359int post_param_configuration(struct s_bkpinfo *bkpinfo)
    423360{
    424     char *extra_cdrom_params;
    425     char *mondo_mkisofs_sz;
     361    char *extra_cdrom_params = NULL;
     362    char *mondo_mkisofs_sz = NULL;
    426363    char *command;
    427     char *mtpt;
    428364    char *hostname, *ip_address;
    429365    int retval = 0;
     
    432368    char *cdr_exe;
    433369    char *tmp;
     370    char *tmp1;
    434371    int rdsiz_MB;
    435     char *iso_dev;
    436     char *iso_mnt;
    437     char *iso_tmp;
    438372    char *iso_path;
    439373
    440374    assert(bkpinfo != NULL);
    441     malloc_string(extra_cdrom_params);
    442     malloc_string(mondo_mkisofs_sz);
    443     malloc_string(command);
    444     malloc_string(mtpt);
    445     malloc_string(hostname);
    446     malloc_string(ip_address);
    447     malloc_string(cdr_exe);
    448     malloc_string(tmp);
    449     malloc_string(iso_dev);
    450     malloc_string(iso_mnt);
    451     malloc_string(iso_tmp);
    452     malloc_string(iso_path);
    453375    bkpinfo->optimal_set_size =
    454376        (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 4 : 8) *
     
    458380    if (bkpinfo->backup_media_type == tape) {
    459381        log_msg(1, "Bar");
    460         sprintf(tmp, "mt -f %s status", bkpinfo->media_device);
     382        asprintf(&tmp, "mt -f %s status", bkpinfo->media_device);
    461383        log_msg(1, "tmp = '%s'", tmp);
    462384        if (run_program_and_log_output(tmp, 3)) {
     
    464386                ("Unable to open tape device. If you haven't specified it with -d, do so. If you already have, check your parameter. I think it's wrong.");
    465387        }
     388        paranoid_free(tmp);
    466389    }
    467390    make_hole_for_dir(bkpinfo->scratchdir);
     
    472395    run_program_and_log_output("uname -a", 5);
    473396    run_program_and_log_output("cat /etc/*issue*", 5);
    474     sprintf(g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir);
    475     sprintf(command, "mkdir -p %s", g_tmpfs_mountpt);
     397    asprintf(&g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir);
     398    asprintf(&command, "mkdir -p %s", g_tmpfs_mountpt);
    476399    paranoid_system(command);
     400    paranoid_free(command);
    477401    rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB;
    478402#ifdef __FreeBSD__
    479     strcpy(tmp,
     403    asprintf(&tmp,
    480404           call_program_and_get_last_line_of_output
    481405           ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6"));
    482406    avm += atol(tmp);
    483     strcpy(tmp,
     407    paranoid_free(tmp);
     408    asprintf(&tmp,
    484409           call_program_and_get_last_line_of_output
    485410           ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"));
    486411    avm += atol(tmp);
    487     sprintf(command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm',
     412    paranoid_free(tmp);
     413    asprintf(&command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm',
    488414            g_tmpfs_mountpt);
    489415#else
    490     strcpy(tmp,
     416    asprintf(&tmp,
    491417           call_program_and_get_last_line_of_output
    492418           ("free | grep \":\" | tr -s ' ' '\t' | cut -f2 | head -n1"));
    493419    avm += atol(tmp);
    494     sprintf(command, "mount /dev/shm -t tmpfs %s -o size=%d%c",
     420    paranoid_free(tmp);
     421    asprintf(&command, "mount /dev/shm -t tmpfs %s -o size=%d%c",
    495422            g_tmpfs_mountpt, rdsiz_MB, 'm');
    496423    run_program_and_log_output("cat /proc/cpuinfo", 5);
     424    /* BERLIOS: rpm is not necessarily there ! */
    497425    run_program_and_log_output
    498426        ("rpm -q newt newt-devel slang slang-devel ncurses ncurses-devel gcc",
     
    510438        log_it("It doesn't seem you have enough swap to use tmpfs. Fine.");
    511439    }
     440    paranoid_free(command);
    512441
    513442    if (bkpinfo->use_lzo) {
     
    524453
    525454    if (bkpinfo->backup_media_type == dvd) {
    526         extra_cdrom_params[0] = '\0';
    527         mondo_mkisofs_sz[0] = '\0';
    528         if (find_home_of_exe("growisofs")) {
    529             strcpy(cdr_exe, "growisofs");
    530         }                       // unlikely to be used
    531         else {
     455        if (! (find_home_of_exe("growisofs"))) {
    532456            fatal_error("Please install growisofs.");
    533457        }
    534458        if (bkpinfo->nonbootable_backup) {
    535             strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);
     459            asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);
    536460        } else if
    537461#ifdef __FreeBSD__
     
    542466#ifdef __IA64__
    543467    {
    544         strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);
     468        asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);
    545469    }
    546470#else
    547471    {
    548         strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);
     472        asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);
    549473    }
    550474#endif
    551475        else
    552476        {
    553             strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
     477            asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
    554478        }
    555479        if (bkpinfo->manual_cd_tray) {
     
    560484                    "%s %s -Z %s . 2>> _ERR_",
    561485                    mondo_mkisofs_sz,
    562                     extra_cdrom_params, bkpinfo->media_device);
    563         }
     486                    "", bkpinfo->media_device);
     487        }
     488        paranoid_free(mondo_mkisofs_sz);
     489
    564490        if (getenv("SUDO_COMMAND")) {
    565491            fatal_error
     
    573499    if (bkpinfo->backup_media_type == cdrw
    574500        || bkpinfo->backup_media_type == cdr) {
    575         extra_cdrom_params[0] = '\0';
    576501        if (!bkpinfo->manual_cd_tray) {
    577             strcat(extra_cdrom_params, "-waiti ");
     502            asprintf(&extra_cdrom_params, "-waiti ");
    578503        }
    579504        if (bkpinfo->backup_media_type == cdrw) {
    580             strcat(extra_cdrom_params, "blank=fast ");
     505            if (extra_cdrom_params != NULL) {
     506                asprintf(&tmp, extra_cdrom_params);
     507                paranoid_free(extra_cdrom_params);
     508                asprintf(&extra_cdrom_params, "%s blank=fast ", tmp);
     509            } else {
     510                asprintf(&extra_cdrom_params, "blank=fast ");
     511            }
    581512        }
    582513        if (find_home_of_exe("cdrecord")) {
    583             strcpy(cdr_exe, "cdrecord");
     514            asprintf(&cdr_exe, "cdrecord");
    584515        } else if (find_home_of_exe("dvdrecord")) {
    585             strcpy(cdr_exe, "dvdrecord");
     516            asprintf(&cdr_exe, "dvdrecord");
    586517        } else {
    587518            fatal_error("Please install either cdrecord or dvdrecord.");
    588519        }
    589520        if (bkpinfo->nonbootable_backup) {
    590             strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT);
     521            asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT);
    591522        } else if
    592523#ifdef __FreeBSD__
     
    597528#ifdef __IA64__
    598529    {
    599         strcat(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);
     530        asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);
    600531    }
    601532#else
    602533    {
    603         strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);
     534        asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);
    604535    }
    605536#endif
    606537        else
    607538        {
    608             strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);
     539            asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);
    609540        }
    610541        if (bkpinfo->manual_cd_tray) {
     
    625556                    bkpinfo->cdrw_speed);
    626557        }
     558        paranoid_free(mondo_mkisofs_sz);
     559        paranoid_free(cdr_exe);
     560        paranoid_free(extra_cdrom_params);
    627561    }                           // end of CD code
    628 
    629     /*
    630        if (bkpinfo->backup_data && bkpinfo->backup_media_type == tape)
    631        {
    632        sprintf (tmp,
    633        "dd if=/dev/zero of=%s bs=%ld count=32 2> /dev/null",
    634        bkpinfo->media_device, bkpinfo->internal_tape_block_size);
    635        if (system(tmp))
    636        {
    637        retval++;
    638        fprintf (stderr,
    639        "Cannot write to tape device. Is the tape set read-only?\n");
    640        }
    641        } // end of tape code
    642      */
    643 
    644562
    645563    if (bkpinfo->backup_media_type == iso) {
     
    653571
    654572        log_it("isodir = %s", bkpinfo->isodir);
    655         sprintf(command, "df %s | tail -n1 | cut -d' ' -f1",
     573        asprintf(&command, "df %s | tail -n1 | cut -d' ' -f1",
    656574                bkpinfo->isodir);
    657575        log_it("command = %s", command);
    658         log_it("res of it = %s",
    659                call_program_and_get_last_line_of_output(command));
    660         sprintf(iso_dev, "%s",
    661                 call_program_and_get_last_line_of_output(command));
    662         sprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
    663         write_one_liner_data_file(tmp,
    664                                   call_program_and_get_last_line_of_output
    665                                   (command));
    666 
    667         sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
    668                 iso_dev);
     576        asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     577        paranoid_free(command);
     578        log_it("res of it = %s", tmp);
     579        asprintf(&tmp1, "%s/ISO-DEV", bkpinfo->tmpdir);
     580        write_one_liner_data_file(tmp1, tmp);
     581        paranoid_free(tmp1);
     582
     583        asprintf(&command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
     584                tmp);
     585        paranoid_free(tmp);
    669586        log_it("command = %s", command);
    670         log_it("res of it = %s",
    671                call_program_and_get_last_line_of_output(command));
    672         sprintf(iso_mnt, "%s",
    673                 call_program_and_get_last_line_of_output(command));
    674         sprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
    675         write_one_liner_data_file(tmp,
    676                                   call_program_and_get_last_line_of_output
    677                                   (command));
    678         log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt));
    679         sprintf(iso_tmp, "%s", bkpinfo->isodir);
    680         if (strlen(iso_tmp) < strlen(iso_mnt)) {
    681             iso_path[0] = '\0';
     587        asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     588        paranoid_free(command);
     589        log_it("res of it = %s", tmp);
     590
     591        asprintf(&tmp1, "%s/ISO-MNT", bkpinfo->tmpdir);
     592        write_one_liner_data_file(tmp1, tmp);
     593        paranoid_free(tmp1);
     594
     595        log_it("isomnt: %s, %d", tmp, strlen(tmp));
     596        if (strlen(bkpinfo->isodir) < strlen(tmp)) {
     597            asprintf(&iso_path,"");
    682598        } else {
    683             sprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt));
    684         }
    685         sprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir);
     599            asprintf(&iso_path, "%s", bkpinfo->isodir + strlen(tmp));
     600        }
     601        paranoid_free(tmp);
     602
     603        asprintf(&tmp, "%s/ISODIR", bkpinfo->tmpdir);
    686604        write_one_liner_data_file(tmp, iso_path);
     605        paranoid_free(tmp);
    687606        log_it("isodir: %s", iso_path);
     607        paranoid_free(iso_path);
    688608
    689609/* End patch */
     
    691611
    692612    if (bkpinfo->backup_media_type == nfs) {
    693         strcpy(hostname, bkpinfo->nfs_mount);
     613        asprintf(&hostname, bkpinfo->nfs_mount);
    694614        colon = strchr(hostname, ':');
    695615        if (!colon) {
     
    706626                retval++;
    707627            } else {
    708                 strcpy(ip_address, inet_ntoa((struct in_addr)
     628                asprintf(&ip_address, "%s%s", inet_ntoa((struct in_addr)
    709629                                             *((struct in_addr *) hent->
    710                                                h_addr)));
    711                 strcat(ip_address, strchr(bkpinfo->nfs_mount, ':'));
     630                                               h_addr)), strchr(bkpinfo->nfs_mount, ':'));
    712631                strcpy(bkpinfo->nfs_mount, ip_address);
     632                paranoid_free(ip_address);
    713633            }
    714634        }
    715635        store_nfs_config(bkpinfo);
     636        paranoid_free(hostname);
    716637    }
    717638
     
    720641        fprintf(stderr, "Type 'man mondoarchive' for help.\n");
    721642    }
    722     sprintf(tmp, "%s", MONDO_TMPISOS);
     643    asprintf(&tmp, "%s", MONDO_TMPISOS);
    723644    if (does_file_exist(tmp)) {
    724645        unlink(tmp);
    725646    }
     647    paranoid_free(tmp);
     648
    726649    if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) {
    727650        log_it("tmpdir or scratchdir are blank/missing");
     
    735658    chmod(bkpinfo->tmpdir, 0700);
    736659    g_backup_media_type = bkpinfo->backup_media_type;
    737     paranoid_free(mtpt);
    738     paranoid_free(extra_cdrom_params);
    739     paranoid_free(mondo_mkisofs_sz);
    740     paranoid_free(command);
    741     paranoid_free(hostname);
    742     paranoid_free(ip_address);
    743     paranoid_free(cdr_exe);
    744     paranoid_free(tmp);
    745     paranoid_free(iso_dev);
    746     paranoid_free(iso_mnt);
    747     paranoid_free(iso_tmp);
    748     paranoid_free(iso_path);
    749660    return (retval);
    750661}
     
    777688    unlink(MONDO_TRACEFILE);
    778689    run_program_and_log_output("rm -Rf /tmp/changed.files*", FALSE);
    779     if (find_and_store_mondoarchives_home(g_mondo_home)) {
     690    if ((g_mondo_home = find_and_store_mondoarchives_home()) == NULL) {
    780691        fprintf(stderr,
    781692                "Cannot find Mondo's homedir. I think you have >1 'mondo' directory on your hard disk. Please delete the superfluous 'mondo' directories and try again\n");
     
    866777long free_space_on_given_partition(char *partition)
    867778{
    868     char command[MAX_STR_LEN], out_sz[MAX_STR_LEN];
     779    char *command, *out_sz;
    869780    long res;
    870781
    871782    assert_string_is_neither_NULL_nor_zerolength(partition);
    872783
    873     sprintf(command, "df -m %s &> /dev/null", partition);
     784    asprintf(&command, "df -m %s &> /dev/null", partition);
    874785    if (system(command)) {
    875786        return (-1);
    876787    }                           // partition does not exist
    877     sprintf(command, "df -m %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
     788    paranoid_free(command);
     789
     790    asprintf(&command, "df -m %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
    878791            partition);
    879     strcpy(out_sz, call_program_and_get_last_line_of_output(command));
     792    asprintf(&out_sz, call_program_and_get_last_line_of_output(command));
     793    paranoid_free(command);
    880794    if (strlen(out_sz) == 0) {
    881795        return (-1);
    882796    }                           // error within df, probably
    883797    res = atol(out_sz);
     798    paranoid_free(out_sz);
    884799    return (res);
    885800}
     
    903818
    904819    /*@ buffers ************ */
    905     char tmp[MAX_STR_LEN];
    906     //  char command[MAX_STR_LEN];
     820    char *tmp;
    907821
    908822    /*@ int's *************** */
     
    921835            ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
    922836    }
    923     strcpy(tmp,
     837    asprintf(&tmp,
    924838           call_program_and_get_last_line_of_output
    925839           ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
     
    932846            ("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
    933847    }
     848    paranoid_free(tmp);
    934849#endif
    935850
     
    1010925    run_program_and_log_output
    1011926        ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
    1012     strcpy(tmp,
     927    asprintf(&tmp,
    1013928           call_program_and_get_last_line_of_output
    1014929           ("mount | grep -E \"cdr(om|w)\""));
     
    1029944        }
    1030945    }
     946    paranoid_free(tmp);
    1031947#ifndef __FreeBSD__
    1032948    if (!does_file_exist("/etc/modules.conf")) {
     
    11021018{
    11031019    /*@ buffer ****************************************************** */
    1104     char command[MAX_STR_LEN * 2];
    1105     char tmp[MAX_STR_LEN];
     1020    char *command;
     1021    char *tmp;
    11061022
    11071023    /*@ end vars *************************************************** */
     
    11101026    assert_string_is_neither_NULL_nor_zerolength(label);
    11111027    if (!does_file_exist(config_file)) {
    1112         sprintf(tmp, "(read_cfg_var) Cannot find %s config file",
     1028        asprintf(&tmp, "(read_cfg_var) Cannot find %s config file",
    11131029                config_file);
    11141030        log_to_screen(tmp);
     1031        paranoid_free(tmp);
    11151032        value[0] = '\0';
    11161033        return (1);
     
    11211038        return (0);
    11221039    } else {
    1123         sprintf(command, "cat %s | grep \"%s .*\" | cut -d' ' -f2,3,4,5",
     1040        asprintf(&command, "cat %s | grep \"%s .*\" | cut -d' ' -f2,3,4,5",
    11241041                config_file, label);
    11251042        strcpy(value, call_program_and_get_last_line_of_output(command));
     1043        paranoid_free(command);
    11261044        if (strlen(value) == 0) {
    11271045            return (1);
     
    11891107void stop_autofs_if_necessary()
    11901108{
    1191     char tmp[MAX_STR_LEN];
     1109    char *tmp;
    11921110
    11931111    g_autofs_exe[0] = '\0';
     
    12031121        log_msg(3, "%s --- autofs detected", g_autofs_exe);
    12041122// FIXME -- only disable it if it's running ---  sprintf(tmp, "%s status", autofs_exe);
    1205         sprintf(tmp, "%s stop", g_autofs_exe);
     1123        asprintf(&tmp, "%s stop", g_autofs_exe);
    12061124        if (run_program_and_log_output(tmp, 2)) {
    12071125            log_it("Failed to stop autofs - I assume it wasn't running");
     
    12101128            log_it("Stopped autofs OK");
    12111129        }
     1130        paranoid_free(tmp);
    12121131    }
    12131132}
     
    12181137void restart_autofs_if_necessary()
    12191138{
    1220     char tmp[MAX_STR_LEN];
     1139    char *tmp;
    12211140
    12221141    if (!g_autofs_stopped || !g_autofs_exe[0]) {
     
    12241143        return;
    12251144    }
    1226     sprintf(tmp, "%s start", g_autofs_exe);
     1145    asprintf(&tmp, "%s start", g_autofs_exe);
    12271146    if (run_program_and_log_output(tmp, 2)) {
    12281147        log_it("Failed to start autofs");
     
    12311150        log_it("Started autofs OK");
    12321151    }
     1152        paranoid_free(tmp);
    12331153}
    12341154
     
    12391159void mount_boot_if_necessary()
    12401160{
    1241     char tmp[MAX_STR_LEN];
    1242     char command[MAX_STR_LEN];
     1161    char *tmp;
     1162    char *tmp1;
     1163    char *command;
    12431164
    12441165    log_msg(1, "Started sub");
    1245     log_msg(4, "About to set g_boot_mountpt[0] to '\\0'");
    1246     g_boot_mountpt[0] = '\0';
     1166    log_msg(4, "About to set g_boot_mountpt to \"\"");
     1167    asprintf(&g_boot_mountpt, "");
    12471168    log_msg(4, "Done. Great. Seeting command to something");
    1248     strcpy(command,
     1169    asprintf(&command,
    12491170           "cat /etc/fstab | grep -v \":\" | grep -vx \"#.*\" | grep -w \"/boot\" | tr -s ' ' '\t' | cut -f1 | head -n1");
    12501171    log_msg(4, "Cool. Command = '%s'", command);
    1251     strcpy(tmp, call_program_and_get_last_line_of_output(command));
     1172    asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     1173    paranoid_free(command);
     1174
    12521175    log_msg(4, "tmp = '%s'", tmp);
    12531176    if (tmp[0]) {
     
    12551178        if (strstr(tmp, "LABEL=")) {
    12561179            if (!run_program_and_log_output("mount /boot", 5)) {
    1257                 strcpy(g_boot_mountpt, "/boot");
     1180                paranoid_free(g_boot_mountpt);
     1181                asprintf(&g_boot_mountpt, "/boot");
    12581182                log_msg(1, "Mounted /boot");
    12591183            } else {
     
    12611185            }
    12621186        } else {
    1263             sprintf(command, "mount | grep -w \"%s\"", tmp);
     1187            asprintf(&command, "mount | grep -w \"%s\"", tmp);
    12641188            log_msg(3, "command = %s", command);
    12651189            if (run_program_and_log_output(command, 5)) {
    1266                 strcpy(g_boot_mountpt, tmp);
    1267                 sprintf(tmp,
     1190                paranoid_free(g_boot_mountpt);
     1191                asprintf(&g_boot_mountpt, tmp);
     1192                asprintf(&tmp1,
    12681193                        "%s (your /boot partition) is not mounted. I'll mount it before backing up",
    12691194                        g_boot_mountpt);
    1270                 log_it(tmp);
    1271                 sprintf(tmp, "mount %s", g_boot_mountpt);
    1272                 if (run_program_and_log_output(tmp, 5)) {
    1273                     g_boot_mountpt[0] = '\0';
     1195                log_it(tmp1);
     1196                paranoid_free(tmp1);
     1197
     1198                asprintf(&tmp1, "mount %s", g_boot_mountpt);
     1199                if (run_program_and_log_output(tmp1, 5)) {
     1200                    paranoid_free(g_boot_mountpt);
     1201                    asprintf(&g_boot_mountpt, "");
    12741202                    log_msg(1, "Plan B");
    12751203                    if (!run_program_and_log_output("mount /boot", 5)) {
    1276                         strcpy(g_boot_mountpt, "/boot");
     1204                        paranoid_free(g_boot_mountpt);
     1205                        asprintf(&g_boot_mountpt, "/boot");
    12771206                        log_msg(1, "Plan B worked");
    12781207                    } else {
     
    12811210                    }
    12821211                }
     1212                paranoid_free(tmp1);
    12831213            }
    1284         }
    1285     }
     1214            paranoid_free(command);
     1215        }
     1216    }
     1217    paranoid_free(tmp);
    12861218    log_msg(1, "Ended sub");
    12871219}
     
    12931225void unmount_boot_if_necessary()
    12941226{
    1295     char tmp[MAX_STR_LEN];
     1227    char *tmp;
    12961228
    12971229    log_msg(3, "starting");
    12981230    if (g_boot_mountpt[0]) {
    1299         sprintf(tmp, "umount %s", g_boot_mountpt);
     1231        asprintf(&tmp, "umount %s", g_boot_mountpt);
    13001232        if (run_program_and_log_output(tmp, 5)) {
    13011233            log_it("WARNING - unable to unmount /boot");
    13021234        }
     1235        paranoid_free(tmp);
    13031236    }
    13041237    log_msg(3, "leaving");
     
    13181251{
    13191252    /*@ buffers ***************************************************** */
    1320     char command[MAX_STR_LEN * 2];
    1321     char tempfile[MAX_STR_LEN];
    1322     char tmp[MAX_STR_LEN];
     1253    char *command;
     1254    char *tempfile;
     1255    char *tmp;
    13231256
    13241257
     
    13271260    assert_string_is_neither_NULL_nor_zerolength(label);
    13281261    assert(value != NULL);
     1262
    13291263    if (!does_file_exist(config_file)) {
    1330         sprintf(tmp, "(write_cfg_file) Cannot find %s config file",
     1264        asprintf(&tmp, "(write_cfg_file) Cannot find %s config file",
    13311265                config_file);
    13321266        log_to_screen(tmp);
     1267        paranoid_free(tmp);
    13331268        return (1);
    13341269    }
    1335     strcpy(tempfile,
     1270    asprintf(&tempfile,
    13361271           call_program_and_get_last_line_of_output
    13371272           ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX"));
    13381273    if (does_file_exist(config_file)) {
    1339         sprintf(command, "cat %s | grep -vx \"%s .*\" > %s", config_file,
     1274        asprintf(&command, "cat %s | grep -vx \"%s .*\" > %s", config_file,
    13401275                label, tempfile);
    13411276        paranoid_system(command);
    1342     }
    1343     sprintf(command, "echo \"%s %s\" >> %s", label, value, tempfile);
     1277        paranoid_free(command);
     1278    }
     1279    asprintf(&command, "echo \"%s %s\" >> %s", label, value, tempfile);
    13441280    paranoid_system(command);
    1345     sprintf(command, "mv -f %s %s", tempfile, config_file);
     1281    paranoid_free(command);
     1282
     1283    asprintf(&command, "mv -f %s %s", tempfile, config_file);
    13461284    paranoid_system(command);
     1285    paranoid_free(command);
    13471286    unlink(tempfile);
     1287    paranoid_free(tempfile);
    13481288    return (0);
    13491289}
     
    13611301    int i;
    13621302    static int depth = 0;
    1363     char *tmp;
    13641303    FILE *fout;
    13651304
     
    13691308    }
    13701309    depth++;
    1371 
    1372     malloc_string(tmp);
    13731310
    13741311    if (debug_level <= g_loglevel) {
     
    14041341    }
    14051342    depth--;
    1406     paranoid_free(tmp);
    14071343}
    14081344
     
    14151351
    14161352/**
    1417  * If @p y, malloc @p x, else free @p x.
    1418  * @bug This function seems orphaned. Please remove.
    1419  */
    1420 #define do_alloc_or_free_depending(x,y) { if(y) {x=malloc(MAX_STR_LEN);} else {paranoid_free(x);} }
    1421 
    1422 /**
    14231353 * Allocate or free important globals, depending on @p mal.
    14241354 * @param mal If TRUE, malloc; if FALSE, free.
     
    14281358    if (mal) {
    14291359        iamhere("Malloc'ing globals");
    1430         malloc_string(g_boot_mountpt);
    1431         malloc_string(g_mondo_home);
    1432         malloc_string(g_tmpfs_mountpt);
    14331360        malloc_string(g_erase_tmpdir_and_scratchdir);
    14341361        malloc_string(g_serial_string);
     
    14431370        paranoid_free(g_magicdev_command);
    14441371    }
    1445 
    1446     /*
    1447        char**list_of_arrays[] = {
    1448        &g_boot_mountpt,
    1449        &g_mondo_home,
    1450        &g_tmpfs_mountpt,
    1451        &g_erase_tmpdir_and_scratchdir,
    1452        &g_serial_string,
    1453        &g_magicdev_command,
    1454        NULL};
    1455 
    1456        char**ppcurr;
    1457        int i;
    1458 
    1459        for(i=0;list_of_arrays[i];i++)
    1460        {
    1461        log_msg(5, "Allocating %d", i);
    1462        ppcurr = list_of_arrays[i];
    1463        if (mal)
    1464        { *ppcurr = malloc(MAX_STR_LEN); }
    1465        else
    1466        {
    1467        if (*ppcurr)
    1468        {
    1469        free(*ppcurr);
    1470        }
    1471        }
    1472        }
    1473        log_msg(5, "Returning");
    1474      */
    14751372}
    14761373
     
    15181415    char *tmp;
    15191416
    1520     malloc_string(tmp);
    15211417    if (g_magicdev_command && g_magicdev_command[0]) {
    1522         sprintf(tmp, "%s &", g_magicdev_command);
     1418        asprintf(&tmp, "%s &", g_magicdev_command);
    15231419        paranoid_system(tmp);
    1524     }
    1525     paranoid_free(tmp);
     1420        paranoid_free(tmp);
     1421    }
    15261422}
    15271423
Note: See TracChangeset for help on using the changeset viewer.