Changeset 1156


Ignore:
Timestamp:
Feb 13, 2007, 2:04:40 AM (12 years ago)
Author:
bruno
Message:

Merge trunk for libmondo-devices.c finished (first pass)

Location:
branches/stable/mondo/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/libmondo-devices-EXT.h

    r1127 r1156  
    3333extern int interactively_obtain_media_parameters_from_user(struct s_bkpinfo
    3434                                                           *, bool);
    35 
    36 
    37 extern void make_fifo(char *store_name_here, char *stub);
    38 
    39 
    4035extern void insist_on_this_cd_number(struct s_bkpinfo *bkpinfo,
    4136                                     int cd_number_i_want);
     
    4742extern int eject_device(char *);
    4843
    49 extern char *list_of_NFS_devices_and_mounts();
    5044extern char *list_of_NFS_mounts_only(void);
    5145
  • branches/stable/mondo/src/common/libmondo-devices.c

    r1130 r1156  
    9393    log_it("rctada: Unmounting all CD drives", __LINE__);
    9494    run_program_and_log_output("umount /dev/cdr* /dev/dvd*", 5);
     95}
     96
     97
     98/**
     99 * Mount the CD-ROM at @p mountpoint.
     100 * @param device The device (or file if g_ISO_restore_mode) to mount.
     101 * @param mountpoint The place to mount it.
     102 * @return 0 for success, nonzero for failure.
     103 */
     104int mount_CDROM_here(char *device, char *mountpoint)
     105{
     106    /*@ buffer ****************************************************** */
     107    char *command = NULL;
     108    char *dev;
     109    int retval = 0;
     110
     111    malloc_string(dev);
     112    assert_string_is_neither_NULL_nor_zerolength(device);
     113    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
     114
     115    make_hole_for_dir(mountpoint);
     116    if (isdigit(device[0])) {
     117        find_cdrom_device(device, FALSE);
     118    } else {
     119        strcpy(dev, device);
     120    }
     121    if (g_ISO_restore_mode) {
     122
     123#ifdef __FreeBSD__
     124        strcpy(dev, make_vn(device));
     125        if (!dev) {
     126            sprintf(command, "Unable to mount ISO (make_vn(%s) failed)",
     127                    device);
     128            fatal_error(command);
     129        }
     130        strcpy(device, dev);
     131#endif
     132    }
     133
     134    mr_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device,
     135            mountpoint);
     136    /*@ end vars *************************************************** */
     137
     138#ifdef __FreeBSD__
     139    mr_asprintf(&command, "mount_cd9660 -r %s %s 2>> %s",
     140            device, mountpoint, MONDO_LOGFILE);
     141#else
     142    mr_asprintf(&command, "mount %s -o ro,loop -t iso9660 %s 2>> %s",
     143            device, mountpoint, MONDO_LOGFILE);
     144#endif
     145
     146    mr_msg(4, command);
     147    if (strncmp(device, "/dev/", 5) == 0) {
     148        retract_CD_tray_and_defeat_autorun();
     149    }
     150    retval = system(command);
     151    mr_msg(1, "system(%s) returned %d", command, retval);
     152    mr_free(command);
     153
     154    mr_free(dev);
     155    return (retval);
    95156}
    96157
     
    12491310
    12501311/**
    1251  * Mount the CD-ROM at @p mountpoint.
    1252  * @param device The device (or file if g_ISO_restore_mode) to mount.
    1253  * @param mountpoint The place to mount it.
    1254  * @return 0 for success, nonzero for failure.
    1255  */
    1256 int mount_CDROM_here(char *device, char *mountpoint)
    1257 {
    1258     /*@ buffer ****************************************************** */
    1259     char *command;
    1260     char *dev;
    1261     char *options;
    1262     int retval;
    1263 
    1264     malloc_string(command);
    1265     malloc_string(dev);
    1266     malloc_string(options);
    1267     assert_string_is_neither_NULL_nor_zerolength(device);
    1268     assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    1269 
    1270     make_hole_for_dir(mountpoint);
    1271     strcpy(options, "ro");
    1272     if (isdigit(device[0])) {
    1273         find_cdrom_device(device, FALSE);
    1274     } else {
    1275         strcpy(dev, device);
    1276     }
    1277     if (g_ISO_restore_mode) {
    1278 
    1279 #ifdef __FreeBSD__
    1280         strcpy(dev, make_vn(device));
    1281         if (!dev) {
    1282             sprintf(command, "Unable to mount ISO (make_vn(%s) failed)",
    1283                     device);
    1284             fatal_error(command);
    1285         }
    1286         strcpy(device, dev);
    1287 #else
    1288         strcat(options, ",loop");
    1289 #endif
    1290 
    1291     }
    1292     mr_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device,
    1293             mountpoint);
    1294     /*@ end vars *************************************************** */
    1295 
    1296 #ifdef __FreeBSD__
    1297     sprintf(command, "mount_cd9660 -r %s %s 2>> %s",
    1298             device, mountpoint, MONDO_LOGFILE);
    1299 
    1300 #else
    1301     sprintf(command, "mount %s -o %s -t iso9660 %s 2>> %s",
    1302             device, options, mountpoint, MONDO_LOGFILE);
    1303 #endif
    1304 
    1305     mr_msg(4, command);
    1306     if (strncmp(device, "/dev/", 5) == 0) {
    1307         retract_CD_tray_and_defeat_autorun();
    1308     }
    1309     retval = system(command);
    1310     mr_msg(1, "system(%s) returned %d", command, retval);
    1311 
    1312     mr_free(command);
    1313     mr_free(dev);
    1314     mr_free(options);
    1315     return (retval);
    1316 }
    1317 
    1318 
    1319 /**
    13201312 * Ask the user for CD number @p cd_number_i_want.
    13211313 * Sets g_current_media_number once the correct CD is inserted.
     
    20252017
    20262018/**
    2027  * @addtogroup utilityGroup
    2028  * @{
    2029  */
    2030 /**
    2031  * Get a space-separated list of NFS devices and mounts.
    2032  * @return The list created.
    2033  * @note The return value points to static data that will be overwritten with each call.
    2034  */
    2035 char *list_of_NFS_devices_and_mounts(void)
    2036 {
    2037     char *exclude_these_devices;
    2038     char *exclude_these_directories;
    2039     static char result_sz[512];
    2040 
    2041     malloc_string(exclude_these_devices);
    2042     malloc_string(exclude_these_directories);
    2043     strcpy(exclude_these_directories,
    2044            call_program_and_get_last_line_of_output
    2045            ("mount -t coda,ncpfs,nfs,smbfs,cifs,afs,mvfs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
    2046     strcpy(exclude_these_devices,
    2047            call_program_and_get_last_line_of_output
    2048            ("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|nfs|smbfs|cifs|mvfs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
    2049     sprintf(result_sz, "%s %s", exclude_these_directories,
    2050             exclude_these_devices);
    2051     mr_free(exclude_these_devices);
    2052     mr_free(exclude_these_directories);
    2053     return (result_sz);
    2054 }
    2055 
    2056 
    2057 /**
    20582019 * Get a space-separated list of NFS mounts.
    20592020 * @return The list created.
     
    20842045
    20852046/**
    2086  * Create a randomly-named FIFO. The format is @p stub "." [random] [random] where
    2087  * [random] is a random number between 1 and 32767.
    2088  * @param store_name_here Where to store the new filename.
    2089  * @param stub A random number will be appended to this to make the FIFO's name.
    2090  * @ingroup deviceGroup
    2091  */
    2092 void make_fifo(char *store_name_here, char *stub)
    2093 {
    2094     char *tmp;
    2095 
    2096     malloc_string(tmp);
    2097     assert_string_is_neither_NULL_nor_zerolength(stub);
    2098 
    2099     sprintf(store_name_here, "%s%d%d", stub, (int) (random() % 32768),
    2100             (int) (random() % 32768));
    2101     make_hole_for_file(store_name_here);
    2102     mkfifo(store_name_here, S_IRWXU | S_IRWXG);
    2103     sprintf(tmp, "chmod 770 %s", store_name_here);
    2104     paranoid_system(tmp);
    2105     mr_free(tmp);
    2106 }
    2107 
    2108 
    2109 /**
    21102047 * Set the tmpdir and scratchdir to reside on the partition with the most free space.
    21112048 * Automatically excludes DOS, NTFS, SMB, and NFS filesystems.
     
    21152052void sensibly_set_tmpdir_and_scratchdir(struct s_bkpinfo *bkpinfo)
    21162053{
    2117     char *tmp, *command, *sz;
    2118 
    2119     malloc_string(tmp);
     2054    char *tmp = NULL;
     2055    char *command = NULL;
     2056    char *sz = NULL;
     2057    int i = 0;
     2058
    21202059    malloc_string(command);
    2121     malloc_string(sz);
    21222060    assert(bkpinfo != NULL);
    21232061
    21242062#ifdef __FreeBSD__
    2125     strcpy(tmp,
     2063    mr_asprintf(&tmp,
    21262064           call_program_and_get_last_line_of_output
    21272065           ("df -m -P -t nonfs,msdosfs,ntfs,smbfs,smb,cifs,afs,mvfs | tr -s '\t' ' ' | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
    21282066#else
    2129     strcpy(tmp,
     2067    mr_asprintf(&tmp,
    21302068           call_program_and_get_last_line_of_output
    21312069           ("df -m -P -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs -x afs -x mvfs | sed 's/                  /devdev/' | tr -s '\t' ' ' | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
     
    21332071
    21342072    if (tmp[0] != '/') {
    2135         strcpy(sz, tmp);
    2136         strcpy(tmp, "/");
    2137         strcat(tmp, sz);
     2073        mr_asprintf(&sz, "/%s", tmp);
     2074        mr_free(tmp);
     2075        tmp = sz;
    21382076    }
    21392077    if (!tmp[0]) {
    21402078        fatal_error("I couldn't figure out the tempdir!");
    21412079    }
    2142     sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp,
    2143             (int) (random() % 32768));
     2080    i = (int) (random() % 32768);
     2081    sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp, i);
    21442082    log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir);
    21452083
    2146     sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp,
    2147             (int) (random() % 32768));
     2084    sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, i);
    21482085    log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
    21492086
     
    21512088            bkpinfo->scratchdir);
    21522089
    2153     sprintf(command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);
     2090    mr_asprintf(&command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);
     2091    mr_free(tmp);
     2092
    21542093    paranoid_system(command);
    2155     mr_free(tmp);
    21562094    mr_free(command);
    2157     mr_free(sz);
    21582095}
    21592096
     
    21722109bool set_dev_to_this_if_rx_OK(char *output, char *dev)
    21732110{
    2174     char *command;
    2175 
    2176     malloc_string(command);
     2111    char *command = NULL;
     2112
    21772113    if (!dev || dev[0] == '\0') {
    21782114        output[0] = '\0';
    21792115        return (FALSE);
    21802116    }
    2181 //  assert_string_is_neither_NULL_nor_zerolength(dev);
    21822117    mr_msg(10, "Injecting %s", dev);
    21832118    inject_device(dev);
     
    21862121        return (FALSE);
    21872122    }
    2188     sprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null",
     2123    mr_asprintf(&command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null",
    21892124            512L, dev);
    21902125    if (!run_program_and_log_output(command, FALSE)
     
    21922127        strcpy(output, dev);
    21932128        mr_msg(4, "Found it - %s", dev);
     2129        mr_free(command);
    21942130        return (TRUE);
    21952131    } else {
    21962132        output[0] = '\0';
    21972133        mr_msg(4, "It's not %s", dev);
     2134        mr_free(command);
    21982135        return (FALSE);
    21992136    }
     
    22112148{
    22122149    int cd_number = -1;
    2213     char *mountdev;
    2214     char *tmp;
    2215 
    2216     malloc_string(mountdev);
    2217     malloc_string(tmp);
     2150    char *mountdev = NULL;
     2151    char *tmp = NULL;
     2152    char *tmp1 = NULL;
     2153
    22182154    assert(bkpinfo != NULL);
    2219 //  log_it("Asking what_number_cd_is_this");
    22202155    if (g_ISO_restore_mode) {
    2221         sprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'");
    2222 //      log_it("tmp = %s", tmp);
    2223 
    2224         strcpy(mountdev, call_program_and_get_last_line_of_output(tmp));
    2225         strcat(mountdev, "/archives/THIS-CD-NUMBER");
    2226 //      log_it("mountdev = %s", mountdev);
     2156        mr_asprintf(&tmp, "mount | grep iso9660 | awk '{print $3;}'");
     2157
     2158        mr_asprintf(&mountdev, "%s/archives/THIS-CD-NUMBER", call_program_and_get_last_line_of_output(tmp));
    22272159        cd_number = atoi(last_line_of_file(mountdev));
    2228 //      log_it("cd_number = %d", cd_number);
    22292160        mr_free(mountdev);
    22302161        mr_free(tmp);
     
    22322163    }
    22332164
    2234     strcpy(mountdev, bkpinfo->media_device);
     2165    mr_asprintf(&mountdev, bkpinfo->media_device);
    22352166    if (!mountdev[0]) {
    22362167        log_it
     
    22432174    cd_number =
    22442175        atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"));
    2245 //  log_it("cd_number..later.. = %d", cd_number);
    22462176    mr_free(mountdev);
    2247     mr_free(tmp);
    22482177    return (cd_number);
    22492178}
     
    24992428    char *command = NULL;
    25002429    char *fdisk = NULL;
    2501 #ifdef __IA64__
    2502     struct stat buf;
    2503 #endif
    2504     malloc_string(tmp);
     2430
    25052431    mr_msg(0, "Looking for partition table format type");
    25062432    mr_asprintf(&fdisk, "/sbin/parted2fdisk");
     
    25092435    mr_free(fdisk);
    25102436
    2511     strcpy(tmp, call_program_and_get_last_line_of_output(command));
     2437    mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command));
    25122438    mr_free(command);
    25132439
     
    25172443        strcpy(output, "GPT");
    25182444    }
     2445    mr_free(tmp);
    25192446    mr_msg(0, "Found %s partition table format type", output);
    2520     mr_free(tmp);
    25212447    return(output);
    25222448}
  • branches/stable/mondo/src/common/libmondo-devices.h

    r1101 r1156  
    3131                                                    bool);
    3232
    33 
    34 
    35 void make_fifo(char *store_name_here, char *stub);
    36 
    3733void insist_on_this_cd_number(struct s_bkpinfo *bkpinfo,
    3834                              int cd_number_i_want);
     
    4238int eject_device(char *);
    4339
    44 char *list_of_NFS_devices_and_mounts(void);
    4540char *list_of_NFS_mounts_only(void);
    4641
  • branches/stable/mondo/src/lib/mr_mem.c

    r1152 r1156  
    103103        mr_exit(-1, "Unable to affect a NULL variable");
    104104    }
    105     if (mr_setenv(name, value, 1) != 0) {
     105    if (setenv(name, value, 1) != 0) {
    106106        mr_msg_int(1,line,file,"Unable to put %s in environment", name);
    107107        mr_exit(-1,"Unable to put in environment");
  • branches/stable/mondo/src/mondoarchive/mondo-cli.c

    r1149 r1156  
    587587    if (flag_set['N'])          // exclude NFS mounts & devices
    588588    {
    589 //      strncpy(psz, list_of_NFS_devices_and_mounts(), MAX_STR_LEN);
    590589        strncpy(psz, list_of_NFS_mounts_only(), MAX_STR_LEN);
    591590        if (bkpinfo->exclude_paths[0]) {
Note: See TracChangeset for help on using the changeset viewer.