Ejemplo n.º 1
0
void
start_httpd()
{
	/*
	 * the first two NULLs are place holders for the 'nextServer' info
	 */
	char	*args[] = { "/lighttpd/sbin/lighttpd", 
				"-f", "/lighttpd/conf/lighttpd.conf",
				"-D", NULL };
	int	pid;
	int	i;
	struct device	**devs;

	/*
	 * try to mount the CD
	 */
	devs = probeDevices(CLASS_CDROM, BUS_UNSPEC, 0);
	if (devs) {
		for (i = 0; devs[i]; i++) {
			if (!devs[i]->device) {
				continue;
			}

			devMakeInode(devs[i]->device, "/tmp/rocks-cdrom");

			logMessage(INFO,
				"start_httpd:trying to mount device %s",
				devs[i]->device);
			if (doPwMount("/tmp/rocks-cdrom", "/mnt/cdrom",
				"iso9660", IMOUNT_RDONLY, NULL)) {

				logMessage(ERROR,
					"start_httpd:doPwMount failed\n");
			} else {
				/*
				 * if there are multiple CD drives, exit this
				 * loop after the first successful mount
				 */ 
				break;
			}
		}
	}

	/*
	 * start the service
	 */
	pid = fork();
	if (pid != 0) {
#ifdef	LATER
		/*
		 * don't close stdin or stdout. this causes problems
		 * with mini_httpd as it uses these file descriptors for
		 * it's CGI processing
		 */
		close(2);
#endif
		execv(args[0], args);
		logMessage(ERROR, "start_httpd:lighttpd failed\n");
	}
}
Ejemplo n.º 2
0
bool
GtkOvgGlue::init(int /*argc*/, char ** /*argv*/[])
{
    GNASH_REPORT_FUNCTION;
    
    bool egl = false;
    bool rawfb = false;
    bool dfb = false;
    bool x11 = false;
    
    // Probe to see what display devices we have that could be used.
    boost::shared_array<renderer::GnashDevice::dtype_t> devs = probeDevices();
    if (devs) {
        int i = 0;
        while (devs[i] != renderer::GnashDevice::NODEV) {
            switch (devs[i++]) {
              case renderer::GnashDevice::EGL:
                  log_debug(_("Probing found an EGL display device"));
                  egl = true;
                  break;
              case renderer::GnashDevice::RAWFB:
                  log_debug(_("Probing found a raw Framebuffer display device"));
                  rawfb = true;
                  break;
              case renderer::GnashDevice::X11:
                  log_debug(_("Probing found an X11 display device"));
                  x11 = true;
                  break;
              case renderer::GnashDevice::DIRECTFB:
                  log_debug(_("Probing found a DirectFB display device"));
                  dfb = true;
                  break;
              case renderer::GnashDevice::NODEV:
              default:
                  log_error(_("No display devices found by probing!"));
                  break;
            }
        }

        // Now that we know what exists, we have to decide which one to
        // use, as OpenVG can work with anything. We can only have one
        // display device operating at a time.
        if (egl) {
            setDevice(renderer::GnashDevice::EGL);
        } else if (rawfb) {
            setDevice(renderer::GnashDevice::RAWFB);
        } else if (dfb) {
            setDevice(renderer::GnashDevice::DIRECTFB);
        } else if (x11) {
            setDevice(renderer::GnashDevice::X11);
        }        
    }

    // Initialize the display device
    _device->initDevice(0, 0);

    return true;
}
int kickstartFromCD(char *kssrc) {
    int rc, i;
    char *p, *kspath;
    struct device ** devices;

    logMessage(INFO, "getting kickstart file from first CDROM");

    devices = probeDevices(CLASS_CDROM, BUS_UNSPEC, 0);
    /* usb can take some time to settle, even with the various hacks we
     * have in place.  some systems use portable USB CD-ROM drives, try to
     * make sure there really isn't one before bailing */
    for (i = 0; !devices && i < 10; ++i) {
        logMessage(DEBUGLVL, "sleeping to wait for a USB CD-ROM");
        sleep(2);
        devices = probeDevices(CLASS_CDROM, BUS_UNSPEC, 0);
    }

    if (!devices) {
        logMessage(ERROR, "No CDROM devices found!");
        return 1;
    }

    /* format is cdrom:[/path/to/ks.cfg] */
    kspath = "";
    p = strchr(kssrc, ':');
    if (p)
        kspath = p + 1;

    if (!p || strlen(kspath) < 1)
        kspath = "/ks.cfg";

    for (i=0; devices[i]; i++) {
        if (!devices[i]->device)
            continue;

        rc = getKickstartFromBlockDevice(devices[i]->device, kspath);
        if (rc == 0)
            return 0;
    }

    startNewt();
    newtWinMessage(_("Error"), _("OK"),
                   _("Cannot find kickstart file on CDROM."));
    return 1;
}
Ejemplo n.º 4
0
UPower::UPower() : m_interfaceProps(0), m_interface(0) {
    m_watcher = new QDBusServiceWatcher;
    m_watcher->addWatchedService("org.freedesktop.UPower");
    m_watcher->setConnection(QDBusConnection::systemBus());
    m_watcher->setWatchMode( QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration );

    connect(m_watcher, SIGNAL(serviceUnregistered(QString)), this, SIGNAL(upowerUnavailable()));
    connect(m_watcher, SIGNAL(serviceRegistered(QString)), this, SLOT(connectInterfaces()));
    connect(this, SIGNAL(upowerAvailable()), this, SLOT(probeDevices()));

    connectInterfaces();
}
Ejemplo n.º 5
0
int main () {
	int i=0;
	struct ddcDevice *monitor = NULL;
	struct device **hw;
  char *buf = NULL;

	initializeDeviceList();

	printf ("Detecting your monitor...\n");
	hw = probeDevices(CLASS_MONITOR, BUS_DDC, PROBE_ONE);

	if (hw == NULL || ((monitor = *(struct ddcDevice**)hw) == NULL &&
	    (monitor = (struct ddcDevice*)ddcProbe(CLASS_MONITOR,
						   PROBE_ONE, NULL)) == NULL)) {
		printf("No DDC capable monitor detected!\n");
		return -1;
	}

	if ((monitor->horizSyncMin == 0) || (monitor->horizSyncMax == 0) || (monitor->vertRefreshMin == 0) || (monitor->vertRefreshMax == 0)) {
		printf("No DDC capable monitor detected!!!!\nhorizSyncMin = %d \nhorizSyncMax = %d \nvertRefreshMin = %d \nvertRefreshMax = %d \n",
				                     monitor->horizSyncMin, monitor->horizSyncMax, monitor->vertRefreshMin, monitor->vertRefreshMax);
		return -1;
	}
	
	printf("Monitor id: %s\n HSync: %d - %d\n VRefresh: %d - %d\n",
			monitor->id, monitor->horizSyncMin, monitor->horizSyncMax, monitor->vertRefreshMin, monitor->vertRefreshMax);

	printf("Begin if 'Monitor modes':\n'");
	for (i = 0; monitor->modes[i]; i += 2) {
		if (i) {
			printf(" ");
		}
		printf("%dx%d", monitor->modes[i], monitor->modes[i + 1]);
		buf = (char *)realloc( buf, 1 + ( i / 2 ) * MODE_SIZE );
	}
	printf("'\n");
	printf("End of 'Monitor modes'.\n");
	
	printf("Contents of buf array:\n");
	sprintf(buf, "%s (", monitor->id);
	for (i = 0; monitor->modes[i]; i += 2) {
		if (i) {
			strcat(buf, " ");
		}
		sprintf(buf + strlen(buf), "%dx%d",
				monitor->modes[i], monitor->modes[i + 1]);
		printf("DEBUG buf = '%s'\n", buf);
	}
	strcat(buf, ")");
	printf("buf array = '%s'\n", buf);
	printf("buf size = '%d'\n", strlen(buf)+1);
	return 0;
}
Ejemplo n.º 6
0
void usbInitializeMouse(moduleList modLoaded, moduleDeps modDeps,
                        moduleInfoSet modInfo) {
    if (FL_NOUSB(flags)) return;

    logMessage(INFO, "looking for USB mouse...");
    if (probeDevices(CLASS_MOUSE, BUS_USB, PROBE_ALL)) {
        logMessage(INFO, "USB mouse found, loading mousedev module");
        if (mlLoadModuleSet("mousedev", modLoaded, modDeps, modInfo)) {
            logMessage (DEBUGLVL, "failed to loading mousedev module");
            return;
        }
    }
}
Ejemplo n.º 7
0
void
writeInterfacesFile(struct loaderData_s *loaderData)
{
	struct device	**devices;
	int		i, fd;
	char		*dev, *mac, tmpstr[128], *drivername;

	logMessage(INFO, "ROCKS:writeInterfacesFile");

	if ((fd = open("/tmp/interfaces",
					O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) {
		logMessage(ERROR, "ROCKS:writeInterfacesFile:failed to open '/tmp/interfaces'");
		return;
	}

	devices = probeDevices(CLASS_NETWORK, BUS_UNSPEC, PROBE_LOADED);
	for (i = 0; devices && devices[i]; i++) {
		dev = devices[i]->device;
		mac = nl_mac2str(dev);

		drivername = get_driver_name(dev);

		if (mac) {
			/* A hint as to our primary interface. */
			if (!strcmp(dev, loaderData->netDev)) {
				snprintf(tmpstr, sizeof(tmpstr),
				"X-RHN-Provisioning-MAC-%d: %s %s %s ks\r\n",
				i, dev, mac, drivername);
			} else {
				snprintf(tmpstr, sizeof(tmpstr),
				"X-RHN-Provisioning-MAC-%d: %s %s %s\r\n",
				i, dev, mac, drivername);
			}

			if (write(fd, tmpstr, strlen(tmpstr)) < 0) {
				logMessage(ERROR,
				    "ROCKS:writeInterfacesFile::write failed");
			}

			free(mac);
		}

		free(drivername);
	}

	close(fd);
	return;
}
Ejemplo n.º 8
0
int usbInitialize(moduleList modLoaded, moduleDeps modDeps,
			 moduleInfoSet modInfo) {
    struct device ** devices;
    char * buf;
    int i;
    char * loadUsbStorage = NULL;

    if (FL_NOUSB(flags)) return 0;

    logMessage(INFO, "looking for usb controllers");

    devices = probeDevices(CLASS_USB, BUS_PCI, 0);

    if (!devices) {
        logMessage(DEBUGLVL, "no usb controller found");
        return 0;
    }

    /* JKFIXME: if we looked for all of them, we could batch this up and it
     * would be faster */
    for (i=0; devices[i]; i++) {
        if (!devices[i]->driver) continue;
        logMessage(INFO, "found USB controller %s", devices[i]->driver);

        if (mlLoadModuleSet(devices[i]->driver, modLoaded, modDeps, modInfo)) {
            /* dont return, just keep going. */
            /* may have USB built into kernel */
            /* return 1; */
        }

    }
    free(devices);


    if (FL_TESTING(flags)) return 0;

    if (doPwMount("/proc/bus/usb", "/proc/bus/usb", "usbfs", 0, NULL))
	logMessage(ERROR, "failed to mount device usbfs: %s", strerror(errno));

    /* sleep so we make sure usb devices get properly enumerated.
       that way we should block when initializing each usb driver until
       the device is ready for use */
    sleepUntilUsbIsStable();

    if (!FL_NOUSBSTORAGE(flags)) {
        devices = probeDevices(CLASS_HD | CLASS_FLOPPY | CLASS_CDROM, 
                               BUS_USB, PROBE_ALL);
        if (devices) {
            if (FL_UB(flags))
                loadUsbStorage = ":ub";
            else 
                loadUsbStorage = ":usb-storage";
            free(devices);
        }
    }

    buf = alloca(40);
    sprintf(buf, "hid:keybdev%s", (loadUsbStorage ? loadUsbStorage : ""));
    mlLoadModuleSet(buf, modLoaded, modDeps, modInfo);
    sleep(1);

    return 0;
}
Ejemplo n.º 9
0
bool
FBOvgGlue::init(int argc, char **argv[])
{
    // GNASH_REPORT_FUNCTION;

#if 0
    bool egl = false;
    bool rawfb = false;
    bool dfb = false;
    bool x11 = false;
    // Probe to see what display devices we have that could be used.
    boost::shared_array<renderer::GnashDevice::dtype_t> devs = probeDevices();
    if (devs) {
        int i = 0;
        while (devs[i] != renderer::GnashDevice::NODEV) {
            switch (devs[i++]) {
              case renderer::GnashDevice::EGL:
                  log_debug(_("Probing found an EGL display device"));
                  egl = true;
                  break;
              case renderer::GnashDevice::RAWFB:
                  log_debug(_("Probing found a raw Framebuffer display device"));
                  rawfb = true;
                  break;
              case renderer::GnashDevice::X11:
                  log_debug(_("Probing found an X11 display device"));
                  x11 = true;
                  break;
              case renderer::GnashDevice::DIRECTFB:
                  log_debug(_("Probing found a DirectFB display device"));
                  dfb = true;
                  break;
              case renderer::GnashDevice::NODEV:
              default:
                  log_error(_("No display devices found by probing!"));
                  break;
            }
        }

    }
    
    // Now that we know what exists, we have to decide which one to
    // use, as OpenVG can work with anything. We can only have one
    // display device operating at a time.
    if (egl) {
        setDevice(renderer::GnashDevice::EGL);
    } else {
        // OpenVG requires EGL, so if we don't have it, Gnash won't run
        log_error("OpenVG needs EGL to work!");
        return false;
    }
#endif

    _device.reset(new renderer::EGLDevice(argc, *argv));

    // Initialize the display device
    // EGL still reqires us to open the framebuffer
    _device->bindClient(renderer::GnashDevice::OPENVG);
    
    _display.initDevice(0, 0);

    _width = getWidth();
    _height = getHeight();

    // Some linux distros like ltib have more information available
    // about the framebuffer
    int fd = ::open("/sys/class/graphics/fb0/stride", O_RDONLY);
    char number[10];
    if (::read(fd, &number, 10)) {
        _stride = strtol(number, NULL, 0);
    } else {
        if (getDepth() == 32) {
            _stride = _width * 4;
        } else {
            _stride = _width * 2;
        }
    }
    close(fd);
    
    // You must pass in the file descriptor to the opened
    // framebuffer when creating a window. Under X11, this is
    // actually the XID of the created window.
    return _device->attachWindow(_display.getHandle());
}
Ejemplo n.º 10
0
/* Get the list of removable devices (floppy/cdrom) available.  Used to
 * find suitable devices for update disk / driver disk source.  
 * Returns the number of devices.  ***devNames will be a NULL-terminated list
 * of device names
 */
int getRemovableDevices(char *** devNames) {
    struct device **devices, **floppies, **cdroms, **disks;
    int numDevices = 0;
    int i = 0, j = 0;

    floppies = probeDevices(CLASS_FLOPPY, 
                            BUS_IDE | BUS_SCSI | BUS_MISC, PROBE_LOADED);
    cdroms = probeDevices(CLASS_CDROM, 
                          BUS_IDE | BUS_SCSI | BUS_MISC, PROBE_LOADED);
    disks = probeDevices(CLASS_HD, 
                         BUS_IDE | BUS_SCSI | BUS_MISC, PROBE_LOADED);

    /* we should probably take detached into account here, but it just
     * means we use a little bit more memory than we really need to */
    if (floppies)
        for (i = 0; floppies[i]; i++) numDevices++;
    if (cdroms)
        for (i = 0; cdroms[i]; i++) numDevices++;
    if (disks)
        for (i = 0; disks[i]; i++) numDevices++;

    /* JKFIXME: better error handling */
    if (!numDevices) {
        logMessage(ERROR, "no devices found to load drivers from");
        return numDevices;
    }

    devices = malloc((numDevices + 1) * sizeof(**devices));

    i = 0;
    if (floppies)
        for (j = 0; floppies[j]; j++) 
            if ((floppies[j]->detached == 0) && (floppies[j]->device != NULL)) 
                devices[i++] = floppies[j];
    if (cdroms)
        for (j = 0; cdroms[j]; j++) 
            if ((cdroms[j]->detached == 0) && (cdroms[j]->device != NULL)) 
                devices[i++] = cdroms[j];
    if (disks)
        for (j = 0; disks[j]; j++) 
            if ((disks[j]->detached == 0) && (disks[j]->device != NULL)) 
                devices[i++] = disks[j];

    devices[i] = NULL;
    numDevices = i;

    for (i = 0; devices[i]; i++) {
        logMessage(DEBUGLVL, "devices[%d] is %s", i, devices[i]->device);
    }

    *devNames = malloc((numDevices + 1) * sizeof(*devNames));
    for (i = 0; devices[i] && (i < numDevices); i++)
        (*devNames)[i] = strdup(devices[i]->device);
    free(devices);
    (*devNames)[i] = NULL;

    if (i != numDevices)
        logMessage(WARNING, "somehow numDevices != len(devices)");

    return numDevices;
}
Ejemplo n.º 11
0
int getFileFromUrl(char * url, char * dest, 
                   struct loaderData_s * loaderData) {
    char ret[47];
    struct iurlinfo ui;
    enum urlprotocol_t proto = 
        !strncmp(url, "ftp://", 6) ? URL_METHOD_FTP : URL_METHOD_HTTP;
    char * host = NULL, * file = NULL, * chptr = NULL;
    char * user = NULL, * password = NULL;
    int fd, rc;
    struct networkDeviceConfig netCfg;
    char * ehdrs = NULL;
    ip_addr_t *tip;

#ifdef  ROCKS
    char *drivername;
#endif

#ifdef  ROCKS
     /*
      * Call non-interactive, exhaustive NetworkUp() if we are
      * a cluster appliance.
      */
    if (!strlen(url)) {
	    logMessage(INFO, "ROCKS:getFileFromUrl:calling rocksNetworkUp");
            rc = rocksNetworkUp(loaderData, &netCfg);
    } else {
	    logMessage(INFO, "ROCKS:getFileFromUrl:calling kickstartNetworkUp");
            rc = kickstartNetworkUp(loaderData, &netCfg);
    }

    if (rc) return 1;
    fd = 0;

    /*
     * this will be used when starting up mini_httpd()
     *
     * Get the nextServer from PUMP if we DHCP, otherwise it
     * better be on the command line.
     */

    if ( netCfg.dev.set & PUMP_INTFINFO_HAS_BOOTFILE ) {
    	tip = &(netCfg.dev.nextServer);
    	inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip));

    	if (strlen(ret) > 0) {
		loaderData->nextServer = strdup(ret);
	} else {
        	loaderData->nextServer = NULL;
	}
    }

    /*
     * If no nextServer use the gateway.
     */
    if ( !loaderData->nextServer ) {
    	loaderData->nextServer = strdup(loaderData->gateway);
    }

    logMessage(INFO, "%s: nextServer %s",
		"ROCKS:getFileFromUrl", loaderData->nextServer);
#else
    if (kickstartNetworkUp(loaderData, &netCfg)) {
        logMessage(ERROR, "unable to bring up network");
        return 1;
    }
#endif /* ROCKS */

    memset(&ui, 0, sizeof(ui));
    ui.protocol = proto;

#ifdef	ROCKS
{
	struct sockaddr_in	*sin;
	int			string_size;
	int			ncpus;
	char			np[16];
	char			*arch;
	char			*base;

#if defined(__i386__)
	arch = "i386";
#elif defined(__ia64__)
	arch = "ia64";
#elif defined(__x86_64__)
	arch = "x86_64";
#endif

	if (!strlen(url)) {
		base = strdup("install/sbin/kickstart.cgi");
		host = strdup(loaderData->nextServer);
	}
	else {
		char	*p, *q;

		base = NULL;
		host = NULL;

		p = strstr(url, "//");
		if (p != NULL) {
			p += 2;

			/*
			 * 'base' is the file name
			 */
			base = strchr(p, '/');
			if (base != NULL) {
				base += 1;
			}

			/*
		 	 * now get the host portion of the URL
			 */
			q = strchr(p, '/');
			if (q != NULL) {
				*q = '\0';
				host = strdup(p);
			}
		}
		
		if (!base || !host) {
			logMessage(ERROR,
				"kickstartFromUrl:url (%s) not well formed.\n",
				url);
			return(1);
		}
	}

	/* We always retrieve our kickstart file via HTTPS, 
	 * however the official install method (for *.img and rpms)
	 * is still HTTP.
	 */
	ui.protocol = URL_METHOD_HTTPS;

	winStatus(40, 3, _("Secure Kickstart"), 
	        _("Looking for Kickstart keys..."));

	getCert(loaderData);

	newtPopWindow();

	/* seed random number generator with our IP: unique for our purposes.
	 * Used for nack backoff.
	 */
	tip = &(netCfg.dev.nextServer);
	sin = (struct sockaddr_in *)IP_ADDR(tip);
	if (sin == NULL) {
		srand(time(NULL));
	} else {
		srand((unsigned int)sin->sin_addr.s_addr);
	}

	ncpus = num_cpus();
	sprintf(np, "%d", ncpus);

	string_size = strlen(base) + strlen("?arch=") + strlen(arch) +
		strlen("&np=") + strlen(np) + 1;

	if ((file = alloca(string_size)) == NULL) {
		logMessage(ERROR, "kickstartFromUrl:alloca failed\n");
		return(1);
	}
	memset(file, 0, string_size);

	sprintf(file, "/%s?arch=%s&np=%s", base, arch, np);
}

	logMessage(INFO, "ks location: https://%s%s", host, file);

#else
    tip = &(netCfg.dev.ip);
    inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip));
    getHostPathandLogin((proto == URL_METHOD_FTP ? url + 6 : url + 7),
                   &host, &file, &user, &password, ret);

    logMessage(INFO, "file location: %s://%s/%s",
               (proto == URL_METHOD_FTP ? "ftp" : "http"), host, file);

