Ignore:
Timestamp:
Sep 25, 2013, 9:03:25 AM (11 years ago)
Author:
Bruno Cornec
Message:
  • revert r3188 & r3189 as I started to work on branch 3.0 before deciding it was much better to do it in 3.2. This will allow some small maintenance work on 3.0 if needed, while pushing all the rest to 3.2 and providing early access to it.
File:
1 edited

Legend:

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

    r3188 r3192  
    3030
    3131extern int g_tape_buffer_size_MB;
     32extern char *g_serial_string;
    3233extern bool g_text_mode;
    3334extern int g_currentY;
    3435extern int g_current_media_number;
    3536extern char *MONDO_LOGFILE;
    36 extern char *g_serial_string;
    3737
    3838/* Reference to global bkpinfo */
     
    113113        return;
    114114    }
     115#ifndef _XWIN
    115116    if (!g_text_mode)
    116117        newtSuspend();
     118#endif
    117119    printf("ASSERTION FAILED: `%s'\n", exp);
    118120    printf("\tat %s:%d in %s\n\n", file, line, function);
     
    161163    getchar();                  // skip \n
    162164
     165#ifndef _XWIN
    163166    if (!g_text_mode)
    164167        newtResume();
     168#endif
    165169}
    166170
     
    171175void clean_up_KDE_desktop_if_necessary(void)
    172176{
    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");
     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 \
     182file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \
     183awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \
     184else { print $0;};}' $file.old  > $file ; fi ; done");
    176185    run_program_and_log_output(tmp, 5);
    177     mr_free(tmp);
     186    paranoid_free(tmp);
    178187}
    179188
     
    223232double get_kernel_version(void)
    224233{
    225     char *p = NULL;
    226     char *tmp = NULL;
     234    char *p, tmp[200];
    227235    double d;
    228236#ifdef __FreeBSD__
     
    230238    d = 5.2;                    // :-)
    231239#else
    232     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("uname -r"));
     240    strcpy(tmp, call_program_and_get_last_line_of_output("uname -r"));
    233241    p = strchr(tmp, '.');
    234242    if (p) {
     
    241249        }
    242250    }
     251//  log_msg(1, "tmp = '%s'", tmp);
    243252    d = atof(tmp);
    244     mr_free(tmp);
    245253#endif
    246254    log_msg(1, "g_kernel_version = %f", d);
     
    249257
    250258
     259
     260
     261
    251262/**
    252263 * Get the current time.
     
    257268    return (long) time((void *) 0);
    258269}
     270
     271
     272
     273
     274
    259275
    260276
     
    352368    char *mondo_mkisofs_sz = NULL;
    353369    char *command = NULL;
    354     char *hostname = NULL;
     370    char *mtpt;
     371    char *hostname;
    355372    char *isofs_cmd = NULL;
    356373    char *ip_address = NULL;
    357374    int retval = 0;
    358375    char *colon;
    359     char *cdr_exe = NULL;
     376    char *cdr_exe;
    360377    char *tmp = NULL;
    361     char *p = NULL;
    362     char *call_before_iso_user = NULL;
     378    char call_before_iso_user[MAX_STR_LEN] = "\0";
     379    /*
     380    long avm = 0;
     381    int rdsiz_MB;
     382    */
    363383    char *iso_dev = NULL;
    364384    char *iso_mnt = NULL;
     
    367387
    368388    assert(bkpinfo != NULL);
    369 
     389    malloc_string(mtpt);
     390    malloc_string(hostname);
     391    malloc_string(cdr_exe);
    370392    bkpinfo->optimal_set_size =
    371393        (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) *
     
    378400        }
    379401        log_msg(1, "Tape");
    380         if (bkpinfo->media_device == NULL) {
    381             return(1);
    382         }
    383402        mr_asprintf(tmp, "mt -f %s status", bkpinfo->media_device);
    384403        log_msg(1, "tmp = '%s'", tmp);
     
    410429        strcpy(bkpinfo->zip_exe, "gzip");
    411430        strcpy(bkpinfo->zip_suffix, "gz");
    412     } else if (bkpinfo->use_lzma) {
    413         strcpy(bkpinfo->zip_exe, "lzma");
    414         strcpy(bkpinfo->zip_suffix, "lzma");
    415431    } else if (bkpinfo->compression_level != 0) {
    416432        strcpy(bkpinfo->zip_exe, "bzip2");
     
    424440    if (bkpinfo->backup_media_type == dvd) {
    425441        if (find_home_of_exe("growisofs")) {
    426             mr_asprintf(cdr_exe, "growisofs");
     442            strcpy(cdr_exe, "growisofs");
    427443        }                       // unlikely to be used
    428444        else {
     
    446462    }
    447463#endif
    448         else {
     464        else
     465        {
    449466            mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
    450467        }
    451468        if (bkpinfo->manual_cd_tray) {
     469            paranoid_free(mondo_mkisofs_sz);
    452470            fatal_error("Manual CD tray + DVD not supported yet.");
    453471            // -m isn't supported by growisofs, BTW...
     
    457475                    mondo_mkisofs_sz,
    458476                    "", bkpinfo->media_device);
    459         }
    460         mr_free(mondo_mkisofs_sz);
     477            paranoid_free(mondo_mkisofs_sz);
     478        }
    461479        if (getenv ("SUDO_COMMAND")) {
    462480            mr_asprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND");
     
    468486            mr_free(command);
    469487        }
    470         log_msg(2, "call_make_iso (DVD res) is ... %s", bkpinfo->call_make_iso);
     488        log_msg(2, "call_make_iso (DVD res) is ... %s",
     489                bkpinfo->call_make_iso);
    471490    }                           // end of DVD code
    472491
     
    485504        }
    486505        if (find_home_of_exe("cdrecord")) {
    487             mr_asprintf(cdr_exe, "cdrecord");
     506            strcpy(cdr_exe, "cdrecord");
    488507        } else if (find_home_of_exe("dvdrecord")) {
    489             mr_asprintf(cdr_exe, "dvdrecord");
     508            strcpy(cdr_exe, "dvdrecord");
    490509        } else {
    491510            fatal_error("Please install either cdrecord or dvdrecord.");
     
    525544                        mondo_mkisofs_sz, bkpinfo->tmpdir);
    526545                } else {
    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);
     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);
    530550            }
    531551            log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso);
    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);
     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);
    533557        } else {
    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);
     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);
    539567    }                           // end of CD code
    540568
     
    549577
    550578        log_it("isodir = %s", bkpinfo->isodir);
    551         mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1", bkpinfo->isodir);
     579        mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1",
     580                bkpinfo->isodir);
    552581        log_it("command = %s", command);
     582        log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    553583        mr_asprintf(iso_dev, "%s", call_program_and_get_last_line_of_output(command));
    554         log_it("res of it = %s", iso_dev);
    555584        mr_asprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
    556         write_one_liner_data_file(tmp, iso_dev);
     585        write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
    557586        mr_free(tmp);
    558587        mr_free(command);
     
    562591
    563592        log_it("command = %s", command);
     593        log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    564594        mr_asprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command));
    565         log_it("res of it = %s", iso_mnt);
    566595        mr_asprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
    567         write_one_liner_data_file(tmp, iso_mnt);
     596        write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
    568597        mr_free(tmp);
    569598        mr_free(command);
     
    583612            }
    584613        }
     614        mr_free(iso_tmp);
    585615        mr_free(iso_mnt);
    586         mr_free(iso_tmp);
    587616
    588617        mr_asprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir);
     
    603632
    604633    if (bkpinfo->backup_media_type == netfs) {
    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         }
     634        strcpy(hostname, bkpinfo->netfs_mount);
    612635        colon = strchr(hostname, ':');
    613636        if (!colon) {
     
    628651            }
    629652            if (!hent) {
    630                 log_it("Can't resolve Network mount (%s): %s", hostname, hstrerror(h_errno));
     653                log_it("Can't resolve Network mount (%s): %s", hostname,
     654                       hstrerror(h_errno));
    631655                retval++;
    632656            } else {
     
    634658                mr_strcat(ip_address, strchr(bkpinfo->netfs_mount, ':'));
    635659                strcpy(bkpinfo->netfs_mount, ip_address);
    636                 mr_free(ip_address);
     660                paranoid_free(ip_address);
    637661            }
    638662        }
    639         mr_free(hostname);
    640663        store_netfs_config();
    641664    }
     
    645668        fprintf(stderr, "Type 'man mondoarchive' for help.\n");
    646669    }
    647     if (bkpinfo->include_paths == NULL) {
    648         mr_asprintf(bkpinfo->include_paths, "/");
    649     }
     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);
    650679    g_backup_media_type = bkpinfo->backup_media_type;
     680    paranoid_free(mtpt);
     681    paranoid_free(hostname);
     682    paranoid_free(cdr_exe);
    651683    return (retval);
    652684}
     
    672704    if (bkpinfo->disaster_recovery) {
    673705        if (!does_nonMS_partition_exist()) {
    674             fatal_error("I am in disaster recovery mode\nPlease don't run mondoarchive.");
     706            fatal_error
     707                ("I am in disaster recovery mode\nPlease don't run mondoarchive.");
    675708        }
    676709    }
     
    680713    paranoid_free(tmp);
    681714    if (find_and_store_mondoarchives_home(g_mondo_home)) {
    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");
     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");
    683717        res++;
    684718        return (res);
     
    689723    }
    690724    g_current_media_number = 1;
    691     bkpinfo->postnuke_tarball[0] = '\0';
     725    bkpinfo->postnuke_tarball[0] = bkpinfo->netfs_mount[0] = '\0';
    692726    return (res);
    693727}
     
    738772    if (p == NULL) {
    739773        log_it("Failed to create global tmp directory %s for Mondo.",tmp);
    740         mr_free(tmp);
    741774        finish(-1);
    742775    }
    743     mr_free(tmp);
    744 
    745776    strcpy(bkpinfo->tmpdir,p);
    746     log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir);
     777    paranoid_free(tmp);
    747778
    748779    mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
     
    786817    }
    787818    strcpy(bkpinfo->scratchdir,p);
    788     log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
    789819    paranoid_free(tmp);
    790820
     
    802832{
    803833    int i;
    804     log_msg(1, "Initializing bkpinfo");
    805 
     834
     835    log_msg(1, "Hi");
    806836    assert(bkpinfo != NULL);
    807837    memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo));
     
    817847    bkpinfo->use_lzo = FALSE;
    818848    bkpinfo->use_gzip = FALSE;
    819     bkpinfo->use_lzma = FALSE;
     849    bkpinfo->do_not_compress_these[0] = '\0';
    820850    bkpinfo->verify_data = FALSE;
    821851    bkpinfo->backup_data = FALSE;
     
    823853    bkpinfo->use_star = FALSE;
    824854    bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
    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();
     855    bkpinfo->disaster_recovery =
     856        (am_I_in_disaster_recovery_mode()? TRUE : FALSE);
    832857    if (bkpinfo->disaster_recovery) {
    833858        strcpy(bkpinfo->isodir, "/");
     
    836861    }
    837862    strcpy(bkpinfo->prefix, STD_PREFIX);
     863    setup_tmpdir(NULL);
     864    setup_scratchdir(NULL);
     865
    838866    bkpinfo->optimal_set_size = 0;
    839     bkpinfo->backup_media_type = none;
     867    strcpy(bkpinfo->include_paths, "/");
    840868    bkpinfo->make_filelist = TRUE;  // unless -J supplied to mondoarchive
    841     bkpinfo->exclude_paths = NULL;
    842     bkpinfo->include_paths = NULL;
     869    bkpinfo->include_paths[0] = '\0';
    843870    bkpinfo->exclude_devs = NULL;
    844871    bkpinfo->restore_path[0] = '\0';
     
    852879    bkpinfo->netfs_user = NULL;
    853880    bkpinfo->netfs_remote_dir[0] = '\0';
     881    bkpinfo->exclude_paths = NULL;
     882    bkpinfo->subdir = NULL;
    854883    bkpinfo->postnuke_tarball[0] = '\0';
    855     bkpinfo->subdir = NULL;
    856884    bkpinfo->wipe_media_first = FALSE;
    857885    bkpinfo->differential = 0;
     
    866894
    867895
     896
     897
    868898/**
    869899 * Get the remaining free space (in MB) on @p partition.
     
    886916    mr_free(command);
    887917
    888     mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", partition);
     918    mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
     919            partition);
    889920    mr_asprintf(out_sz, "%s", call_program_and_get_last_line_of_output(command));
    890921    mr_free(command);
     
    926957    if (system("which mkfs.vfat 2> /dev/null 1> /dev/null")
    927958        && !system("which mkfs.msdos 2> /dev/null 1> /dev/null")) {
    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"));
     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"));
    932967    if (atol(tmp) < 35000) {
    933968        retval++;
     
    935970    }
    936971    if (atol(tmp) < 66000) {
    937         log_to_screen("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
     972        log_to_screen
     973            ("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
    938974    }
    939975    mr_free(tmp);
     
    9901026        whine_if_not_found("cmp");
    9911027    }
    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)\""));
     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)\""));
    9941033    if (strcmp("", tmp)) {
    9951034        if (strstr(tmp, "autofs")) {
     
    10651104    /*@ buffer ****************************************************** */
    10661105    char *command = NULL;
     1106    char *tmp = NULL;
    10671107
    10681108    /*@ end vars *************************************************** */
     
    10711111    assert_string_is_neither_NULL_nor_zerolength(label);
    10721112    if (!does_file_exist(config_file)) {
    1073         log_to_screen("(read_cfg_var) Cannot find %s config file", 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
    10741118        value[0] = '\0';
    10751119        return (1);
     
    10831127        mr_free(command);
    10841128
    1085         log_msg(4, "Configuration item %s is %s", label, value);
    10861129        if (strlen(value) == 0) {
    10871130            return (1);
     
    11991242 * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it.
    12001243 */
    1201 void mount_boot_if_necessary() {
     1244void mount_boot_if_necessary()
     1245{
    12021246    char *tmp = NULL;
    12031247    char *command = NULL;
     
    12071251    g_boot_mountpt[0] = '\0';
    12081252    log_msg(4, "Done. Great. Seeting command to something");
    1209     mr_asprintf(command, "%s", "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[   ]/boot[     ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
     1253    mr_asprintf(command, "%s",
     1254           "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[   ]/boot[     ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
    12101255    log_msg(4, "Cool. Command = '%s'", command);
    12111256    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     
    12131258
    12141259    log_msg(4, "tmp = '%s'", tmp);
    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");
     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 :-)");
     1274                }
    12271275            } else {
    1228                 log_it("...ignored cos it's a label or uuid :-)");
     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);
    12291302            }
    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                     }
    1249                 }
    1250             }
    1251             mr_free(command);
    1252         }
    1253     }
    1254     mr_free(tmp);
     1303        }
     1304    }
    12551305    log_msg(1, "Ended sub");
    12561306}
     
    12901340    char *command = NULL;
    12911341    char *tempfile = NULL;
     1342    char *tmp = NULL;
    12921343
    12931344
     
    12971348    assert(value != NULL);
    12981349    if (!does_file_exist(config_file)) {
    1299         log_to_screen("(write_cfg_file) Cannot find %s config file", 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);
    13001354        return (1);
    13011355    }
    13021356    mr_asprintf(tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir);
    13031357    if (does_file_exist(config_file)) {
    1304         mr_asprintf(command, "grep -vE '^%s .*$' %s > %s", label, config_file, tempfile);
     1358        mr_asprintf(command, "grep -vE '^%s .*$' %s > %s",
     1359                label, config_file, tempfile);
    13051360        paranoid_system(command);
    13061361        mr_free(command);
     
    13231378 * information to the logfile.
    13241379 */
    1325 void standard_log_debug_msg(int debug_level, const char *szFile, const char *szFunction, int nLine, const char *fmt, ...) {
    1326 
     1380void standard_log_debug_msg(int debug_level, const char *szFile,
     1381                            const char *szFunction, int nLine,
     1382                            const char *fmt, ...)
     1383{
    13271384    va_list args;
     1385    int i;
    13281386    static int depth = 0;
    13291387    FILE *fout;
     
    13381396        if (!(fout = fopen(MONDO_LOGFILE, "a"))) {
    13391397            return;
    1340         }
     1398        }       // fatal_error("Failed to openout to logfile - sheesh..."); }
    13411399
    13421400        // add tabs to distinguish log levels
    13431401        if (debug_level > 0) {
    1344             fprintf(fout, "DBG%d: ", debug_level);
     1402            for (i = 1; i < debug_level; i++)
     1403                fprintf(fout, "\t");
    13451404            if (getpid() == g_main_pid)
    13461405                fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction, nLine);
     
    13491408            else
    13501409                fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile, szFunction, nLine);
    1351         } else {
    1352             fprintf(fout, "INFO: ");
    13531410        }
    13541411        va_start(args, fmt);
     
    13561413        va_end(args);
    13571414
     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
    13581420        fprintf(fout, "\n");
    13591421        paranoid_fclose(fout);
     
    13681430                       ...) = standard_log_debug_msg;
    13691431
     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);} }
    13701438
    13711439/**
     
    13781446        malloc_string(g_boot_mountpt);
    13791447        malloc_string(g_mondo_home);
     1448        /*
     1449        malloc_string(g_tmpfs_mountpt);
     1450        */
    13801451        malloc_string(g_serial_string);
    13811452        malloc_string(g_magicdev_command);
     
    13831454        paranoid_free(g_boot_mountpt);
    13841455        paranoid_free(g_mondo_home);
     1456        /*
     1457        paranoid_free(g_tmpfs_mountpt);
     1458        */
     1459        paranoid_free(g_serial_string);
    13851460        paranoid_free(g_magicdev_command);
    13861461
    1387         mr_free(g_serial_string);
    1388     }
     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     */
    13891492}
    13901493
     
    14151518void stop_magicdev_if_necessary()
    14161519{
    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"));
     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"));
    14181523    if (g_magicdev_command[0]) {
    14191524        log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
Note: See TracChangeset for help on using the changeset viewer.