Changeset 2326 in MondoRescue


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

r3337@localhost: bruno | 2009-08-11 20:02:18 +0200
bkpinfo->boot_device and bkpinfo->zip_exe are now dynamically allocated

Location:
branches/2.2.10/mondo/src
Files:
8 edited

Legend:

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

    r2325 r2326  
    616616    }
    617617
    618     if (!bkpinfo->nonbootable_backup
    619         && (bkpinfo->boot_loader == '\0'
    620             || bkpinfo->boot_device[0] == '\0')) {
     618    if (!bkpinfo->nonbootable_backup && (bkpinfo->boot_loader == '\0' || bkpinfo->boot_device == NULL)) {
    621619
    622620#ifdef __FreeBSD__
     
    660658            bkpinfo->boot_loader = ch;
    661659        }
    662         if (bkpinfo->boot_device[0] != '\0') {
     660        if (bkpinfo->boot_device != NULL) {
    663661            log_msg(2, "User specified boot device. It is '%s'.", bkpinfo->boot_device);
    664662        } else {
    665             strcpy(bkpinfo->boot_device, bootdev);
     663            mr_asprintf(bkpinfo->boot_device, "%s", bootdev);
    666664        }
    667665    }
  • branches/2.2.10/mondo/src/common/libmondo-cli.c

    r2325 r2326  
    13261326
    13271327    if (flag_set['f']) {
    1328         strncpy(bkpinfo->boot_device,
    1329                 resolve_softlinks_to_get_to_actual_device_file(flag_val
    1330                                                                ['f']),
    1331                 MAX_STR_LEN / 4);
     1328        mr_free(bkpinfo->boot_device);
     1329        mr_asprintf(bkpinfo->boot_device, "%s", resolve_softlinks_to_get_to_actual_device_file(flag_val['f']));
    13321330    }
    13331331
  • branches/2.2.10/mondo/src/common/libmondo-devices.c

    r2325 r2326  
    18231823    if (archiving_to_media) {
    18241824
     1825        mr_free(bkpinfo->boot_device);
    18251826#ifdef __FreeBSD__
    1826         strcpy(bkpinfo->boot_device,
    1827                call_program_and_get_last_line_of_output
    1828                ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
     1827#define EXAMPLEBD   "/dev/ad0"
     1828        mr_asprintf(bkpinfo->boot_device, "%s", call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
    18291829#else
    1830         strcpy(bkpinfo->boot_device,
    1831                call_program_and_get_last_line_of_output
    1832                ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
     1830#define EXAMPLEBD   "/dev/hda"
     1831        mr_asprintf(bkpinfo->boot_device, "%s", call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    18331832#endif
    18341833        i = which_boot_loader(bkpinfo->boot_device);
     
    18361835        {
    18371836
    1838 #ifdef __FreeBSD__
    1839             p = popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/ad0)", bkpinfo->boot_device);
    1840             if (!p == NULL) {
    1841                 log_to_screen("User has chosen not to backup the PC");
    1842                 finish(1);
    1843             }
    1844             strcpy(bkpinfo->boot_device, p);
    1845             mr_free(p);
    1846             i = which_boot_loader(bkpinfo->boot_device);
    1847 #else
    1848             p = popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/hda)", bkpinfo->boot_device);
     1837            p = popup_and_get_string("Boot device", "What is your boot device? (e.g. "EXAMPLEBD")", bkpinfo->boot_device);
     1838#undef EXAMPLEBD
    18491839            if (p == NULL) {
    18501840                log_to_screen("User has chosen not to backup the PC");
    18511841                finish(1);
    18521842            }
    1853             strcpy(bkpinfo->boot_device, p);
    1854             mr_free(p);
    1855 
     1843            mr_free(bkpinfo->boot_device);
     1844            bkpinfo->boot_device = p;
     1845#ifdef __FreeBSD__
     1846            i = which_boot_loader(bkpinfo->boot_device);
     1847#else
    18561848            if (does_string_exist_in_boot_block(bkpinfo->boot_device, "LILO")) {
    18571849                i = 'L';
     
    18671859#endif
    18681860            if (i == 'U') {
    1869                 if (ask_me_yes_or_no
    1870                     ("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?"))
    1871                 {
     1861                if (ask_me_yes_or_no("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?")) {
    18721862                    i = 'R';    // raw
    18731863                } else {
    1874                     log_to_screen
    1875                         ("I cannot find your boot loader. Please run mondoarchive with parameters.");
     1864                    log_to_screen("I cannot find your boot loader. Please run mondoarchive with parameters.");
    18761865                    finish(1);
    18771866                }
  • branches/2.2.10/mondo/src/common/libmondo-tools.c

    r2325 r2326  
    478478
    479479    if (bkpinfo->use_lzo) {
    480         strcpy(bkpinfo->zip_exe, "lzop");
     480        mr_asprintf(bkpinfo->zip_exe, "lzop");
    481481        strcpy(bkpinfo->zip_suffix, "lzo");
    482482    } else if (bkpinfo->use_gzip) {
    483         strcpy(bkpinfo->zip_exe, "gzip");
     483        mr_asprintf(bkpinfo->zip_exe, "gzip");
    484484        strcpy(bkpinfo->zip_suffix, "gz");
    485485    } else if (bkpinfo->compression_level != 0) {
    486         strcpy(bkpinfo->zip_exe, "bzip2");
     486        mr_asprintf(bkpinfo->zip_exe, "bzip2");
    487487        strcpy(bkpinfo->zip_suffix, "bz2");
    488     } else {
    489         bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
    490488    }
    491489
     
    798796
    799797    mr_free(bkpinfo->media_device);
     798    mr_free(bkpinfo->boot_device);
     799    mr_free(bkpinfo->zip_exe);
    800800    mr_free(bkpinfo->isodir);
    801801    mr_free(bkpinfo->prefix);
     
    827827    }
    828828    bkpinfo->boot_loader = '\0';
    829     bkpinfo->boot_device[0] = '\0';
    830     bkpinfo->zip_exe[0] = '\0';
     829    bkpinfo->boot_device = NULL;
     830    bkpinfo->zip_exe = NULL;
    831831    bkpinfo->zip_suffix[0] = '\0';
    832832    bkpinfo->image_devs[0] = '\0';
     
    12231223 * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it.
    12241224 */
    1225 void mount_boot_if_necessary()
    1226 {
     1225void mount_boot_if_necessary() {
    12271226    char *tmp = NULL;
    12281227    char *command = NULL;
     
    12381237
    12391238    log_msg(4, "tmp = '%s'", tmp);
    1240     if (tmp[0]) {
    1241         log_it("/boot is at %s according to /etc/fstab", tmp);
    1242         mr_asprintf(command, "mount | grep -Ew '/boot'");
    1243         mr_free(tmp);
    1244         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    1245         mr_free(command);
    1246 
    1247         if (!strcmp(tmp,"")) {
    1248             if ((strstr(tmp, "LABEL=") || strstr(tmp,"UUID="))) {
    1249                 if (!run_program_and_log_output("mount /boot", 5)) {
    1250                     strcpy(g_boot_mountpt, "/boot");
    1251                     log_msg(1, "Mounted /boot");
    1252                 } else {
    1253                     log_it("...ignored cos it's a label or uuid :-)");
     1239    log_it("/boot is at %s according to /etc/fstab", tmp);
     1240    mr_asprintf(command, "mount | grep -Ew '/boot'");
     1241    mr_free(tmp);
     1242    mr_asprintf(tmp, call_program_and_get_last_line_of_output(command));
     1243    mr_free(command);
     1244
     1245    if (!strcmp(tmp,"")) {
     1246        if ((strstr(tmp, "LABEL=") || strstr(tmp,"UUID="))) {
     1247            if (!run_program_and_log_output("mount /boot", 5)) {
     1248                strcpy(g_boot_mountpt, "/boot");
     1249                log_msg(1, "Mounted /boot");
     1250            } else {
     1251                log_it("...ignored cos it's a label or uuid :-)");
     1252            }
     1253        } else {
     1254            mr_asprintf(command, "mount | grep -E '^%s'", tmp);
     1255            log_msg(3, "command = %s", command);
     1256            if (run_program_and_log_output(command, 5)) {
     1257                strcpy(g_boot_mountpt, tmp);
     1258                mr_free(tmp);
     1259                log_it("%s (your /boot partition) is not mounted. I'll mount it before backing up", g_boot_mountpt);
     1260
     1261                mr_asprintf(tmp, "mount %s", g_boot_mountpt);
     1262                if (run_program_and_log_output(tmp, 5)) {
     1263                    g_boot_mountpt[0] = '\0';
     1264                    log_msg(1, "Plan B");
     1265                    if (!run_program_and_log_output("mount /boot", 5)) {
     1266                        strcpy(g_boot_mountpt, "/boot");
     1267                        log_msg(1, "Plan B worked");
     1268                    } else {
     1269                        log_msg(1,
     1270                            "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
     1271                    }
    12541272                }
    1255             } else {
    1256                 mr_asprintf(command, "mount | grep -E '^%s'", tmp);
    1257                 log_msg(3, "command = %s", command);
    1258                 if (run_program_and_log_output(command, 5)) {
    1259                     strcpy(g_boot_mountpt, tmp);
    1260                     mr_free(tmp);
    1261                     log_it("%s (your /boot partition) is not mounted. I'll mount it before backing up", g_boot_mountpt);
    1262 
    1263                     mr_asprintf(tmp, "mount %s", g_boot_mountpt);
    1264                     if (run_program_and_log_output(tmp, 5)) {
    1265                         g_boot_mountpt[0] = '\0';
    1266                         log_msg(1, "Plan B");
    1267                         if (!run_program_and_log_output("mount /boot", 5)) {
    1268                             strcpy(g_boot_mountpt, "/boot");
    1269                             log_msg(1, "Plan B worked");
    1270                         } else {
    1271                             log_msg(1,
    1272                                 "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
    1273                         }
    1274                     }
    1275                     mr_free(tmp);
    1276                 }
    1277                 mr_free(command);
    12781273            }
    1279         }
    1280     }
     1274            mr_free(command);
     1275        }
     1276    }
     1277    mr_free(tmp);
    12811278    log_msg(1, "Ended sub");
    12821279}
  • branches/2.2.10/mondo/src/common/libmondo-verify.c

    r2325 r2326  
    204204 * - @c restore_path
    205205 * - @c use_lzo
    206  * - @c zip_exe
    207206 * - @c zip_suffix
    208207 * @param mtpt The mountpoint the CD/DVD/ISO is mounted on.
     
    432431    mr_asprintf(outlog, "%s/afio.log", bkpinfo->tmpdir);
    433432    /* if programmer forgot to say which compression thingy to use then find out */
    434     if (strstr(tarball_fname, ".lzo")
    435         && strcmp(bkpinfo->zip_suffix, "lzo")) {
     433    if (strstr(tarball_fname, ".lzo") && strcmp(bkpinfo->zip_suffix, "lzo")) {
    436434        log_msg(2, "OK, I'm going to start using lzop.");
    437         strcpy(bkpinfo->zip_exe, "lzop");
     435        mr_free(bkpinfo->zip_exe);
     436        mr_asprintf(bkpinfo->zip_exe, "lzop");
    438437        strcpy(bkpinfo->zip_suffix, "lzo");
    439438        bkpinfo->use_lzo = TRUE;
    440439        bkpinfo->use_gzip = FALSE;
    441440    }
    442     if (strstr(tarball_fname, ".gz")
    443         && strcmp(bkpinfo->zip_suffix, "gz")) {
     441    if (strstr(tarball_fname, ".gz") && strcmp(bkpinfo->zip_suffix, "gz")) {
    444442        log_msg(2, "OK, I'm going to start using gzip.");
    445         strcpy(bkpinfo->zip_exe, "gzip");
     443        mr_free(bkpinfo->zip_exe);
     444        mr_asprintf(bkpinfo->zip_exe, "gzip");
    446445        strcpy(bkpinfo->zip_suffix, "gz");
    447446        bkpinfo->use_lzo = FALSE;
    448447        bkpinfo->use_gzip = TRUE;
    449448    }
    450     if (strstr(tarball_fname, ".bz2")
    451         && strcmp(bkpinfo->zip_suffix, "bz2")) {
     449    if (strstr(tarball_fname, ".bz2") && strcmp(bkpinfo->zip_suffix, "bz2")) {
    452450        log_msg(2, "OK, I'm going to start using bzip2.");
    453         strcpy(bkpinfo->zip_exe, "bzip2");
     451        mr_free(bkpinfo->zip_exe);
     452        mr_asprintf(bkpinfo->zip_exe, "bzip2");
    454453        strcpy(bkpinfo->zip_suffix, "bz2");
    455454        bkpinfo->use_lzo = FALSE;
     
    463462    } else {
    464463        bkpinfo->use_star = FALSE;
    465         mr_asprintf(command, "afio -r -P %s -Z %s >> %s 2>> %s", bkpinfo->zip_exe, tarball_fname, outlog, outlog);
     464        /* Here we suppose that there is always a compression program called */
     465        if (bkpinfo->zip_exe) {
     466            mr_asprintf(command, "afio -r -P %s -Z %s >> %s 2>> %s", bkpinfo->zip_exe, tarball_fname, outlog, outlog);
     467        } else {
     468            mr_asprintf(command, "afio -r -Z %s >> %s 2>> %s", tarball_fname, outlog, outlog);
     469        }
    466470    }
    467471    log_msg(6, "command=%s", command);
  • branches/2.2.10/mondo/src/common/mondostructures.h

    r2325 r2326  
    369369   * to take truncate_to_drive_name() of where_is_root_mounted().
    370370   */
    371     char boot_device[MAX_STR_LEN / 4];
     371    char *boot_device;
    372372
    373373  /**
     
    376376   * compression_level is 0.
    377377   */
    378     char zip_exe[MAX_STR_LEN / 4];
     378    char *zip_exe;
    379379
    380380  /**
  • branches/2.2.10/mondo/src/mondorestore/mondo-rstr-tools.c

    r2325 r2326  
    895895mr_free(value);
    896896
    897 bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
     897bkpinfo->zip_suffix[0] = '\0';
    898898value = read_cfg_var(cfg_file, "use-lzo");
    899899if (value && strstr(value, "yes")) {
    900900    bkpinfo->use_lzo = TRUE;
    901901    bkpinfo->use_gzip = FALSE;
    902     strcpy(bkpinfo->zip_exe, "lzop");
     902    mr_free(bkpinfo->zip_exe);
     903    mr_asprintf(bkpinfo->zip_exe, "lzop");
    903904    strcpy(bkpinfo->zip_suffix, "lzo");
    904905}
     
    909910    bkpinfo->use_lzo = FALSE;
    910911    bkpinfo->use_gzip = TRUE;
    911     strcpy(bkpinfo->zip_exe, "gzip");
     912    mr_free(bkpinfo->zip_exe);
     913    mr_asprintf(bkpinfo->zip_exe, "gzip");
    912914    strcpy(bkpinfo->zip_suffix, "gz");
    913915}
     
    918920    bkpinfo->use_lzo = FALSE;
    919921    bkpinfo->use_gzip = FALSE;
    920     strcpy(bkpinfo->zip_exe, "bzip2");
     922    mr_free(bkpinfo->zip_exe);
     923    mr_asprintf(bkpinfo->zip_exe, "bzip2");
    921924    strcpy(bkpinfo->zip_suffix, "bz2");
    922925}
  • branches/2.2.10/mondo/src/mondorestore/mondorestore.c

    r2325 r2326  
    14881488    }
    14891489
    1490     if (!bkpinfo->zip_exe[0]) {
     1490    if (bkpinfo->zip_exe == NULL) {
    14911491        mr_asprintf(command, "cat > \"%s\"", file_to_openout);
    14921492    } else {
     
    15491549    paranoid_pclose(pout);
    15501550
    1551     if (bkpinfo->zip_exe[0]) {
     1551    if (bkpinfo->zip_exe != NULL) {
    15521552        if (strcmp(bkpinfo->zip_exe, "gzip") == 0) {
    15531553            /* Re-enable SIGPIPE for gzip */
Note: See TracChangeset for help on using the changeset viewer.