#endif /* ROCKS */
    chptr = strchr(host, '/');
    if (chptr == NULL) {
        ui.address = strdup(host);
        ui.prefix = strdup("/");
    } else {
        *chptr = '\0';
        ui.address = strdup(host);
        host = chptr;
        *host = '/';
        ui.prefix = strdup(host);
    }

    if (user && strlen(user)) {
        ui.login = strdup(user);
        if (password && strlen(password)) ui.password = strdup(password);
    }

    if (proto == URL_METHOD_HTTP) {
        ehdrs = (char *) malloc(24+strlen(VERSION));
        sprintf(ehdrs, "User-Agent: anaconda/%s\r\n", VERSION);
    }

    if (proto == URL_METHOD_HTTP && FL_KICKSTART_SEND_MAC(flags)) {
        /* find all ethernet devices and make a header entry for each one */
        int i;
        unsigned int hdrlen;
        char *dev, *mac, tmpstr[128];
        struct device ** devices;

        hdrlen = 0;
        devices = probeDevices(CLASS_NETWORK, BUS_UNSPEC, PROBE_LOADED);
        for (i = 0; devices && devices[i]; i++) {
            dev = devices[i]->device;
            mac = nl_mac2str(dev);
#ifdef  ROCKS
            drivername = get_driver_name(dev);
#endif
            if (mac) {
#ifdef  ROCKS
                /* A hint as to our primary interface. */
                if (!strcmp(dev, loaderData->netDev)) {
                        snprintf(tmpstr, sizeof(tmpstr),
                                "X-RHN-Provisioning-MAC-%d: %s %s %s ks\r\n",
                                i, dev, mac, drivername);
                } else {
                        snprintf(tmpstr, sizeof(tmpstr),
                                "X-RHN-Provisioning-MAC-%d: %s %s %s\r\n",
                                i, dev, mac, drivername);
                }
#else
                snprintf(tmpstr, sizeof(tmpstr),
                         "X-RHN-Provisioning-MAC-%d: %s %s\r\n", i, dev, mac);

#endif /* ROCKS */

#ifdef  ROCKS
                free(drivername);
#endif
                free(mac);

                if (!ehdrs) {
                    hdrlen = 128;
                    ehdrs = (char *) malloc(hdrlen);
                    *ehdrs = '\0';
                } else if ( strlen(tmpstr) + strlen(ehdrs) + 2 > hdrlen) {
                    hdrlen += 128;
                    ehdrs = (char *) realloc(ehdrs, hdrlen);
                }

                strcat(ehdrs, tmpstr);
            }
        }
    }
	
