Ignore:
Timestamp:
Sep 25, 2013, 8:55:45 AM (11 years ago)
Author:
Bruno Cornec
Message:
  • Lots of memory management backports from 3.1 to 3.2 - still not finished, nor working ATM. the common subdir was done during travel, so this is essentially a backup !
File:
1 edited

Legend:

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

    r3185 r3191  
    3030
    3131extern int g_tape_buffer_size_MB;
    32 extern char *g_serial_string;
    3332extern bool g_text_mode;
    3433extern int g_currentY;
    3534extern int g_current_media_number;
    3635extern char *MONDO_LOGFILE;
     36extern char *g_serial_string;
    3737
    3838/* Reference to global bkpinfo */
     
    113113        return;
    114114    }
    115 #ifndef _XWIN
    116115    if (!g_text_mode)
    117116        newtSuspend();
    118 #endif
    119117    printf("ASSERTION FAILED: `%s'\n", exp);
    120118    printf("\tat %s:%d in %s\n\n", file, line, function);
     
    163161    getchar();                  // skip \n
    164162
    165 #ifndef _XWIN
    166163    if (!g_text_mode)
    167164        newtResume();
    168 #endif
    169165}
    170166
     
    175171void clean_up_KDE_desktop_if_necessary(void)
    176172{
    177     char *tmp;
    178 
    179     malloc_string(tmp);
    180     strcpy(tmp,
    181            "for i in `find /root /home -maxdepth 2 -type d -name Desktop`; do \
    182 file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \
    183 awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \
    184 else { print $0;};}' $file.old  > $file ; fi ; done");
     173    char *tmp = NULL;
     174
     175    mr_asprintf(tmp, "for i in `find /root /home -maxdepth 2 -type d -name Desktop -maxdepth 2`; do file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } else { print $0;};}' $file.old  > $file ; fi ; done");
    185176    run_program_and_log_output(tmp, 5);
    186     paranoid_free(tmp);
     177    mr_free(tmp);
    187178}
    188179
     
    232223double get_kernel_version(void)
    233224{
    234     char *p, tmp[200];
     225    char *p = NULL;
     226    char *tmp = NULL;
    235227    double d;
    236228#ifdef __FreeBSD__
     
    238230    d = 5.2;                    // :-)
    239231#else
    240     strcpy(tmp, call_program_and_get_last_line_of_output("uname -r"));
     232    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("uname -r"));
    241233    p = strchr(tmp, '.');
    242234    if (p) {
     
    249241        }
    250242    }
    251 //  log_msg(1, "tmp = '%s'", tmp);
    252243    d = atof(tmp);
     244    mr_free(tmp);
    253245#endif
    254246    log_msg(1, "g_kernel_version = %f", d);
     
    257249
    258250
    259 
    260 
    261 
    262251/**
    263252 * Get the current time.
     
    268257    return (long) time((void *) 0);
    269258}
    270 
    271 
    272 
    273 
    274 
    275259
    276260
     
    368352    char *mondo_mkisofs_sz = NULL;
    369353    char *command = NULL;
    370     char *mtpt;
    371     char *hostname;
     354    char *hostname = NULL;
    372355    char *isofs_cmd = NULL;
    373356    char *ip_address = NULL;
    374357    int retval = 0;
    375358    char *colon;
    376     char *cdr_exe;
     359    char *cdr_exe = NULL;
    377360    char *tmp = NULL;
    378     char call_before_iso_user[MAX_STR_LEN] = "\0";
    379     /*
    380     long avm = 0;
    381     int rdsiz_MB;
    382     */
     361    char *p = NULL;
     362    char *call_before_iso_user = NULL;
    383363    char *iso_dev = NULL;
    384364    char *iso_mnt = NULL;
     
    387367
    388368    assert(bkpinfo != NULL);
    389     malloc_string(mtpt);
    390     malloc_string(hostname);
    391     malloc_string(cdr_exe);
     369
    392370    bkpinfo->optimal_set_size =
    393371        (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) *
     
    400378        }
    401379        log_msg(1, "Tape");
     380        if (bkpinfo->media_device == NULL) {
     381            return(1);
     382        }
    402383        mr_asprintf(tmp, "mt -f %s status", bkpinfo->media_device);
    403384        log_msg(1, "tmp = '%s'", tmp);
     
    429410        strcpy(bkpinfo->zip_exe, "gzip");
    430411        strcpy(bkpinfo->zip_suffix, "gz");
     412    } else if (bkpinfo->use_lzma) {
     413        strcpy(bkpinfo->zip_exe, "lzma");
     414        strcpy(bkpinfo->zip_suffix, "lzma");
    431415    } else if (bkpinfo->compression_level != 0) {
    432416        strcpy(bkpinfo->zip_exe, "bzip2");
     
    440424    if (bkpinfo->backup_media_type == dvd) {
    441425        if (find_home_of_exe("growisofs")) {
    442             strcpy(cdr_exe, "growisofs");
     426            mr_asprintf(cdr_exe, "growisofs");
    443427        }                       // unlikely to be used
    444428        else {
     
    462446    }
    463447#endif
    464         else
    465         {
     448        else {
    466449            mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
    467450        }
    468451        if (bkpinfo->manual_cd_tray) {
    469             paranoid_free(mondo_mkisofs_sz);
    470452            fatal_error("Manual CD tray + DVD not supported yet.");
    471453            // -m isn't supported by growisofs, BTW...
     
    475457                    mondo_mkisofs_sz,
    476458                    "", bkpinfo->media_device);
    477             paranoid_free(mondo_mkisofs_sz);
    478         }
     459        }
     460        mr_free(mondo_mkisofs_sz);
    479461        if (getenv ("SUDO_COMMAND")) {
    480462            mr_asprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND");
     
    486468            mr_free(command);
    487469        }
    488         log_msg(2, "call_make_iso (DVD res) is ... %s",
    489                 bkpinfo->call_make_iso);
     470        log_msg(2, "call_make_iso (DVD res) is ... %s", bkpinfo->call_make_iso);
    490471    }                           // end of DVD code
    491472
     
    504485        }
    505486        if (find_home_of_exe("cdrecord")) {
    506             strcpy(cdr_exe, "cdrecord");
     487            mr_asprintf(cdr_exe, "cdrecord");
    507488        } else if (find_home_of_exe("dvdrecord")) {
    508             strcpy(cdr_exe, "dvdrecord");
     489            mr_asprintf(cdr_exe, "dvdrecord");
    509490        } else {
    510491            fatal_error("Please install either cdrecord or dvdrecord.");
     
    544525                        mondo_mkisofs_sz, bkpinfo->tmpdir);
    545526                } else {
    546                 strncpy(call_before_iso_user, bkpinfo->call_before_iso, MAX_STR_LEN);
    547                 sprintf (bkpinfo->call_before_iso,
    548                                     "( %s -o %s/"MONDO_TMPISOS" . 2>> _ERR_ ; %s )",
    549                         mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user);
     527                mr_asprintf(call_before_iso_user, "%s", bkpinfo->call_before_iso);
     528                sprintf(bkpinfo->call_before_iso, "( %s -o %s/"MONDO_TMPISOS" . 2>> _ERR_ ; %s )", mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user);
     529                mr_free(call_before_iso_user);
    550530            }
    551531            log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso);
    552             sprintf(bkpinfo->call_make_iso,
    553                     "%s %s -v %s fs=4m dev=%s speed=%d %s/"MONDO_TMPISOS,
    554                     cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject",
    555                     extra_cdrom_params, bkpinfo->media_device,
    556                     bkpinfo->cdrw_speed, bkpinfo->tmpdir);
     532            sprintf(bkpinfo->call_make_iso, "%s %s -v %s fs=4m dev=%s speed=%d %s/"MONDO_TMPISOS, cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject", extra_cdrom_params, bkpinfo->media_device, bkpinfo->cdrw_speed, bkpinfo->tmpdir);
    557533        } else {
    558             sprintf(bkpinfo->call_make_iso,
    559                     "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -",
    560                     mondo_mkisofs_sz, cdr_exe,
    561                     (bkpinfo->please_dont_eject) ? " " : "-eject",
    562                     extra_cdrom_params, bkpinfo->media_device,
    563                     bkpinfo->cdrw_speed);
    564         }
    565         paranoid_free(mondo_mkisofs_sz);
    566         paranoid_free(extra_cdrom_params);
     534            sprintf(bkpinfo->call_make_iso, "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -", mondo_mkisofs_sz, cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject", extra_cdrom_params, bkpinfo->media_device, bkpinfo->cdrw_speed);
     535        }
     536        mr_free(cdr_exe);
     537        mr_free(mondo_mkisofs_sz);
     538        mr_free(extra_cdrom_params);
    567539    }                           // end of CD code
    568540
     
    577549
    578550        log_it("isodir = %s", bkpinfo->isodir);
    579         mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1",
    580                 bkpinfo->isodir);
     551        mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1", bkpinfo->isodir);
    581552        log_it("command = %s", command);
    582         log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    583553        mr_asprintf(iso_dev, "%s", call_program_and_get_last_line_of_output(command));
     554        log_it("res of it = %s", iso_dev);
    584555        mr_asprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
    585         write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
     556        write_one_liner_data_file(tmp, iso_dev);
    586557        mr_free(tmp);
    587558        mr_free(command);
     
    591562
    592563        log_it("command = %s", command);
    593         log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    594564        mr_asprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command));
     565        log_it("res of it = %s", iso_mnt);
    595566        mr_asprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
    596         write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
     567        write_one_liner_data_file(tmp, iso_mnt);
    597568        mr_free(tmp);
    598569        mr_free(command);
     
    612583            }
    613584        }
     585        mr_free(iso_mnt);
    614586        mr_free(iso_tmp);
    615         mr_free(iso_mnt);
    616587
    617588        mr_asprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir);
     
    632603
    633604    if (bkpinfo->backup_media_type == netfs) {
    634         strcpy(hostname, bkpinfo->netfs_mount);
     605        if (bkpinfo->netfs_mount) {
     606            mr_asprintf(hostname, "%s", bkpinfo->netfs_mount);
     607        } else {
     608            log_it("netfs_mount is NULL");
     609            retval++;
     610            mr_asprintf(hostname, "");
     611        }
    635612        colon = strchr(hostname, ':');
    636613        if (!colon) {
     
    651628            }
    652629            if (!hent) {
    653                 log_it("Can't resolve Network mount (%s): %s", hostname,
    654                        hstrerror(h_errno));
     630                log_it("Can't resolve Network mount (%s): %s", hostname, hstrerror(h_errno));
    655631                retval++;
    656632            } else {
     
    658634                mr_strcat(ip_address, strchr(bkpinfo->netfs_mount, ':'));
    659635                strcpy(bkpinfo->netfs_mount, ip_address);
    660                 paranoid_free(ip_address);
     636                mr_free(ip_address);
    661637            }
    662638        }
     639        mr_free(hostname);
    663640        store_netfs_config();
    664641    }
     
    668645        fprintf(stderr, "Type 'man mondoarchive' for help.\n");
    669646    }
    670     if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) {
    671         log_it("tmpdir or scratchdir are blank/missing");
    672         retval++;
    673     }
    674     if (bkpinfo->include_paths[0] == '\0') {
    675         //      fatal_error ("Why no backup path?");
    676         strcpy(bkpinfo->include_paths, "/");
    677     }
    678     chmod(bkpinfo->scratchdir, 0700);
     647    if (bkpinfo->include_paths == NULL) {
     648        mr_asprintf(bkpinfo->include_paths, "/");
     649    }
    679650    g_backup_media_type = bkpinfo->backup_media_type;
    680     paranoid_free(mtpt);
    681     paranoid_free(hostname);
    682     paranoid_free(cdr_exe);
    683651    return (retval);
    684652}
     
    704672    if (bkpinfo->disaster_recovery) {
    705673        if (!does_nonMS_partition_exist()) {
    706             fatal_error
    707                 ("I am in disaster recovery mode\nPlease don't run mondoarchive.");
     674            fatal_error("I am in disaster recovery mode\nPlease don't run mondoarchive.");
    708675        }
    709676    }
     
    713680    paranoid_free(tmp);
    714681    if (find_and_store_mondoarchives_home(g_mondo_home)) {
    715         fprintf(stderr,
    716                 "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");
     682        fprintf(stderr, "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");
    717683        res++;
    718684        return (res);
     
    723689    }
    724690    g_current_media_number = 1;
    725     bkpinfo->postnuke_tarball[0] = bkpinfo->netfs_mount[0] = '\0';
     691    bkpinfo->postnuke_tarball[0] = '\0';
    726692    return (res);
    727693}
     
    772738    if (p == NULL) {
    773739        log_it("Failed to create global tmp directory %s for Mondo.",tmp);
     740        mr_free(tmp);
    774741        finish(-1);
    775742    }
     743    mr_free(tmp);
     744
    776745    strcpy(bkpinfo->tmpdir,p);
    777     paranoid_free(tmp);
     746    log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir);
    778747
    779748    mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
     
    817786    }
    818787    strcpy(bkpinfo->scratchdir,p);
     788    log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
    819789    paranoid_free(tmp);
    820790
     
    832802{
    833803    int i;
    834 
    835     log_msg(1, "Hi");
     804    log_msg(1, "Initializing bkpinfo");
     805
    836806    assert(bkpinfo != NULL);
    837807    memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo));
     
    847817    bkpinfo->use_lzo = FALSE;
    848818    bkpinfo->use_gzip = FALSE;
    849     bkpinfo->do_not_compress_these[0] = '\0';
     819    bkpinfo->use_lzma = FALSE;
    850820    bkpinfo->verify_data = FALSE;
    851821    bkpinfo->backup_data = FALSE;
     
    853823    bkpinfo->use_star = FALSE;
    854824    bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
    855     bkpinfo->disaster_recovery =
    856         (am_I_in_disaster_recovery_mode()? TRUE : FALSE);
     825   
     826/*  We need tmpdir as early as possible for further function calls */
     827    bkpinfo->tmpdir = NULL;         // Really setup after
     828    setup_tmpdir(NULL);
     829    setup_scratchdir(NULL);
     830
     831    bkpinfo->disaster_recovery = am_I_in_disaster_recovery_mode();
    857832    if (bkpinfo->disaster_recovery) {
    858833        strcpy(bkpinfo->isodir, "/");
     
    861836    }
    862837    strcpy(bkpinfo->prefix, STD_PREFIX);
    863     setup_tmpdir(NULL);
    864     setup_scratchdir(NULL);
    865 
    866838    bkpinfo->optimal_set_size = 0;
    867     strcpy(bkpinfo->include_paths, "/");
     839    bkpinfo->backup_media_type = none;
    868840    bkpinfo->make_filelist = TRUE;  // unless -J supplied to mondoarchive
    869     bkpinfo->include_paths[0] = '\0';
     841    bkpinfo->exclude_paths = NULL;
     842    bkpinfo->include_paths = NULL;
    870843    bkpinfo->exclude_devs = NULL;
    871844    bkpinfo->restore_path[0] = '\0';
     
    879852    bkpinfo->netfs_user = NULL;
    880853    bkpinfo->netfs_remote_dir[0] = '\0';
    881     bkpinfo->exclude_paths = NULL;
     854    bkpinfo->postnuke_tarball[0] = '\0';
    882855    bkpinfo->subdir = NULL;
    883     bkpinfo->postnuke_tarball[0] = '\0';
    884856    bkpinfo->wipe_media_first = FALSE;
    885857    bkpinfo->differential = 0;
     
    894866
    895867
    896 
    897 
    898868/**
    899869 * Get the remaining free space (in MB) on @p partition.
     
    916886    mr_free(command);
    917887
    918     mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
    919             partition);
     888    mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", partition);
    920889    mr_asprintf(out_sz, "%s", call_program_and_get_last_line_of_output(command));
    921890    mr_free(command);
     
    957926    if (system("which mkfs.vfat 2> /dev/null 1> /dev/null")
    958927        && !system("which mkfs.msdos 2> /dev/null 1> /dev/null")) {
    959         log_it
    960             ("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand...");
    961         run_program_and_log_output
    962             ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
    963     }
    964     mr_asprintf(tmp, "%s",
    965            call_program_and_get_last_line_of_output
    966            ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
     928        log_it("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand...");
     929        run_program_and_log_output("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
     930    }
     931    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
    967932    if (atol(tmp) < 35000) {
    968933        retval++;
     
    970935    }
    971936    if (atol(tmp) < 66000) {
    972         log_to_screen
    973             ("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
     937        log_to_screen("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
    974938    }
    975939    mr_free(tmp);
     
    1026990        whine_if_not_found("cmp");
    1027991    }
    1028     run_program_and_log_output
    1029         ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
    1030     mr_asprintf(tmp, "%s",
    1031            call_program_and_get_last_line_of_output
    1032            ("mount | grep -E \"cdr(om|w)\""));
     992    run_program_and_log_output("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
     993    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\""));
    1033994    if (strcmp("", tmp)) {
    1034995        if (strstr(tmp, "autofs")) {
     
    11041065    /*@ buffer ****************************************************** */
    11051066    char *command = NULL;
    1106     char *tmp = NULL;
    11071067
    11081068    /*@ end vars *************************************************** */
     
    11111071    assert_string_is_neither_NULL_nor_zerolength(label);
    11121072    if (!does_file_exist(config_file)) {
    1113         mr_asprintf(tmp, "(read_cfg_var) Cannot find %s config file",
    1114                 config_file);
    1115         log_to_screen(tmp);
    1116         mr_free(tmp);
    1117 
     1073        log_to_screen("(read_cfg_var) Cannot find %s config file", config_file);
    11181074        value[0] = '\0';
    11191075        return (1);
     
    11271083        mr_free(command);
    11281084
     1085        log_msg(4, "Configuration item %s is %s", label, value);
    11291086        if (strlen(value) == 0) {
    11301087            return (1);
     
    12421199 * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it.
    12431200 */
    1244 void mount_boot_if_necessary()
    1245 {
     1201void mount_boot_if_necessary() {
    12461202    char *tmp = NULL;
    12471203    char *command = NULL;
     
    12511207    g_boot_mountpt[0] = '\0';
    12521208    log_msg(4, "Done. Great. Seeting command to something");
    1253     mr_asprintf(command, "%s",
    1254            "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[   ]/boot[     ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
     1209    mr_asprintf(command, "%s", "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[   ]/boot[     ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
    12551210    log_msg(4, "Cool. Command = '%s'", command);
    12561211    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     
    12581213
    12591214    log_msg(4, "tmp = '%s'", tmp);
    1260     if (tmp[0]) {
    1261         log_it("/boot is at %s according to /etc/fstab", tmp);
    1262         mr_asprintf(command, "mount | grep -Ew '/boot'");
    1263         mr_free(tmp);
    1264         mr_asprintf(tmp, call_program_and_get_last_line_of_output(command));
    1265         mr_free(command);
    1266 
    1267         if (!strcmp(tmp,"")) {
    1268             if (((strstr(tmp, "LABEL=") != NULL) || (strstr(tmp,"UUID=")) != NULL)) {
    1269                 if (!run_program_and_log_output("mount /boot", 5)) {
    1270                     strcpy(g_boot_mountpt, "/boot");
    1271                     log_msg(1, "Mounted /boot");
    1272                 } else {
    1273                     log_it("...ignored cos it's a label or uuid :-)");
     1215    log_it("/boot is at %s according to /etc/fstab", tmp);
     1216    mr_asprintf(command, "mount | grep -Ew '/boot'");
     1217    mr_free(tmp);
     1218
     1219    mr_asprintf(tmp, call_program_and_get_last_line_of_output(command));
     1220    mr_free(command);
     1221
     1222    if (!strcmp(tmp,"")) {
     1223        if ((strstr(tmp, "LABEL=") != NULL) || (strstr(tmp,"UUID=") != NULL)) {
     1224            if (!run_program_and_log_output("mount /boot", 5)) {
     1225                strcpy(g_boot_mountpt, "/boot");
     1226                log_msg(1, "Mounted /boot");
     1227            } else {
     1228                log_it("...ignored cos it's a label or uuid :-)");
     1229            }
     1230        } else {
     1231            mr_asprintf(command, "mount | grep -E '^%s'", tmp);
     1232            log_msg(3, "command = %s", command);
     1233            if (run_program_and_log_output(command, 5)) {
     1234                strcpy(g_boot_mountpt, tmp);
     1235                mr_free(tmp);
     1236                log_it("%s (your /boot partition) is not mounted. I'll mount it before backing up", g_boot_mountpt);
     1237
     1238                mr_asprintf(tmp, "mount %s", g_boot_mountpt);
     1239                if (run_program_and_log_output(tmp, 5)) {
     1240                    g_boot_mountpt[0] = '\0';
     1241                    log_msg(1, "Plan B");
     1242                    if (!run_program_and_log_output("mount /boot", 5)) {
     1243                        strcpy(g_boot_mountpt, "/boot");
     1244                        log_msg(1, "Plan B worked");
     1245                    } else {
     1246                        log_msg(1,
     1247                            "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
     1248                    }
    12741249                }
    1275             } else {
    1276                 mr_asprintf(command, "mount | grep -E '^%s'", tmp);
    1277                 log_msg(3, "command = %s", command);
    1278                 if (run_program_and_log_output(command, 5)) {
    1279                     strcpy(g_boot_mountpt, tmp);
    1280                     mr_free(tmp);
    1281                     mr_asprintf(tmp,
    1282                             "%s (your /boot partition) is not mounted. I'll mount it before backing up",
    1283                             g_boot_mountpt);
    1284                     log_it(tmp);
    1285                     mr_free(tmp);
    1286 
    1287                     mr_asprintf(tmp, "mount %s", g_boot_mountpt);
    1288                     if (run_program_and_log_output(tmp, 5)) {
    1289                         g_boot_mountpt[0] = '\0';
    1290                         log_msg(1, "Plan B");
    1291                         if (!run_program_and_log_output("mount /boot", 5)) {
    1292                             strcpy(g_boot_mountpt, "/boot");
    1293                             log_msg(1, "Plan B worked");
    1294                         } else {
    1295                             log_msg(1,
    1296                                 "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
    1297                         }
    1298                     }
    1299                     mr_free(tmp);
    1300                 }
    1301                 mr_free(command);
    13021250            }
    1303         }
    1304     }
     1251            mr_free(command);
     1252        }
     1253    }
     1254    mr_free(tmp);
    13051255    log_msg(1, "Ended sub");
    13061256}
     
    13401290    char *command = NULL;
    13411291    char *tempfile = NULL;
    1342     char *tmp = NULL;
    13431292
    13441293
     
    13481297    assert(value != NULL);
    13491298    if (!does_file_exist(config_file)) {
    1350         mr_asprintf(tmp, "(write_cfg_file) Cannot find %s config file",
    1351                 config_file);
    1352         log_to_screen(tmp);
    1353         mr_free(tmp);
     1299        log_to_screen("(write_cfg_file) Cannot find %s config file", config_file);
    13541300        return (1);
    13551301    }
    13561302    mr_asprintf(tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir);
    13571303    if (does_file_exist(config_file)) {
    1358         mr_asprintf(command, "grep -vE '^%s .*$' %s > %s",
    1359                 label, config_file, tempfile);
     1304        mr_asprintf(command, "grep -vE '^%s .*$' %s > %s", label, config_file, tempfile);
    13601305        paranoid_system(command);
    13611306        mr_free(command);
     
    13781323 * information to the logfile.
    13791324 */
    1380 void standard_log_debug_msg(int debug_level, const char *szFile,
    1381                             const char *szFunction, int nLine,
    1382                             const char *fmt, ...)
    1383 {
     1325void standard_log_debug_msg(int debug_level, const char *szFile, const char *szFunction, int nLine, const char *fmt, ...) {
     1326
    13841327    va_list args;
    1385     int i;
    13861328    static int depth = 0;
    13871329    FILE *fout;
     
    13961338        if (!(fout = fopen(MONDO_LOGFILE, "a"))) {
    13971339            return;
    1398         }       // fatal_error("Failed to openout to logfile - sheesh..."); }
     1340        }
    13991341
    14001342        // add tabs to distinguish log levels
    14011343        if (debug_level > 0) {
    1402             for (i = 1; i < debug_level; i++)
    1403                 fprintf(fout, "\t");
     1344            fprintf(fout, "DBG%d: ", debug_level);
    14041345            if (getpid() == g_main_pid)
    14051346                fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction, nLine);
     
    14081349            else
    14091350                fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile, szFunction, nLine);
     1351        } else {
     1352            fprintf(fout, "INFO: ");
    14101353        }
    14111354        va_start(args, fmt);
     
    14131356        va_end(args);
    14141357
    1415         // do not slow down the progran if standard debug level
    1416         // must be enabled: if no flush, the log won't be up-to-date if there
    1417         // is a segfault
    1418         //if (g_dwDebugLevel != 1)
    1419 
    14201358        fprintf(fout, "\n");
    14211359        paranoid_fclose(fout);
     
    14301368                       ...) = standard_log_debug_msg;
    14311369
    1432 
    1433 /**
    1434  * If @p y, malloc @p x, else free @p x.
    1435  * @bug This function seems orphaned. Please remove.
    1436  */
    1437 #define do_alloc_or_free_depending(x,y) { if(y) {x=malloc(MAX_STR_LEN);} else {paranoid_free(x);} }
    14381370
    14391371/**
     
    14461378        malloc_string(g_boot_mountpt);
    14471379        malloc_string(g_mondo_home);
    1448         /*
    1449         malloc_string(g_tmpfs_mountpt);
    1450         */
    14511380        malloc_string(g_serial_string);
    14521381        malloc_string(g_magicdev_command);
     
    14541383        paranoid_free(g_boot_mountpt);
    14551384        paranoid_free(g_mondo_home);
    1456         /*
    1457         paranoid_free(g_tmpfs_mountpt);
    1458         */
    1459         paranoid_free(g_serial_string);
    14601385        paranoid_free(g_magicdev_command);
    14611386
    1462     }
    1463 
    1464     /*
    1465        char**list_of_arrays[] = {
    1466        &g_boot_mountpt,
    1467        &g_mondo_home,
    1468        &g_tmpfs_mountpt,
    1469        &g_serial_string,
    1470        &g_magicdev_command,
    1471        NULL};
    1472 
    1473        char**ppcurr;
    1474        int i;
    1475 
    1476        for(i=0;list_of_arrays[i];i++)
    1477        {
    1478        log_msg(5, "Allocating %d", i);
    1479        ppcurr = list_of_arrays[i];
    1480        if (mal)
    1481        { *ppcurr = malloc(MAX_STR_LEN); }
    1482        else
    1483        {
    1484        if (*ppcurr)
    1485        {
    1486        free(*ppcurr);
    1487        }
    1488        }
    1489        }
    1490        log_msg(5, "Returning");
    1491      */
     1387        mr_free(g_serial_string);
     1388    }
    14921389}
    14931390
     
    15181415void stop_magicdev_if_necessary()
    15191416{
    1520     strcpy(g_magicdev_command,
    1521            call_program_and_get_last_line_of_output
    1522            ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"));
     1417    strcpy(g_magicdev_command, call_program_and_get_last_line_of_output("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"));
    15231418    if (g_magicdev_command[0]) {
    15241419        log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
Note: See TracChangeset for help on using the changeset viewer.