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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.