#ifdef ROCKS
{
        /* Retrieve the kickstart file via HTTPS */

        BIO *sbio;

        sbio = urlinstStartSSLTransfer(&ui, file, ehdrs, 1, flags,
		loaderData->nextServer);
        if (!sbio) {
                logMessage(ERROR, "failed to retrieve https://%s/%s",
                        ui.address, file);
                return 1;
        }

        rc = copyFileSSL(sbio, dest);
        if (rc) {
                unlink (dest);
                logMessage(ERROR, "failed to copy file to %s", dest);
                return 1;
        }

        urlinstFinishSSLTransfer(sbio);
        if (haveCertificate())
                umount("/mnt/rocks-disk");
}
#else
    fd = urlinstStartTransfer(&ui, file, ehdrs);
    if (fd < 0) {
        logMessage(ERROR, "failed to retrieve http://%s/%s/%s", ui.address, ui.prefix, file);
        if (ehdrs) free(ehdrs);
        return 1;
    }
           
    rc = copyFileFd(fd, dest);
    if (rc) {
        unlink (dest);
        logMessage(ERROR, "failed to copy file to %s", dest);
        if (ehdrs) free(ehdrs);
        return 1;
    }

    urlinstFinishTransfer(&ui, fd);
#endif /* ROCKS */

    if (ehdrs) free(ehdrs);

    return 0;
}
/* set up a cdrom, nominally for installation 
 *
 * location: where to mount the cdrom at JKFIXME: ignored
 * interactive: whether or not to prompt about questions/errors (1 is yes)
 *
 * loaderData is the kickstart info, can be NULL meaning no info
 *
 * requirepkgs=1 means CD should have packages, otherwise we just find stage2
 *
 * side effect: found cdrom is mounted as /mnt/source.  stage2 mounted
 * as /mnt/runtime.
 */
