Ejemplo n.º 1
0
static SCSI *openscsi (int scsibus, int target, int lun)
{
    SCSI *scgp = scg_smalloc ();

    if (scgp) {
	char *device;

	scgp->debug   = getenvint ("UAE_SCSI_DEBUG", 0);
	scgp->kdebug  = getenvint ("UAE_SCSI_KDEBUG", 0);
	scgp->silent  = getenvint ("UAE_SCSI_SILENT", 1);
	scgp->verbose = getenvint ("UAE_SCSI_VERBOSE", 0);
	device        = getenv    ("UAE_SCSI_DEVICE");

	if (!device || (strlen(device) == 0))
	    device = currprefs.scsi_device;

	write_log ("SCSIDEV: Device '%s'\n", device);

	scg_settarget (scgp, scsibus, target, lun);
	scg_settimeout (scgp, 80*60);

	if (scg__open (scgp, device) <= 0) {
	    if (scgp->errstr)
		write_log ("SCSIDEV: Failed to open '%s': %s\n",
			   device, scgp->errstr);
	    scg_sfree (scgp);
	    scgp = 0;
       }
    }
    return scgp;
}
Ejemplo n.º 2
0
Archivo: usbd.c Proyecto: elbing/harvey
static void
args(void)
{
	getenvint("usbdebug",	&usbdebug);
	getenvint("usbfsdebug",	&usbfsdebug);
	getenvdrvargs("kbargs",    "kb");
	getenvdrvargs("diskargs",  "disk");
	getenvdrvargs("etherargs", "ether");
}
Ejemplo n.º 3
0
static int parse_cpu_line(char *buff)
{
	char *s;
	int hz_ = getenvint("HZ", 100);
	if (!(s = strtok(buff + 4, " \t")))
		return -1;
	print_stat_value("user", s, hz_);
	if (!(s = strtok(NULL, " \t")))
		return -1;
	print_stat_value("nice", s, hz_);
	if (!(s = strtok(NULL, " \t")))
		return -1;
	print_stat_value("system", s, hz_);
	if (!(s = strtok(NULL, " \t")))
		return -1;
	print_stat_value("idle", s, hz_);
	if (!(s = strtok(NULL, " \t")))
		return 0;
	print_stat_value("iowait", s, hz_);
	if (!(s = strtok(NULL, " \t")))
		return 0;
	print_stat_value("irq", s, hz_);
	if (!(s = strtok(NULL, " \t")))
		return 0;
	print_stat_value("softirq", s, hz_);
	if (!(s = strtok(NULL, " \t")))
		return 0;
	print_stat_value("steal", s, hz_);
	if (!(s = strtok(NULL, " \t")))
		return 0;
	print_stat_value("guest", s, hz_);
	return 0;
}
Ejemplo n.º 4
0
/* wrapper for the underlying combination of scsi_smalloc()/scsi_open() */
static SCSI *openscsi (int scsibus, int target, int lun)
{
    SCSI *scgp = scsi_smalloc ();
    if (!scgp) {
	return NULL;
    }

    scgp->debug = getenvint ("UAE_SCSI_DEBUG", 0);
    scgp->kdebug = getenvint ("UAE_SCSI_KDEBUG", 0);
    scgp->silent = getenvint ("UAE_SCSI_SILENT", 1);
	 scgp->verbose = getenvint ("UAE_SCSI_VERBOSE", 0);
    scgp->scsibus = scsibus;
    scgp->target = target;
    scgp->lun = lun;

    if (!scsi_open(scgp, NULL, scsibus, target, lun)) {
	scsi_sfree (scgp);
	return NULL;
    } else {
	return scgp;
    }
}
Ejemplo n.º 5
0
static int open_scsi_bus (int flags)
{
    int   result = 0;
    int   debug, verbose;
    SCSI *scgp_scan;
    char *device;
    char  errstr[128];
    static int init = 0;

    DEBUG_LOG ("SCSIDEV: open_scsi_bus\n");

    if (!init) {
	init = 1;
	uae_sem_init (&scgp_sem, 0, 1);
	/* TODO: replace global lock with per-device locks */
    }

    debug   = getenvint ("UAE_SCSI_DEBUG", 0);
    verbose = getenvint ("UAE_SCSI_VERBOSE", 0);
    device  = getenv    ("UAE_SCSI_DEVICE");

    if (!device || (strlen (device) == 0))
	device = currprefs.scsi_device;

    if ((scgp_scan = scg_open (device, errstr, sizeof (errstr),
					       debug, verbose)) != (SCSI *)0) {
	scanscsi (scgp_scan);
	result = 1;
	scg_close (scgp_scan);
    } else {
	write_log ("SCSIDEV: can't open bus: %s\n", errstr);
    }

    write_log ("SCSIDEV: %d devices found\n", total_drives);
    return result;
}
Ejemplo n.º 6
0
Archivo: cpu.c Proyecto: schatt/munin-c
int cpu(int argc, char **argv) {
    FILE *f;
    char buff[256], *s;
    int ncpu=0, extinfo=0, scaleto100=0, hz;
    if(argc > 1) {
        if(!strcmp(argv[1], "config")) {
            s = getenv("scaleto100");
            if(s && !strcmp(s, "yes"))
                scaleto100=1;

            if(!(f=fopen(PROC_STAT, "r")))
                return fail("cannot open " PROC_STAT);
            while(fgets(buff, 256, f)) {
                if(!strncmp(buff, "cpu", 3)) {
                    if(isdigit(buff[3]))
                        ncpu++;
                    if(buff[3] == ' ') {
                        s = strtok(buff+4, " \t");
                        for(extinfo=1; strtok(NULL, " \t"); extinfo++)
                            ;
                    }
                }
            }
            fclose(f);

            if(ncpu < 1 || extinfo < 4)
                return fail("cannot parse " PROC_STAT);

            puts("graph_title CPU usage");
            if(extinfo >= 7)
                puts("graph_order system user nice idle iowait irq softirq");
            else
                puts("graph_order system user nice idle");
            if(scaleto100)
                puts("graph_args --base 1000 -r --lower-limit 0 --upper-limit 100");
            else
                printf("graph_args --base 1000 -r --lower-limit 0 --upper-limit %d\n", 100 * ncpu);
            puts("graph_vlabel %\n"
                 "graph_scale no\n"
                 "graph_info This graph shows how CPU time is spent.\n"
                 "graph_category system\n"
                 "graph_period second\n"
                 "system.label system\n"
                 "system.draw AREA");
            printf("system.max %d\n", 100 * ncpu);
            puts("system.min 0\n"
                 "system.type DERIVE");
            printf("system.warning %d\n", SYSWARNING * ncpu);
            printf("system.critical %d\n", SYSCRITICAL * ncpu);
            puts("system.info CPU time spent by the kernel in system activities\n"
                 "user.label user\n"
                 "user.draw STACK\n"
                 "user.min 0");
            printf("user.max %d\n", 100 * ncpu);
            printf("user.warning %d\n", USRWARNING * ncpu);
            puts("user.type DERIVE\n"
                 "user.info CPU time spent by normal programs and daemons\n"
                 "nice.label nice\n"
                 "nice.draw STACK\n"
                 "nice.min 0");
            printf("nice.max %d\n", 100 * ncpu);
            puts("nice.type DERIVE\n"
                 "nice.info CPU time spent by nice(1)d programs\n"
                 "idle.label idle\n"
                 "idle.draw STACK\n"
                 "idle.min 0");
            printf("idle.max %d\n", 100 * ncpu);
            puts("idle.type DERIVE\n"
                 "idle.info Idle CPU time");
            if(scaleto100)
                printf("system.cdef system,%d,/\n"
                       "user.cdef user,%d,/\n"
                       "nice.cdef nice,%d,/\n"
                       "idle.cdef idle,%d,/\n", ncpu, ncpu, ncpu, ncpu);
            if(extinfo >= 7) {
                puts("iowait.label iowait\n"
                     "iowait.draw STACK\n"
                     "iowait.min 0");
                printf("iowait.max %d\n", 100 * ncpu);
                puts("iowait.type DERIVE\n"
                     "iowait.info CPU time spent waiting for I/O operations to finish\n"
                     "irq.label irq\n"
                     "irq.draw STACK\n"
                     "irq.min 0");
                printf("irq.max %d\n", 100 * ncpu);
                puts("irq.type DERIVE\n"
                     "irq.info CPU time spent handling interrupts\n"
                     "softirq.label softirq\n"
                     "softirq.draw STACK\n"
                     "softirq.min 0");
                printf("softirq.max %d\n", 100 * ncpu);
                puts("softirq.type DERIVE\n"
                     "softirq.info CPU time spent handling \"batched\" interrupts");
                if(scaleto100)
                    printf("iowait.cdef iowait,%d,/\n"
                           "irq.cdef irq,%d,/\n"
                           "softirq.cdef softirq,%d,/\n", ncpu, ncpu, ncpu);
            }
            if(extinfo >= 8) {
                puts("steal.label steal\n"
                     "steal.draw STACK\n"
                     "steal.min 0");
                printf("steal.max %d\n", 100 * ncpu);
                puts("steal.type DERIVE\n"
                     "steal.info The time that a virtual CPU had runnable tasks, but the virtual CPU itself was not running");
                if(scaleto100)
                    printf("steal.cdef steal,%d,/\n", ncpu);
            }
            if(extinfo >= 9) {
                puts("guest.label guest\n"
                     "guest.draw STACK\n"
                     "guest.min 0");
                printf("guest.max %d\n", 100 * ncpu);
                puts("guest.type DERIVE\n"
                     "guest.info The time spent running a virtual CPU for guest operating systems under the control of the Linux kernel.");
                if(scaleto100)
                    printf("guest.cdef guest,%d,/\n", ncpu);
            }
            return 0;
        }
        if(!strcmp(argv[1], "autoconf"))
            return autoconf_check_readable(PROC_STAT);
    }
    if(!(f=fopen(PROC_STAT, "r")))
        return fail("cannot open " PROC_STAT);
    hz = getenvint("HZ", 100);
    while(fgets(buff, 256, f)) {
        if(!strncmp(buff, "cpu ", 4)) {
            fclose(f);
            if(!(s = strtok(buff+4, " \t")))
                break;
            print_stat_value("user", s, hz);
            if(!(s = strtok(NULL, " \t")))
                break;
            print_stat_value("nice", s, hz);
            if(!(s = strtok(NULL, " \t")))
                break;
            print_stat_value("system", s, hz);
            if(!(s = strtok(NULL, " \t")))
                break;
            print_stat_value("idle", s, hz);
            if(!(s = strtok(NULL, " \t")))
                return 0;
            print_stat_value("iowait", s, hz);
            if(!(s = strtok(NULL, " \t")))
                return 0;
            print_stat_value("irq", s, hz);
            if(!(s = strtok(NULL, " \t")))
                return 0;
            print_stat_value("softirq", s, hz);
            if(!(s = strtok(NULL, " \t")))
                return 0;
            print_stat_value("steal", s, hz);
            if(!(s = strtok(NULL, " \t")))
                return 0;
            print_stat_value("guest", s, hz);
            return 0;
        }
    }
    fclose(f);
    return fail("no cpu line found in " PROC_STAT);
}