Пример #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");
	}
}
/* JKFIXME: Assumes CD is mounted as /mnt/source                      */
static void mountCdromStage2(char *cddev) {
    int gotcd1=0;
    int rc;

    devMakeInode(cddev, "/tmp/cdrom");
    do {
        do {
            if (doPwMount("/tmp/cdrom", "/mnt/source", 
                          "iso9660", IMOUNT_RDONLY, NULL)) {
                if (!FL_NOEJECT(flags))
                    ejectCdrom();
                else
                    logMessage(INFO, "noeject in effect, not ejecting cdrom");
                wrongCDMessage();
            } else {
                break;
            }
        } while (1);

        rc = mountStage2("/mnt/source/images/stage2.img");

        /* if we failed, umount /mnt/source and keep going */
        if (rc) {
            umount("/mnt/source");
            if (!FL_NOEJECT(flags))
                ejectCdrom();
            else
                logMessage(INFO, "noeject in effect, not ejecting cdrom");
            wrongCDMessage();
        } else {
            gotcd1 = 1;
        }
    } while (!gotcd1);
}
Пример #3
0
int isUsableDasd(char *device) {
#if !defined(__s390__) && !defined(__s390x__)
    return 0;
#else
	char devname[16];
	char label[5], v4_hex[9];
	char l4ebcdic_hex[] = "d3d5e7f1";  /* LNX1 */
	char cms1_hex[] = "c3d4e2f1";      /* CMS1 */
	int f, ret, blksize;
	dasd_information_t dasd_info;
	volume_label_t vlabel;
	memset(&dasd_info, 0, sizeof(dasd_info));
	strcpy(devname, "/dev/");
	strcat(devname, device);
	devMakeInode(device, devname);
	if((f = open(devname, O_RDONLY)) == -1) {
		return 0;
	}
	if (ioctl(f, BLKSSZGET, &blksize) != 0) {
		close(f);
		/* fprintf(stderr, "Could not retrieve blocksize information!\n"); */
		return 0;
	}
	if (ioctl(f, BIODASDINFO, &dasd_info) != 0) {
		close(f);
		/* fprintf(stderr, "Could not retrieve disk information!\n"); */
		return 0;
	}
	ret = read_vlabel(&dasd_info, f, blksize, &vlabel);
        close(f);

	if (ret == 2) {
		return 0;
	} else if (ret == 1) { /* probably unformatted DASD */
		/* fprintf(stderr, "Found a usable device: %s\n", devname); */
		return 1;
	}
	memset(label, 0, 5);
	memset(v4_hex, 0, 9);
	strncpy(label, vlabel.volkey, 4);
	sprintf(v4_hex, "%02x%02x%02x%02x", label[0], label[1], label[2], label[3]);
        
	if(!strncmp(v4_hex, cms1_hex, 9)) {
		return 0;
	}
	if(!strncmp(v4_hex, l4ebcdic_hex, 9)) {
		return 2;
	}
        return 1;
#endif
}
/* reads iso status from device cddriver */
static int getISOStatusFromCDROM(char *cddriver, char *mediasum) {
    int isofd;
    int isostatus;

    devMakeInode(cddriver, "/tmp/cdrom");
    isofd = open("/tmp/cdrom", O_RDONLY);
    if (isofd < 0) {
        logMessage(WARNING, "Could not check iso status: %s", strerror(errno));
        unlink("/tmp/cdrom");
        return 0;
    }

    isostatus = getISOStatusFromFD(isofd, mediasum);

    close(isofd);
    unlink("/tmp/cdrom");

    return isostatus;
}
/*
 * Given cd device cddriver, this function will attempt to check its internal
 * checksum.
 *
 * JKFIXME: this ignores "location", which should be fixed */
static char * mediaCheckCdrom(char *cddriver) {
    int rc;
    int first;

    devMakeInode(cddriver, "/tmp/cdrom");

    first = 1;
    do {
        char *descr;
        char *tstamp;
        int ejectcd;

        /* init every pass */
        ejectcd = 0;
        descr = NULL;

        /* if first time through, see if they want to eject the CD      */
        /* currently in the drive (most likely the CD they booted from) */
        /* and test a different disk.  Otherwise just test the disk in  */
        /* the drive since it was inserted in the previous pass through */
        /* this loop, so they want it tested.                           */
        if (first) {
            first = 0;
            rc = newtWinChoice(_("Media Check"), _("Test"), _("Eject CD"),
                               _("Choose \"%s\" to test the CD currently in "
                                 "the drive, or \"%s\" to eject the CD and "
                                 "insert another for testing."), _("Test"),
                               _("Eject CD"));

            if (rc == 2)
                ejectcd = 1;
        }

        if (!ejectcd) {
            /* XXX MSFFIXME: should check return code for error */
            readStampFileFromIso("/tmp/cdrom", &tstamp, &descr);
            mediaCheckFile("/tmp/cdrom", descr);

            if (descr)
                free(descr);
        }

        if (!FL_NOEJECT(flags))
            ejectCdrom();
        else
            logMessage(INFO, "noeject in effect, not ejecting cdrom");

        rc = newtWinChoice(_("Media Check"), _("Test"), _("Continue"),
                       _("If you would like to test additional media, "
                       "insert the next CD and press \"%s\". "
                       "Testing each CD is not strictly required, however "
                       "it is highly recommended.  Minimally, the CDs should "
                       "be tested prior to using them for the first time. "
                       "After they have been successfully tested, it is not "
                       "required to retest each CD prior to using it again."),
                       _("Test"), _("Continue"));

        if (rc == 2) {
            if (!FL_NOEJECT(flags))
                unlink("/tmp/cdrom");
            else
                logMessage(INFO, "noeject in effect, not unmounting /tmp/cdrom");
            return NULL;
        } else {
            continue;
        }
    } while (1);
    
    return NULL;
}
/* 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;
}