char * setupCdrom(char * location, struct loaderData_s * loaderData,
                  moduleInfoSet modInfo, moduleList modLoaded, 
                  moduleDeps modDeps, int interactive, int requirepkgs) {
    int i, r, rc;
    int foundinvalid = 0;
    int stage2inram = 0;
    char * buf;
    char *stage2img;
    struct device ** devices;

    devices = probeDevices(CLASS_CDROM, BUS_UNSPEC, 0);
    if (!devices) {
        logMessage(ERROR, "got to setupCdrom without a CD device");
        return NULL;
    }

    /* JKFIXME: ASSERT -- we have a cdrom device when we get here */
    do {
        for (i = 0; devices[i]; i++) {
            if (!devices[i]->device)
                continue;

            logMessage(INFO,"trying to mount CD device %s", devices[i]->device);

            if (devMakeInode(devices[i]->device, "/tmp/cdrom") != 0) {
                logMessage(ERROR, "unable to create device node for %s",
                           devices[i]->device);
                continue;
            }

            if (!doPwMount("/tmp/cdrom", "/mnt/source", "iso9660", 
                           IMOUNT_RDONLY, NULL)) {
                if (!access("/mnt/source/images/stage2.img", R_OK) &&
                    (!requirepkgs || !access("/mnt/source/.discinfo", R_OK))) {

                    /* if in rescue mode lets copy stage 2 into RAM so we can */
                    /* free up the CD drive and user can have it avaiable to  */
                    /* aid system recovery.                                   */
                    if (FL_RESCUE(flags) && !FL_TEXT(flags) &&
                        totalMemory() > 128000) {
                        rc = copyFile("/mnt/source/images/stage2.img", 
                                      "/tmp/ramfs/stage2.img");
                        stage2img = "/tmp/ramfs/stage2.img";
                        stage2inram = 1;
                    } else {
                        stage2img = strdup("/mnt/source/images/stage2.img");
                        stage2inram = 0;
                    }
	
                    rc = mountStage2(stage2img);

                    /* if we failed, umount /mnt/source and keep going */
                    if (rc) {
                        logMessage(INFO, "mounting stage2 failed");

                        umount("/mnt/source");
                        if (rc == -1)
                            foundinvalid = 1;
                        continue;
                    }

                    /* do the media check */
                    queryCDMediaCheck(devices[i]->device);

                    /* if in rescue mode and we copied stage2 to RAM */
                    /* we can now unmount the CD                     */
                    if (FL_RESCUE(flags) && stage2inram) {
                        umount("/mnt/source");
                        unlink("/tmp/cdrom");
                    }

                    r = asprintf(&buf, "cdrom://%s:/mnt/source",
                                 devices[i]->device);
                    if (r == -1)
                        return NULL;
                    else
                        return buf;

                }

                /* this wasnt the CD we were looking for, clean up and */
                /* try the next CD drive                               */
                umount("/mnt/source");
            }
        }

        if (interactive) {
            char * buf;
            if (foundinvalid)
                buf = sdupprintf(_("No %s CD was found which matches your "
                                   "boot media.  Please insert the %s CD "
                                   "and press %s to retry."), getProductName(),
                                 getProductName(), _("OK"));
            else
                buf = sdupprintf(_("The %s CD was not found in any of your "
                                   "CDROM drives. Please insert the %s CD "
                                   "and press %s to retry."), getProductName(),
                                 getProductName(), _("OK"));

            if (!FL_NOEJECT(flags)) {
                ejectCdrom();
                unlink("/tmp/cdrom");
            } else {
                logMessage(INFO, "noeject in effect, not ejecting cdrom");
            }
            rc = newtWinChoice(_("CD Not Found"),
                               _("OK"), _("Back"), buf, _("OK"));
            free(buf);
            if (rc == 2)
                return NULL;
        } else {
            /* we can't ask them about it, so just return not found */
            return NULL;
        }
    } while (1);

    return NULL;
}