Пример #1
0
int main() {
  printf("msp430_serial starting...\n");
  printf("libusb initing...\n");
  // initialize USB context, and get a device handle.
  HANDLE h = init_dev(1, 0, 0xf432);
  if (h == NULL) {
    fprintf(stderr, "Handle is NULL, initialization failed.\n");
    return(1);
  }
  // enable debugging
#ifdef DEBUG
  libusb_set_debug(mspContext, 3);
#endif
  // get endpoints
  MSP_get_endpoints(h, &ep_int_in, &ep_bulk_in, &ep_bulk_out);
  // Send magic setup control transfers...
  MSP_setup(h);
  get_descriptor(h);
  // TI driver does this 26 times... not sure why
  // read status
  do_control_transfer(h,0xa1,0x21);
  // write back to device
  do_send_std(h,0x21,0x20,true);

  while (1) {
    do_bulk_transfer(h);
    libusb_handle_events(mspContext);
  }
  printf("Exiting.\n");
  MSP_uninitialize(h);
  return(0);
}
Пример #2
0
static int gotemp_probe(struct usb_interface *interface,
			const struct usb_device_id *id)
{
	struct usb_device *udev = interface_to_usbdev(interface);
	struct gotemp *gdev;
	int retval;

	gdev = kzalloc(sizeof(struct gotemp), GFP_KERNEL);
	if (gdev == NULL) {
		dev_err(&interface->dev, "Out of memory\n");
		return -ENOMEM;
	}

	gdev->udev = usb_get_dev(udev);

	usb_set_intfdata(interface, gdev);

	init_dev(gdev);

	retval = device_create_file(&interface->dev, &dev_attr_temperature);
	if (retval)
		goto error;

	dev_info(&interface->dev, "USB GoTemp device now attached\n");
	return 0;

error:
	usb_set_intfdata(interface, NULL);
	kfree(gdev);
	return retval;
}
Пример #3
0
static int gotemp_probe(struct usb_interface *interface,
			const struct usb_device_id *id)
{
	struct usb_device *udev = interface_to_usbdev(interface);
	struct gotemp *gdev;
	struct usb_endpoint_descriptor *endpoint;
	int retval = -ENOMEM;
	size_t buffer_size;

	gdev = kzalloc(sizeof(struct gotemp), GFP_KERNEL);
	if (gdev == NULL) {
		dev_err(&interface->dev, "Out of memory\n");
		return -ENOMEM;
	}

	gdev->udev = usb_get_dev(udev);

	/* find the one control endpoint of this device */
	endpoint = &interface->cur_altsetting->endpoint[0].desc;
	buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
	gdev->int_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
	if (!gdev->int_in_buffer) {
		dev_err(&interface->dev, "Could not allocate buffer");
		goto error;
	}

	gdev->int_in_urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!gdev->int_in_urb) {
		dev_err(&interface->dev, "No free urbs available\n");
		goto error;
	}
	usb_fill_int_urb(gdev->int_in_urb, udev,
			 usb_rcvintpipe(udev,
					endpoint->bEndpointAddress),
			 gdev->int_in_buffer, buffer_size,
			 read_int_callback, gdev,
			 endpoint->bInterval);

	usb_set_intfdata(interface, gdev);

	init_dev(gdev);

	retval = device_create_file(&interface->dev, &dev_attr_temperature);
	if (retval)
		goto error;

	dev_info(&interface->dev, "USB GoTemp device now attached\n");
	return 0;

error:
	usb_free_urb(gdev->int_in_urb);
	kfree(gdev->int_in_buffer);
	kfree(gdev);
	return retval;
}
Пример #4
0
dev_major *new_dev( uint8_t n_minor, const char *name )
{
    dev_major *dev = malloc( sizeof (dev_major) );
    if( dev == 0 ) return 0;

    if( !init_dev( dev, n_minor, name ) )
        return dev;

    free( dev );
    return 0;
}
Пример #5
0
static EFI_STATUS
probe(dev_info_t* dev)
{

	if (init_dev(dev) < 0)
		return (EFI_UNSUPPORTED);

	add_device(&devices, dev);

	return (EFI_SUCCESS);
}
Пример #6
0
static EFI_STATUS
load(const char *filepath, dev_info_t *dev, void **bufp, size_t *bufsize)
{
	ufs_ino_t ino;
	EFI_STATUS status;
	size_t size;
	ssize_t read;
	void *buf;

#ifdef EFI_DEBUG
	{
		CHAR16 *text = efi_devpath_name(dev->devpath);
		DPRINTF("Loading '%s' from %S\n", filepath, text);
		efi_free_devpath_name(text);
	}
#endif
	if (init_dev(dev) < 0) {
		DPRINTF("Failed to init device\n");
		return (EFI_UNSUPPORTED);
	}

	if ((ino = lookup(filepath)) == 0) {
		DPRINTF("Failed to lookup '%s' (file not found?)\n", filepath);
		return (EFI_NOT_FOUND);
	}

	if (fsread_size(ino, NULL, 0, &size) < 0 || size <= 0) {
		printf("Failed to read size of '%s' ino: %d\n", filepath, ino);
		return (EFI_INVALID_PARAMETER);
	}

	if ((status = BS->AllocatePool(EfiLoaderData, size, &buf)) !=
	    EFI_SUCCESS) {
		printf("Failed to allocate read buffer %zu for '%s' (%lu)\n",
		    size, filepath, EFI_ERROR_CODE(status));
		return (status);
	}

	read = fsread(ino, buf, size);
	if ((size_t)read != size) {
		printf("Failed to read '%s' (%zd != %zu)\n", filepath, read,
		    size);
		(void)BS->FreePool(buf);
		return (EFI_INVALID_PARAMETER);
	}

	DPRINTF("Load complete\n");

	*bufp = buf;
	*bufsize = size;

	return (EFI_SUCCESS);
}
Пример #7
0
int main(multiboot_t * mbp)
{
	cpu_state_t *cpu;

	// first is to save critical info from bootloader
	// and get symbol tables so we can print back traces
	mbootp = mbp;
	init_debug(mbp);

	// reset text-mode
	c80_clear();
	printk_color(rc_black, rc_red, "\t\t\t\tRed Magic\n");

	// init processors
	init_bootstrap_processor();
	cpu = get_boot_processor();
	ASSERT(cpu != NULL);

	// initialize descriptors
	init_global_descriptor_table(cpu);
	init_interrupt_descriptor_table();
	init_io_apic();

	// interrupt on
	local_irq_enable();

	// memory management
	show_kernel_pos();
	show_ARDS_from_multiboot(mbp);
	init_paging();
	init_kheap();

	// initialize devices and rootfs
	init_dev();
	//init_root_fs();

	// start all APs
	if (mpinfo.ismp)
		start_smp();

	// start system clock
	if (!mpinfo.ismp)
		init_pit_timer(CLOCK_INT_HZ);
	else
		init_apic_timer(CLOCK_INT_HZ);

	// initialize kernel task and scheduling
	setup_init_task();
	init_sched();

	// All our initialisation calls will go in here.
	return 0xDEADBABA;
}
Пример #8
0
/*
 *   Query Device command from Director
 *   Sends Storage Daemon's information on the device to the
 *    caller (presumably the Director).
 *   This command always returns "true" so that the line is
 *    not closed on an error.
 *
 */
bool query_cmd(JCR *jcr)
{
   POOL_MEM dev_name, VolumeName, MediaType, ChangerName;
   BSOCK *dir = jcr->dir_bsock;
   DEVRES *device;
   AUTOCHANGER *changer;
   bool ok;

   Dmsg1(100, "Query_cmd: %s", dir->msg);
   ok = sscanf(dir->msg, query_device, dev_name.c_str()) == 1;
   Dmsg1(100, "<dird: %s", dir->msg);
   if (ok) {
      unbash_spaces(dev_name);
      foreach_res(device, R_DEVICE) {
         /* Find resource, and make sure we were able to open it */
         if (bstrcmp(dev_name.c_str(), device->name())) {
            if (!device->dev) {
               device->dev = init_dev(jcr, device);
            }
            if (!device->dev) {
               break;
            }
            ok = dir_update_device(jcr, device->dev);
            if (ok) {
               ok = dir->fsend(OK_query);
            } else {
               dir->fsend(NO_query);
            }
            return ok;
         }
      }
      foreach_res(changer, R_AUTOCHANGER) {
         /*Find resource, and make sure we were able to open it */
         if (bstrcmp(dev_name.c_str(), changer->name())) {
            if (!changer->device || changer->device->size() == 0) {
               continue;              /* no devices */
            }
            ok = dir_update_changer(jcr, changer);
            if (ok) {
               ok = dir->fsend(OK_query);
            } else {
               dir->fsend(NO_query);
            }
            return ok;
         }
      }
      /* If we get here, the device/autochanger was not found */
      unbash_spaces(dir->msg);
      pm_strcpy(jcr->errmsg, dir->msg);
      dir->fsend(NO_device, dev_name.c_str());
      Dmsg1(100, ">dird: %s", dir->msg);
   } else {
Пример #9
0
static void init_link(struct bus *link)
{
	struct device *dev;
	struct bus *c_link;

	for (dev = link->children; dev; dev = dev->sibling)
		init_dev(dev);

	for (dev = link->children; dev; dev = dev->sibling) {
		for (c_link = dev->link_list; c_link; c_link = c_link->next)
			init_link(c_link);
	}
}
Пример #10
0
struct pipe_screen *
ilo_screen_create(struct intel_winsys *ws)
{
   struct ilo_screen *is;
   const struct intel_winsys_info *info;

   ilo_debug = debug_get_flags_option("ILO_DEBUG", ilo_debug_flags, 0);

   is = CALLOC_STRUCT(ilo_screen);
   if (!is)
      return NULL;

   is->winsys = ws;

   intel_winsys_enable_reuse(is->winsys);

   info = intel_winsys_get_info(is->winsys);
   if (!init_dev(&is->dev, info)) {
      FREE(is);
      return NULL;
   }

   util_format_s3tc_init();

   is->base.destroy = ilo_screen_destroy;
   is->base.get_name = ilo_get_name;
   is->base.get_vendor = ilo_get_vendor;
   is->base.get_param = ilo_get_param;
   is->base.get_paramf = ilo_get_paramf;
   is->base.get_shader_param = ilo_get_shader_param;
   is->base.get_video_param = ilo_get_video_param;
   is->base.get_compute_param = ilo_get_compute_param;

   is->base.get_timestamp = ilo_get_timestamp;

   is->base.flush_frontbuffer = NULL;

   is->base.fence_reference = ilo_fence_reference;
   is->base.fence_signalled = ilo_fence_signalled;
   is->base.fence_finish = ilo_fence_finish;

   is->base.get_driver_query_info = NULL;

   ilo_init_format_functions(is);
   ilo_init_context_functions(is);
   ilo_init_resource_functions(is);

   return &is->base;
}
Пример #11
0
int __init cec_init(void)
{
    printk("[CEC] init - starting\n");

    cec_internal_init();

    udelay(10000);

    startTask();

    /* ********* */
    /* irq setup */

   printk("[CEC] init - starting intterrupt (%d)\n", CEC_IRQ);

#if defined (CONFIG_KERNELVERSION) || LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)
    if (!request_irq(CEC_IRQ, (void*)cec_interrupt, IRQF_DISABLED, "cec", NULL))
#else
    if (!request_irq(CEC_IRQ, (void*)cec_interrupt, SA_INTERRUPT, "cec", NULL))
#endif
    {

    }
    else 
    {
       printk("[CEC] Can't get irq\n");
    }

    if(activemode)
    {
        init_e2_proc();

        input_init();
    }
    else
    {
        init_dev();
    }

    // TODO: how can we implement hotplug support?
    //while(!cancelStart && getPhysicalAddress() == 0) // HDMI is not plugged in
    //  msleep(200);

    cec_worker_init();

    return 0;
}
Пример #12
0
int main(int argc, char **argv)
{
	int handle;

	if (argc < 2)
		usage();
	if (argc > 1 && (streq(argv[1], "-h") || streq(argv[1], "--help")))
		usage();

	handle = open_dev("/dev/hidraw%d");
	if (handle == -1)
		trouble_shooting();

	init_dev(handle);

	configure(handle, argc, argv);

	close_dev(handle);
	exit(0);
}
Пример #13
0
static EFI_STATUS
try_load(dev_info_t *dev, const char *loader_path, void **bufp, size_t *bufsize)
{
	ufs_ino_t ino;
	EFI_STATUS status;
	size_t size;
	ssize_t read;
	void *buf;

	if (init_dev(dev) < 0)
		return (EFI_UNSUPPORTED);

	if ((ino = lookup(loader_path)) == 0)
		return (EFI_NOT_FOUND);

	if (fsread_size(ino, NULL, 0, &size) < 0 || size <= 0) {
		printf("Failed to read size of '%s' ino: %d\n", loader_path,
		    ino);
		return (EFI_INVALID_PARAMETER);
	}

	if ((status = bs->AllocatePool(EfiLoaderData, size, &buf)) !=
	    EFI_SUCCESS) {
		printf("Failed to allocate read buffer (%lu)\n",
		    EFI_ERROR_CODE(status));
		return (status);
	}

	read = fsread(ino, buf, size);
	if ((size_t)read != size) {
		printf("Failed to read '%s' (%zd != %zu)\n", loader_path, read,
		    size);
		(void)bs->FreePool(buf);
		return (EFI_INVALID_PARAMETER);
	}

	*bufp = buf;
	*bufsize = size;

	return (EFI_SUCCESS);
}
Пример #14
0
void open_sound(void)
{
    int err;

    ao_initialize();
    driver = ao_default_driver_id();
    mpg123_init();
    mh = mpg123_new(NULL, &err);
    buffer_size = mpg123_outblock(mh);
    buffer = malloc(buffer_size * sizeof(char));

    GError *error = NULL;
    gchar  *str;
    if ((str = g_key_file_get_string(keyfile, "preferences", "soundfile", &error))) {
        if (str[0]) {
            sound_file = str;
            init_dev();
        } else
            g_free(str);
    }
}
Пример #15
0
/**
 * Initialize all devices in the global device tree.
 *
 * Starting at the root device, call the device's init() method to do
 * device-specific setup, then call each child's init() method.
 */
void dev_initialize(void)
{
	struct bus *link;

	printk(BIOS_INFO, "Initializing devices...\n");

#if CONFIG_ARCH_X86
	/* Ensure EBDA is prepared before Option ROMs. */
	setup_default_ebda();
#endif

	/* First call the mainboard init. */
	init_dev(&dev_root);

	/* Now initialize everything. */
	for (link = dev_root.link_list; link; link = link->next)
		init_link(link);

	printk(BIOS_INFO, "Devices initialized\n");
	show_all_devs(BIOS_SPEW, "After init.");
}
Пример #16
0
void handler::run()
{
	// 初始化
	int rc = init_dev("eth0", "ether proto 0x888e");
	if (rc < 0)	return;

	packet::getInstance()->init_start();
	PKT *start = packet::getInstance()->get_start_pkt();
	pcap_sendpacket(handle, start->data, start->len);
	
	printf("[i]SEARCH SERVER.\n");

	pcap_loop(handle, 0, dispatcher_handler, (u_char *)this);

	printf("[i]ENTER KEEPALIVE.\n");
	// 保持在线
	while (1){
		packet::getInstance()->keepalive();
		PKT *keepalive = packet::getInstance()->get_keepalive_pkt();
		pcap_sendpacket(handle, keepalive->data, keepalive->len);
		sleep(20);
	}
}
Пример #17
0
int main(int argc, char **argv)
{
    int i, ret, become_daemon = 1;

    for(i=1; i<argc; i++) {
        if(argv[i][0] == '-' && argv[i][2] == 0) {
            switch(argv[i][1]) {
            case 'd':
                become_daemon = !become_daemon;
                break;

            case 'v':
                verbose = 1;
                break;

            case 'h':
                printf("usage: %s [options]\n", argv[0]);
                printf("options:\n");
                printf("  -d\tdo not daemonize\n");
                printf("  -v\tverbose output\n");
                printf("  -h\tprint this usage information\n");
                return 0;

            default:
                fprintf(stderr, "unrecognized argument: %s\n", argv[i]);
                return 1;
            }
        } else {
            fprintf(stderr, "unexpected argument: %s\n", argv[i]);
            return 1;
        }
    }

    if(become_daemon) {
        daemonize();
    }
    write_pid_file();

    puts("Spacenav daemon " VERSION);

    read_cfg("/etc/spnavrc", &cfg);

    if(init_clients() == -1) {
        return 1;
    }

    signal(SIGINT, sig_handler);
    signal(SIGTERM, sig_handler);
    signal(SIGSEGV, sig_handler);
    signal(SIGHUP, sig_handler);
    signal(SIGUSR1, sig_handler);
    signal(SIGUSR2, sig_handler);

    if(init_dev() == -1) {
        init_hotplug();
    }
    init_unix();
#ifdef USE_X11
    init_x11();
#endif

    atexit(cleanup);

    for(;;) {
        fd_set rset;
        int fd, max_fd = 0;
        struct client *c;

        FD_ZERO(&rset);

        /* set the device fd if it's open, otherwise set the hotplug fd */
        if((fd = get_dev_fd()) != -1 || (fd = get_hotplug_fd()) != -1) {
            FD_SET(fd, &rset);
            if(fd > max_fd) max_fd = fd;
        }

        /* the UNIX domain socket listening for connections */
        if((fd = get_unix_socket()) != -1) {
            FD_SET(fd, &rset);
            if(fd > max_fd) max_fd = fd;
        }

        /* all the UNIX socket clients */
        c = first_client();
        while(c) {
            if(get_client_type(c) == CLIENT_UNIX) {
                int s = get_client_socket(c);
                assert(s >= 0);

                FD_SET(s, &rset);
                if(s > max_fd) max_fd = s;
            }
            c = next_client();
        }

        /* and the X server socket */
#ifdef USE_X11
        if((fd = get_x11_socket()) != -1) {
            FD_SET(fd, &rset);
            if(fd > max_fd) max_fd = fd;
        }
#endif

        do {
            ret = select(max_fd + 1, &rset, 0, 0, 0);
        } while(ret == -1 && errno == EINTR);

        if(ret > 0) {
            handle_events(&rset);
        }
    }
    return 0;	/* unreachable */
}
Пример #18
0
void select_sound(GtkWidget *menu_item, gpointer data)
{
    GtkWidget *dialog;
    GtkFileFilter *filter, *filter_all;

    play = FALSE;

    dialog = gtk_file_chooser_dialog_new(_("Choose a file"),
                                         NULL,
                                         GTK_FILE_CHOOSER_ACTION_OPEN,
                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                         "Stop Sound", 1000,
                                         GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
                                         NULL);

    filter = gtk_file_filter_new();
    gtk_file_filter_add_pattern(filter, "*.[mM][pP][1-3]");
    gtk_file_filter_add_pattern(filter, "*.[wW][aA][vV]");
    gtk_file_filter_add_pattern(filter, "*.[oO][gG][gG]");
    gtk_file_filter_set_name(filter, _("Sound Files"));
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);

    filter_all = gtk_file_filter_new();
    gtk_file_filter_add_pattern(filter_all, "*");
    gtk_file_filter_set_name(filter_all, _("All Files"));
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter_all);

    gchar *dir = g_build_filename(installation_dir, "etc", NULL);
    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), dir);
    g_free(dir);

    gint r = gtk_dialog_run(GTK_DIALOG(dialog));

    if (play) { // can start during dialog
        gtk_widget_destroy(dialog);
        return;
    }

    if (r == 1000) { // stop sound
        G_LOCK(sound);

        g_free(sound_file);
        sound_file = NULL;

        if (dev) ao_close(dev);
        dev = NULL;

        g_key_file_set_string(keyfile, "preferences", "soundfile", "");
        gtk_widget_destroy(dialog);

        G_UNLOCK(sound);
        return;
    }

    if (r != GTK_RESPONSE_ACCEPT) {
        gtk_widget_destroy(dialog);
        return;
    }
               
    G_LOCK(sound);

    g_free(sound_file);
    sound_file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
    g_key_file_set_string(keyfile, "preferences", "soundfile", sound_file);

    init_dev();

    G_UNLOCK(sound);

    gtk_widget_destroy(dialog);
}
Пример #19
0
/*
 * Read in the information about files used in making the system.
 * Store it in the ftab linked list.
 */
void
read_files(void)
{
	FILE *fp;
	register struct file_list *tp, *pf;
	register struct device *dp;
	register struct opt *op;
	const char *wd;
	char *this, *needs;
	const char *devorprof;
	int options;
	int not_option;
	char pname[BUFSIZ];
	char fname[1024];
	char *rest = (char *) 0;
	int nreqs, first = 1, isdup;

	ftab = 0;
	(void) sprintf(fname, "%s/files", config_directory);
openit:
	fp = fopenp(VPATH, fname, pname, "r");
	if (fp == 0) {
		perror(fname);
		exit(1);
	}
next:
	options = 0;
	rest = (char *) 0;
	/*
	 * filename	[ standard | optional ]
	 *	[ dev* | profiling-routine ] [ device-driver]
	 */
	wd = get_word(fp);
	if (wd == (char *)EOF) {
		(void) fclose(fp);
		if (first == 1) {
			(void) sprintf(fname, "%s/files.%s", config_directory, machinename);
			first++;
			goto openit;
		}
		return;
	}
	if (wd == 0)
		goto next;
	/*
	 *  Allow comment lines beginning witha '#' character.
	 */
	if (*wd == '#')
	{
		while ((wd=get_word(fp)) && wd != (char *)EOF)
			;
		goto next;
	}

	this = ns(wd);
	next_word(fp, wd);
	if (wd == 0) {
		printf("%s: No type for %s.\n",
		    fname, this);
		exit(1);
	}
	if ((pf = fl_lookup(this)) && (pf->f_type != INVISIBLE || pf->f_flags))
		isdup = 1;
	else
		isdup = 0;
	tp = 0;
	nreqs = 0;
	devorprof = "";
	needs = 0;
	if (eq(wd, "standard"))
		goto checkdev;
	if (!eq(wd, "optional")) {
		printf("%s: %s must be optional or standard\n", fname, this);
		exit(1);
	}
	if (strncmp(this, "OPTIONS/", 8) == 0)
		options++;
	not_option = 0;
nextopt:
	next_word(fp, wd);
	if (wd == 0)
		goto doneopt;
	if (eq(wd, "not")) {
		not_option = !not_option;
		goto nextopt;
	}
	devorprof = wd;
	if (eq(wd, "device-driver") || eq(wd, "profiling-routine")) {
		next_word(fp, wd);
		goto save;
	}
	nreqs++;
	if (needs == 0 && nreqs == 1)
		needs = ns(wd);
	if (isdup)
		goto invis;
	if (options)
	{
		struct opt *lop = 0;
		struct device tdev;

		/*
		 *  Allocate a pseudo-device entry which we will insert into
		 *  the device list below.  The flags field is set non-zero to
		 *  indicate an internal entry rather than one generated from
		 *  the configuration file.  The slave field is set to define
		 *  the corresponding symbol as 0 should we fail to find the
		 *  option in the option list.
		 */
		init_dev(&tdev);
		tdev.d_name = ns(wd);
		tdev.d_type = PSEUDO_DEVICE;
		tdev.d_flags++;
		tdev.d_slave = 0;

		for (op=opt; op; lop=op, op=op->op_next)
		{
			char *od = allCaps(ns(wd));

			/*
			 *  Found an option which matches the current device
			 *  dependency identifier.  Set the slave field to
			 *  define the option in the header file.
			 */
			if (strcmp(op->op_name, od) == 0)
			{
				tdev.d_slave = 1;
				if (lop == 0)
					opt = op->op_next;
				else
					lop->op_next = op->op_next;
				free(op);
				op = 0;
			 }
			free(od);
			if (op == 0)
				break;
		}
		newdev(&tdev);
	}
 	for (dp = dtab; dp != 0; dp = dp->d_next) {
		if (eq(dp->d_name, wd) && (dp->d_type != PSEUDO_DEVICE || dp->d_slave)) {
			if (not_option)
				goto invis;	/* dont want file if option present */
			else
				goto nextopt;
		}
	}
	if (not_option)
		goto nextopt;		/* want file if option missing */

	for (op = opt; op != 0; op = op->op_next)
		if (op->op_value == 0 && opteq(op->op_name, wd)) {
			if (nreqs == 1) {
				free(needs);
				needs = 0;
			}
			goto nextopt;
		}

invis:
	while ((wd = get_word(fp)) != 0)
		;
	if (tp == 0)
		tp = new_fent();
	tp->f_fn = this;
	tp->f_type = INVISIBLE;
	tp->f_needs = needs;
	tp->f_flags = isdup;
	goto next;

doneopt:
	if (nreqs == 0) {
		printf("%s: what is %s optional on?\n",
		    fname, this);
		exit(1);
	}

checkdev:
	if (wd) {
		if (*wd == '|')
			goto getrest;
		next_word(fp, wd);
		if (wd) {
			devorprof = wd;
			next_word(fp, wd);
		}
	}

save:
getrest:
	if (wd) {
		if (*wd == '|') {
			rest = ns(get_rest(fp));
		} else {
			printf("%s: syntax error describing %s\n",
			       fname, this);
			exit(1);
		}
	}
	if (eq(devorprof, "profiling-routine") && profiling == 0)
		goto next;
	if (tp == 0)
		tp = new_fent();
	tp->f_fn = this;
	tp->f_extra = rest;
	if (options)
		tp->f_type = INVISIBLE;
	else
	if (eq(devorprof, "device-driver"))
		tp->f_type = DRIVER;
	else if (eq(devorprof, "profiling-routine"))
		tp->f_type = PROFILING;
	else
		tp->f_type = NORMAL;
	tp->f_flags = 0;
	tp->f_needs = needs;
	if (pf && pf->f_type == INVISIBLE)
		pf->f_flags = 1;		/* mark as duplicate */
	goto next;
}
Пример #20
0
int main(int argc, char **argv)
{
	int i, become_daemon = 1;

	for(i=1; i<argc; i++) {
		if(argv[i][0] == '-' && argv[i][2] == 0) {
			switch(argv[i][1]) {
			case 'd':
				become_daemon = !become_daemon;
				break;

			case 'v':
				verbose = 1;
				break;

			case 'h':
				printf("usage: %s [options]\n", argv[0]);
				printf("options:\n");
				printf("  -d\tdo not daemonize\n");
				printf("  -v\tverbose output\n");
				printf("  -h\tprint this usage information\n");
				return 0;

			default:
				fprintf(stderr, "unrecognized argument: %s\n", argv[i]);
				return 1;
			}
		} else {
			fprintf(stderr, "unexpected argument: %s\n", argv[i]);
			return 1;
		}
	}

	if(become_daemon) {
		daemonize();
	}
	write_pid_file();

	read_cfg("/etc/spnavrc", &cfg);

	if(!(client_list = malloc(sizeof *client_list))) {
		perror("failed to allocate client list");
		return 1;
	}
	client_list->next = 0;

	signal(SIGINT, sig_handler);
	signal(SIGTERM, sig_handler);
	signal(SIGSEGV, sig_handler);
	signal(SIGHUP, sig_handler);
	signal(SIGUSR1, sig_handler);
	signal(SIGUSR2, sig_handler);

	init_dev();
	init_unix();
#ifdef USE_X11
	init_x11();
#endif

	/* event handling loop */
	while(1) {
		fd_set rd_set;

		if(dev_fd == -1) {
			if(init_dev() == -1) {
				sleep(30);
				continue;
			}
		}

		if(select_all(&rd_set) >= 0) {
			handle_events(&rd_set);
		}
	}

	/* just for the sense of symmetry, execution can't reach this :) */
#ifdef USE_X11
	close_x11();
#endif
	close_dev();
	return 0;
}
Пример #21
0
/*
 * Setup device, jcr, and prepare to access device.
 *   If the caller wants read access, acquire the device, otherwise,
 *     the caller will do it.
 */
static DCR *setup_to_access_device(JCR *jcr, char *dev_name,
              const char *VolumeName, int mode)
{
   DEVICE *dev;
   char *p;
   DEVRES *device;
   DCR *dcr;
   char VolName[MAX_NAME_LENGTH];

   init_reservations_lock();

   /*
    * If no volume name already given and no bsr, and it is a file,
    * try getting name from Filename
    */
   if (VolumeName) {
      bstrncpy(VolName, VolumeName, sizeof(VolName));
      if (strlen(VolumeName) >= MAX_NAME_LENGTH) {
         Jmsg0(jcr, M_ERROR, 0, _("Volume name or names is too long. Please use a .bsr file.\n"));
      }
   } else {
      VolName[0] = 0;
   }
   if (!jcr->bsr && VolName[0] == 0) {
      if (!bstrncmp(dev_name, "/dev/", 5)) {
         /* Try stripping file part */
         p = dev_name + strlen(dev_name);

         while (p >= dev_name && !IsPathSeparator(*p))
            p--;
         if (IsPathSeparator(*p)) {
            bstrncpy(VolName, p+1, sizeof(VolName));
            *p = 0;
         }
      }
   }

   if ((device=find_device_res(dev_name, mode)) == NULL) {
      Jmsg2(jcr, M_FATAL, 0, _("Cannot find device \"%s\" in config file %s.\n"),
           dev_name, configfile);
      return NULL;
   }

   dev = init_dev(jcr, device);
   if (!dev) {
      Jmsg1(jcr, M_FATAL, 0, _("Cannot init device %s\n"), dev_name);
      return NULL;
   }
   device->dev = dev;
   jcr->dcr = dcr = new_dcr(jcr, NULL, dev);
   if (VolName[0]) {
      bstrncpy(dcr->VolumeName, VolName, sizeof(dcr->VolumeName));
   }
   bstrncpy(dcr->dev_name, device->device_name, sizeof(dcr->dev_name));

   create_restore_volume_list(jcr);

   if (mode) {                        /* read only access? */
      Dmsg0(100, "Acquire device for read\n");
      if (!acquire_device_for_read(dcr)) {
         return NULL;
      }
      jcr->read_dcr = dcr;
   } else {
      if (!first_open_device(dcr)) {
         Jmsg1(jcr, M_FATAL, 0, _("Cannot open %s\n"), dev->print_name());
         return NULL;
      }
      jcr->dcr = dcr;        /* write dcr */
   }
   return dcr;
}
Пример #22
0
/*
 * tty_open and tty_release keep up the tty count that contains the
 * number of opens done on a tty. We cannot use the inode-count, as
 * different inodes might point to the same tty.
 *
 * Open-counting is needed for pty masters, as well as for keeping
 * track of serial lines: DTR is dropped when the last close happens.
 * (This is not done solely through tty->count, now.  - Ted 1/27/92)
 *
 * The termios state of a pty is reset on first open so that
 * settings don't persist across reuse.
 */
static int tty_open(struct inode * inode, struct file * filp)
{
	struct tty_struct *tty;
	int major, minor;
	int noctty, retval;

retry_open:
	minor = MINOR(inode->i_rdev);
	major = MAJOR(inode->i_rdev);
	noctty = filp->f_flags & O_NOCTTY;
	if (major == TTYAUX_MAJOR) {
		if (!minor) {
			major = TTY_MAJOR;
			minor = current->tty;
		}
		/* noctty = 1; */
	} else if (major == TTY_MAJOR) {
		if (!minor) {
			minor = fg_console + 1;
			noctty = 1;
		}
	} else {
		printk("Bad major #%d in tty_open\n", MAJOR(inode->i_rdev));
		return -ENODEV;
	}
	if (minor <= 0)
		return -ENXIO;
	if (IS_A_PTY_MASTER(minor))
		noctty = 1;
	filp->f_rdev = (major << 8) | minor;
	retval = init_dev(minor);
	if (retval)
		return retval;
	tty = tty_table[minor];
#ifdef TTY_DEBUG_HANGUP
	printk("opening tty%d...", tty->line);
#endif
	if (test_bit(TTY_EXCLUSIVE, &tty->flags) && !suser())
		return -EBUSY;

#if 0
	/* clean up the packet stuff. */
	/*
	 *  Why is this not done in init_dev?  Right here, if another 
	 * process opens up a tty in packet mode, all the packet 
	 * variables get cleared.  Come to think of it, is anything 
	 * using the packet mode at all???  - Ted, 1/27/93
	 *
	 * Not to worry, a pty master can only be opened once.
	 * And rlogind and telnetd both use packet mode.  -- jrs
	 *
	 * Not needed.  These are cleared in initialize_tty_struct. -- jlc
	 */
	tty->ctrl_status = 0;
	tty->packet = 0;
#endif

	if (tty->open) {
		retval = tty->open(tty, filp);
	} else {
		retval = -ENODEV;
	}
	if (retval) {
#ifdef TTY_DEBUG_HANGUP
		printk("error %d in opening tty%d...", retval, tty->line);
#endif

		release_dev(minor, filp);
		if (retval != -ERESTARTSYS)
			return retval;
		if (current->signal & ~current->blocked)
			return retval;
		schedule();
		goto retry_open;
	}
	if (!noctty &&
	    current->leader &&
	    current->tty<0 &&
	    tty->session==0) {
		current->tty = minor;
		tty->session = current->session;
		tty->pgrp = current->pgrp;
	}
	filp->f_rdev = MKDEV(TTY_MAJOR,minor); /* Set it to something normal */
	return 0;
}
Пример #23
0
/*------------------------------------------------------------------------
 *  sysinit  --  initialize all Xinu data structeres and devices
 *------------------------------------------------------------------------
 */
LOCAL
sysinit()
{
	static	long	currsp;
	int	i,j, avail;
	struct	pentry	*pptr;
	struct	sentry	*sptr;
	struct	mblock	*mptr;
	SYSCALL pfintr();

	/*********************/
	set_evec(14, pfintr);

	pptr = &proctab[NULLPROC]; /* initialize null process entry */
	/*********************/
	

	numproc = 0;			/* initialize system variables */
	nextproc = NPROC-1;
	nextsem = NSEM-1;
	nextqueue = NPROC;		/* q[0..NPROC-1] are processes */

	/* initialize free memory list */
	/* PC version has to pre-allocate 640K-1024K "hole" */
	if (maxaddr+1 > HOLESTART) {
		memlist.mnext = mptr = (struct mblock *) roundmb(&end);
		mptr->mnext = (struct mblock *)HOLEEND;
		mptr->mlen = (int) truncew(((unsigned) HOLESTART -
	     		 (unsigned)&end));
        mptr->mlen -= 4;

		mptr = (struct mblock *) HOLEEND;
		mptr->mnext = 0;
		mptr->mlen = (int) truncew((unsigned)maxaddr - HOLEEND -
	      		NULLSTK);
/*
		mptr->mlen = (int) truncew((unsigned)maxaddr - (4096 - 1024 ) *  4096 - HOLEEND - NULLSTK);
*/
	} else {
		/* initialize free memory list */
		memlist.mnext = mptr = (struct mblock *) roundmb(&end);
		mptr->mnext = 0;
		mptr->mlen = (int) truncew((unsigned)maxaddr - (int)&end -
			NULLSTK);
	}
	

	for (i=0 ; i<NPROC ; i++)	/* initialize process table */
		proctab[i].pstate = PRFREE;


#ifdef	MEMMARK
	_mkinit();			/* initialize memory marking */
#endif

#ifdef	RTCLOCK
	clkinit();			/* initialize r.t.clock	*/
#endif

	mon_init();     /* init monitor */

#ifdef NDEVS
	for (i=0 ; i<NDEVS ; i++ ) {	    
	    init_dev(i);
	}
#endif

	pptr = &proctab[NULLPROC];	/* initialize null process entry */
	pptr->pstate = PRCURR;
	for (j=0; j<7; j++)
		pptr->pname[j] = "prnull"[j];
	pptr->plimit = (WORD)(maxaddr + 1) - NULLSTK;
	pptr->pbase = (WORD) maxaddr - 3;
/*
	pptr->plimit = (WORD)(maxaddr + 1) - NULLSTK - (4096 - 1024 )*4096;
	pptr->pbase = (WORD) maxaddr - 3 - (4096-1024)*4096;
*/
	pptr->pesp = pptr->pbase-4;	/* for stkchk; rewritten before used */
	*( (int *)pptr->pbase ) = MAGIC;
	pptr->paddr = (WORD) nulluser;
	pptr->pargs = 0;
	pptr->pprio = 0;
	currpid = NULLPROC;
	
	
	for (i=0 ; i<NSEM ; i++) {	/* initialize semaphores */
		(sptr = &semaph[i])->sstate = SFREE;
		sptr->sqtail = 1 + (sptr->sqhead = newqueue());
	}

	rdytail = 1 + (rdyhead=newqueue());/* initialize ready list */

	init_bsm();
	init_frm();

	kprintf("initialize page tables for null process\n");
	init_glb_pgs(glb_pg_tbl_frm_mapping);
	// init pg dir for proc 0
	frame_t *pg_dir = get_free_frame();
	init_pg_dir(pg_dir, NULLPROC);
	pptr->pdbr = pg_dir->frm_num;
	pptr->pd = pg_dir;
	return(OK);
}
Пример #24
0
int tc58128_init(struct SH7750State *s, const char *zone1, const char *zone2)
{
    init_dev(&tc58128_devs[0], zone1);
    init_dev(&tc58128_devs[1], zone2);
    return sh7750_register_io_device(s, &tc58128);
}
/*------------------------------------------------------------------------
 *  sysinit  --  initialize all Xinu data structeres and devices
 *------------------------------------------------------------------------
 */
LOCAL int sysinit()
{
	int	i,j;
	struct	pentry	*pptr;
	struct	sentry	*sptr;
	struct	mblock	*mptr;

	numproc = 0;			/* initialize system variables */
	nextproc = NPROC-1;
	nextsem = NSEM-1;
	nextqueue = NPROC;		/* q[0..NPROC-1] are processes */

	/* initialize free memory list */
	/* PC version has to pre-allocate 640K-1024K "hole" */
	if (maxaddr+1 > (char *)HOLESTART) {
		memlist.mnext = mptr = (struct mblock *) roundmb(&end);
		mptr->mnext = (struct mblock *)HOLEEND;
		mptr->mlen = (int) truncew(((unsigned) HOLESTART -
	     		 (unsigned)&end));
        mptr->mlen -= 4;

		mptr = (struct mblock *) HOLEEND;
		mptr->mnext = 0;
		mptr->mlen = (int) truncew((unsigned)maxaddr - HOLEEND -
	      		NULLSTK);
	} else {
		/* initialize free memory list */
		memlist.mnext = mptr = (struct mblock *) roundmb(&end);
		mptr->mnext = 0;
		mptr->mlen = (int) truncew((unsigned)maxaddr - (int)&end -
			NULLSTK);
	}
	

	for (i=0 ; i<NPROC ; i++)	/* initialize process table */
		proctab[i].pstate = PRFREE;

	pptr = &proctab[NULLPROC];	/* initialize null process entry */
	pptr->pstate = PRCURR;
	for (j=0; j<7; j++)
		pptr->pname[j] = "prnull"[j];
	pptr->plimit = (WORD)(maxaddr + 1) - NULLSTK;
	pptr->pbase = (WORD) maxaddr - 3;
	pptr->pesp = pptr->pbase-4;	/* for stkchk; rewritten before used */
	*( (int *)pptr->pbase ) = MAGIC;
	pptr->paddr = (WORD) nulluser;
	pptr->pargs = 0;
	pptr->pprio = 0;
	currpid = NULLPROC;

	for (i=0 ; i<NSEM ; i++) {	/* initialize semaphores */
		(sptr = &semaph[i])->sstate = SFREE;
		sptr->sqtail = 1 + (sptr->sqhead = newqueue());
	}

	rdytail = 1 + (rdyhead=newqueue());/* initialize ready list */

#ifdef	MEMMARK
	_mkinit();			/* initialize memory marking */
#endif

#ifdef	RTCLOCK
	clkinit();			/* initialize r.t.clock	*/
#endif

	pci_init();	/* PCI */

	mon_init();	/* init monitor */
//	ripinit();

#ifdef NDEVS
	for (i=0 ; i<NDEVS ; i++ ) {	    
	    init_dev(i);
	}
#endif
	buf_init();
	return(OK);
}
Пример #26
0
int main()
{

struct douban_radio* douban;
douban=(struct douban_radio*) malloc (sizeof(struct douban_radio));
memset(douban, 0, sizeof(struct douban_radio));

douban->channel=2;

douban_radio_playlist_load(douban);

int mp3_out = 0;
char com_temp[1];

init_dev(22050);
uart_fd = Uart_Init(uart_dev);

printf("douban channel %d \n", douban->channel);

while(1)													//主消息循环
{
	if(uart_read(uart_fd, protocol_buff, 1, 0) > 0)
	//if((mp3_out == 1) || (uart_read(uart_fd, protocol_buff, 1, 0) > 0))
	{
		//mp3_out = 0;
		//printf("get data\n");
		switch(protocol_buff[0])
		{	
			case COM_START:
				com_temp[0] = COM_END;
				write(uart_fd, com_temp, 1);
				break;
			case COM_TITLE:
				printf("send title!\n");
				send_title(uart_fd, douban);
				break;
			case COM_ARTIST:
				printf("send artist!\n");
				send_artist(uart_fd, douban);	
				break;
			case COM_JPG:
				printf("send jpg!\n");
				send_jpg(uart_fd, douban);
				break;
			case COM_PLAY:
				printf("douban channel %d \n", douban->channel);
				play_song(uart_fd, douban);
				//printf("play song1\n");
				//ice_mp3("http://190.220.157.52:8000");
				//mp3("/song1.mp3");
				//mp3_out = 1;								
				break;
			case NEW_LIST:
				load_list(uart_fd, douban);
			case COM_STOP:
				stop(uart_fd);
				printf("stop!\n");
				break;			
			default:
				break;
		}
	}
}

/*

int index;
struct douban_radio* douban;
douban=(struct douban_radio*) malloc (sizeof(struct douban_radio));
memset(douban, 0, sizeof(struct douban_radio));
douban->channel=2;

douban_radio_playlist_load(douban);
printf("items:\t%d\n",douban->size );
	for (index = 0; index < douban->size; index ++)
	{
		printf("picture: \t%s\n", douban->items[index].picture);
		printf("title  : \t%s\n", douban->items[index].title);
		printf("artist : \t%s\n", douban->items[index].artist);
		printf("url    : \t%s\n\n", douban->items[index].url);
		printf("index %d \n", index);
	}

free(douban);
printf("\n\n\n\n\n");


douban=(struct douban_radio*) malloc (sizeof(struct douban_radio));
memset(douban, 0, sizeof(struct douban_radio));
douban->channel=2;
douban_radio_playlist_load(douban);
//load_list(douban);


printf("items:\t%d\n",douban->size );
	for (index = 0; index < douban->size; index ++)
	{
		printf("picture: \t%s\n", douban->items[index].picture);
		printf("title  : \t%s\n", douban->items[index].title);
		printf("artist : \t%s\n", douban->items[index].artist);
		printf("url    : \t%s\n\n", douban->items[index].url);
		printf("index %d \n", index);
	}
*/

return 0;



}
Пример #27
0
/*
 * Read in the information about files used in making the system.
 * Store it in the ftab linked list.
 */
static void
read_files(void)
{
	FILE *fp;
	struct file_list *tp, *pf;
	struct device *dp;
	struct device *save_dp;
	struct opt *op;
	char *wd, *this, *needs, *special, *depends, *clean, *warning;
	char fname[MAXPATHLEN];
	int nonoptional;
	int nreqs, first = 1, configdep, isdup, std, filetype,
	    imp_rule, no_obj, before_depend, nowerror, mandatory;

	ftab = 0;
	save_dp = NULL;
	if (ident == NULL) {
		printf("no ident line specified\n");
		exit(1);
	}
	snprintf(fname, sizeof(fname), "../conf/files");
openit:
	fp = fopen(fname, "r");
	if (fp == NULL)
		err(1, "%s", fname);
next:
	/*
	 * filename    [ standard | mandatory | optional ] [ config-dependent ]
	 *	[ dev* | profiling-routine ] [ no-obj ]
	 *	[ compile-with "compile rule" [no-implicit-rule] ]
	 *      [ dependency "dependency-list"] [ before-depend ]
	 *	[ clean "file-list"] [ warning "text warning" ]
	 */
	wd = get_word(fp);
	if (wd == (char *)EOF) {
		fclose(fp);
		if (first == 1) {
			first++;
			snprintf(fname, sizeof(fname),
			    "../platform/%s/conf/files",
			    platformname);
			fp = fopen(fname, "r");
			if (fp != NULL)
				goto next;
			snprintf(fname, sizeof(fname),
			    "files.%s", platformname);
			goto openit;
		}
		if (first == 2) {
			first++;
			snprintf(fname, sizeof(fname),
			    "files.%s", raisestr(ident));
			fp = fopen(fname, "r");
			if (fp != NULL)
				goto next;
		}
		return;
	}
	if (wd == 0)
		goto next;
	if (wd[0] == '#')
	{
		while (((wd = get_word(fp)) != (char *)EOF) && wd)
			;
		goto next;
	}
	this = strdup(wd);
	next_word(fp, wd);
	if (wd == 0) {
		printf("%s: No type for %s.\n",
		    fname, this);
		exit(1);
	}
	if ((pf = fl_lookup(this)) && (pf->f_type != INVISIBLE || pf->f_flags))
		isdup = 1;
	else
		isdup = 0;
	tp = 0;
	if (first == 3 && pf == NULL && (tp = fltail_lookup(this)) != NULL) {
		if (tp->f_type != INVISIBLE || tp->f_flags)
			printf("%s: Local file %s overrides %s.\n",
			    fname, this, tp->f_fn);
		else
			printf("%s: Local file %s could override %s"
			    " with a different kernel configuration.\n",
			    fname, this, tp->f_fn);
	}
	nreqs = 0;
	special = NULL;
	depends = NULL;
	clean = NULL;
	warning = NULL;
	configdep = 0;
	needs = NULL;
	std = mandatory = nonoptional = 0;
	imp_rule = 0;
	no_obj = 0;
	before_depend = 0;
	nowerror = 0;
	filetype = NORMAL;
	if (strcmp(wd, "standard") == 0) {
		std = 1;
	} else if (strcmp(wd, "mandatory") == 0) {
		/*
		 * If an entry is marked "mandatory", config will abort if 
		 * it's not called by a configuration line in the config
		 * file.  Apart from this, the device is handled like one
		 * marked "optional".
		 */
		mandatory = 1;
	} else if (strcmp(wd, "nonoptional") == 0) {
		nonoptional = 1;
	} else if (strcmp(wd, "optional") == 0) {
		/* don't need to do anything */
	} else {
		printf("%s: %s must be optional, mandatory or standard\n",
		       fname, this);
		printf("Alternatively, your version of config(8) may be out of sync with your\nkernel source.\n");
		exit(1);
	}
nextparam:
	next_word(fp, wd);
	if (wd == NULL)
		goto doneparam;
	if (strcmp(wd, "config-dependent") == 0) {
		configdep++;
		goto nextparam;
	}
	if (strcmp(wd, "no-obj") == 0) {
		no_obj++;
		goto nextparam;
	}
	if (strcmp(wd, "no-implicit-rule") == 0) {
		if (special == NULL) {
			printf("%s: alternate rule required when "
			       "\"no-implicit-rule\" is specified.\n",
			       fname);
		}
		imp_rule++;
		goto nextparam;
	}
	if (strcmp(wd, "before-depend") == 0) {
		before_depend++;
		goto nextparam;
	}
	if (strcmp(wd, "dependency") == 0) {
		next_quoted_word(fp, wd);
		if (wd == NULL) {
			printf("%s: %s missing compile command string.\n",
			       fname, this);
			exit(1);
		}
		depends = strdup(wd);
		goto nextparam;
	}
	if (strcmp(wd, "clean") == 0) {
		next_quoted_word(fp, wd);
		if (wd == NULL) {
			printf("%s: %s missing clean file list.\n",
			       fname, this);
			exit(1);
		}
		clean = strdup(wd);
		goto nextparam;
	}
	if (strcmp(wd, "compile-with") == 0) {
		next_quoted_word(fp, wd);
		if (wd == NULL) {
			printf("%s: %s missing compile command string.\n",
			       fname, this);
			exit(1);
		}
		special = strdup(wd);
		goto nextparam;
	}
	if (strcmp(wd, "nowerror") == 0) {
		nowerror++;
		goto nextparam;
	}
	if (strcmp(wd, "warning") == 0) {
		next_quoted_word(fp, wd);
		if (wd == NULL) {
			printf("%s: %s missing warning text string.\n",
				fname, this);
			exit(1);
		}
		warning = strdup(wd);
		goto nextparam;
	}
	nreqs++;
	if (strcmp(wd, "local") == 0) {
		filetype = LOCAL;
		goto nextparam;
	}
	if (strcmp(wd, "no-depend") == 0) {
		filetype = NODEPEND;
		goto nextparam;
	}
	if (strcmp(wd, "device-driver") == 0) {
		printf("%s: `device-driver' flag obsolete.\n", fname);
		exit(1);
	}
	if (strcmp(wd, "profiling-routine") == 0) {
		filetype = PROFILING;
		goto nextparam;
	}
	if (needs == 0 && nreqs == 1)
		needs = strdup(wd);
	if (isdup)
		goto invis;
	for (dp = dtab; dp != NULL; save_dp = dp, dp = dp->d_next)
		if (strcmp(dp->d_name, wd) == 0) {
			if (std && dp->d_type == PSEUDO_DEVICE &&
			    dp->d_count <= 0)
				dp->d_count = 1;
			goto nextparam;
		}
	if (mandatory) {
		printf("%s: mandatory device \"%s\" not found\n",
		       fname, wd);
		exit(1);
	}
	if (std) {
		dp = malloc(sizeof(*dp));
		bzero(dp, sizeof(*dp));
		init_dev(dp);
		dp->d_name = strdup(wd);
		dp->d_type = PSEUDO_DEVICE;
		dp->d_count = 1;
		save_dp->d_next = dp;
		goto nextparam;
	}
	for (op = opt; op != NULL; op = op->op_next) {
		if (op->op_value == 0 && opteq(op->op_name, wd)) {
			if (nreqs == 1) {
				free(needs);
				needs = NULL;
			}
			goto nextparam;
		}
	}
	if (nonoptional) {
		printf("%s: the option \"%s\" MUST be specified\n",
			fname, wd);
		exit(1);
	}
invis:
	while ((wd = get_word(fp)) != 0)
		;
	if (tp == NULL)
		tp = new_fent();
	tp->f_fn = this;
	tp->f_type = INVISIBLE;
	tp->f_needs = needs;
	tp->f_flags = isdup;
	tp->f_special = special;
	tp->f_depends = depends;
	tp->f_clean = clean;
	tp->f_warn = warning;
	goto next;

doneparam:
	if (std == 0 && nreqs == 0) {
		printf("%s: what is %s optional on?\n",
		    fname, this);
		exit(1);
	}

	if (wd != NULL) {
		printf("%s: syntax error describing %s\n",
		    fname, this);
		exit(1);
	}
	if (filetype == PROFILING && profiling == 0)
		goto next;
	if (tp == NULL)
		tp = new_fent();
	tp->f_fn = this;
	tp->f_type = filetype;
	tp->f_flags = 0;
	if (configdep)
		tp->f_flags |= CONFIGDEP;
	if (imp_rule)
		tp->f_flags |= NO_IMPLCT_RULE;
	if (no_obj)
		tp->f_flags |= NO_OBJ;
	if (before_depend)
		tp->f_flags |= BEFORE_DEPEND;
	if (nowerror)
		tp->f_flags |= NOWERROR;
	if (imp_rule)
		tp->f_flags |= NO_IMPLCT_RULE;
	if (no_obj)
		tp->f_flags |= NO_OBJ;
	tp->f_needs = needs;
	tp->f_special = special;
	tp->f_depends = depends;
	tp->f_clean = clean;
	tp->f_warn = warning;
	if (pf && pf->f_type == INVISIBLE)
		pf->f_flags = 1;		/* mark as duplicate */
	goto next;
}
Пример #28
0
static int gotemp_probe(struct usb_interface *interface,
			const struct usb_device_id *id)
{
	struct usb_device *udev = interface_to_usbdev(interface);
	struct gotemp *gdev = NULL;
	int retval = -ENOMEM;
	int i;
	struct usb_host_interface *iface_desc;
	struct usb_endpoint_descriptor *endpoint = NULL;
	size_t buffer_size = 0;

	gdev = kzalloc(sizeof(struct gotemp), GFP_KERNEL);
	if (gdev == NULL) {
		dev_err(&interface->dev, "Out of memory\n");
		goto error;
	}

	gdev->udev = usb_get_dev(udev);

	/* find the one control endpoint of this device */
	iface_desc = interface->cur_altsetting;
	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
		endpoint = &iface_desc->endpoint[i].desc;

		if (usb_endpoint_is_int_in(endpoint)) {
			buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
			gdev->int_in_endpointAddr = endpoint->bEndpointAddress;
			gdev->int_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
			if (!gdev->int_in_buffer) {
				dev_err(&interface->dev,
					"Could not allocate buffer");
				goto error;
			}
			break;
		}
	}
	if (!gdev->int_in_endpointAddr) {
		dev_err(&interface->dev, "Could not find int-in endpoint");
		retval = -ENODEV;
		goto error;
	}

	gdev->int_in_urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!gdev->int_in_urb) {
		dev_err(&interface->dev, "No free urbs available\n");
		goto error;
	}
	usb_fill_int_urb(gdev->int_in_urb, udev,
			 usb_rcvintpipe(udev,
					endpoint->bEndpointAddress),
			 gdev->int_in_buffer, buffer_size,
			 read_int_callback, gdev,
			 endpoint->bInterval);

	usb_set_intfdata(interface, gdev);

	init_dev(gdev);

	/*
	 * this must come last - after this call the device is active
	 * if we delayed any initialization until after this, the user
	 * would read garbage
	 */
	retval = device_create_file(&interface->dev, &dev_attr_temperature);
	if (retval)
		goto error;

	dev_info(&interface->dev, "USB GoTemp device now attached\n");
	return 0;

error:
	usb_set_intfdata(interface, NULL);
	if (gdev) {
		usb_free_urb(gdev->int_in_urb);
		kfree(gdev->int_in_buffer);
	}
	kfree(gdev);
	return retval;
}
Пример #29
0
void *device_initialization(void *arg)
{
   DEVRES *device;
   DCR *dcr;
   JCR *jcr;
   DEVICE *dev;
   int errstat;

   LockRes();

   pthread_detach(pthread_self());
   jcr = new_jcr(sizeof(JCR), stored_free_jcr);
   new_plugins(jcr);  /* instantiate plugins */
   jcr->setJobType(JT_SYSTEM);

   /*
    * Initialize job start condition variable
    */
   errstat = pthread_cond_init(&jcr->job_start_wait, NULL);
   if (errstat != 0) {
      berrno be;
      Jmsg1(jcr, M_ABORT, 0, _("Unable to init job start cond variable: ERR=%s\n"), be.bstrerror(errstat));
   }

   /*
    * Initialize job end condition variable
    */
   errstat = pthread_cond_init(&jcr->job_end_wait, NULL);
   if (errstat != 0) {
      berrno be;
      Jmsg1(jcr, M_ABORT, 0, _("Unable to init job endstart cond variable: ERR=%s\n"), be.bstrerror(errstat));
   }

   foreach_res(device, R_DEVICE) {
      Dmsg1(90, "calling init_dev %s\n", device->device_name);
      dev = init_dev(NULL, device);
      Dmsg1(10, "SD init done %s\n", device->device_name);
      if (!dev) {
         Jmsg1(NULL, M_ERROR, 0, _("Could not initialize %s\n"), device->device_name);
         continue;
      }

      jcr->dcr = dcr = new_dcr(jcr, NULL, dev, NULL);
      generate_plugin_event(jcr, bsdEventDeviceInit, dcr);
      if (dev->is_autochanger()) {
         /* If autochanger set slot in dev structure */
         get_autochanger_loaded_slot(dcr);
      }

      if (device->cap_bits & CAP_ALWAYSOPEN) {
         Dmsg1(20, "calling first_open_device %s\n", dev->print_name());
         if (!first_open_device(dcr)) {
            Jmsg1(NULL, M_ERROR, 0, _("Could not open device %s\n"), dev->print_name());
            Dmsg1(20, "Could not open device %s\n", dev->print_name());
            free_dcr(dcr);
            jcr->dcr = NULL;
            continue;
         }
      }

      if (device->cap_bits & CAP_AUTOMOUNT && dev->is_open()) {
         switch (read_dev_volume_label(dcr)) {
         case VOL_OK:
            memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
            volume_unused(dcr);             /* mark volume "released" */
            break;
         default:
            Jmsg1(NULL, M_WARNING, 0, _("Could not mount device %s\n"), dev->print_name());
            break;
         }
      }
      free_dcr(dcr);
      jcr->dcr = NULL;
   }
Пример #30
0
int
process_cgi (struct ushare_t *ut, char *cgiargs)
{
  char *action = NULL;
  int refresh = 0;

  if (!ut || !cgiargs)
    return -1;

  if (strncmp (cgiargs, CGI_ACTION, strlen (CGI_ACTION)))
    return -1;

  action = cgiargs + strlen (CGI_ACTION);

  if (!strncmp (action, CGI_ACTION_ADD, strlen (CGI_ACTION_ADD)))
  {
    char *path = NULL;
    path = action + strlen (CGI_ACTION_ADD) + 1;

    if (path && !strncmp (path, CGI_PATH"=", strlen (CGI_PATH) + 1))
    {
      ut->contentlist = content_add (ut->contentlist,
                                     path + strlen (CGI_PATH) + 1);
      refresh = 1;
    }
  }
  else if (!strncmp (action, CGI_ACTION_DEL, strlen (CGI_ACTION_DEL)))
  {
    char *shares,*share;
    char *m_buffer = NULL, *buffer;
    int num, shift=0;

    shares = strdup (action + strlen (CGI_ACTION_DEL) + 1);
    m_buffer = (char*) malloc (strlen (shares) * sizeof (char));
    if (m_buffer)
    {
      buffer = m_buffer;
      for (share = strtok_r (shares, "&", &buffer) ; share ;
           share = strtok_r (NULL, "&", &buffer))
      {
        if (sscanf (share, CGI_SHARE"[%d]=on", &num) < 0)
          continue;
        ut->contentlist = content_del (ut->contentlist, num - shift++);
      }
      free (m_buffer);
    }

    refresh = 1;
    free (shares);
  }
  else if (!strncmp (action, CGI_ACTION_REFRESH, strlen (CGI_ACTION_REFRESH)))
    refresh = 1;
  else if (!strncmp (action, CGI_WebCam_Start, strlen (CGI_WebCam_Start)))
  {
  	  extern pthread_mutex_t grab_ctrl_mutex;
  	  extern pthread_cond_t grab_ctrl_cond;
	  if( videoIn.cameraname == NULL )
	  {
	  	if( init_dev(WebCam_DEV, 0)== 0)
	  	{
			pthread_mutex_lock (&grab_ctrl_mutex);
			pthread_cond_signal (&grab_ctrl_cond);
			pthread_mutex_unlock (&grab_ctrl_mutex);
			capFlag = 1;capOK = 0;
	  	}
	  	else
	  	{
	  		close_v4l(&videoIn);
	  		memset (&videoIn, 0, sizeof (struct vdIn));
	  		capFlag = 0;capOK = 1;
	  	}
  	  }
  	  else
  	  {
  	  		pthread_mutex_lock (&grab_ctrl_mutex);
			pthread_cond_signal (&grab_ctrl_cond);
			pthread_mutex_unlock (&grab_ctrl_mutex);
			capFlag = 1;capOK = 0;
  	  }
  	
  }
  else if (!strncmp (action, CGI_WebCam_Stop, strlen (CGI_WebCam_Stop)))
  {
  	extern int webcam_exit_flag,Pic_exit_flag, Mov_exit_flag;
  	extern pthread_mutex_t Pic_mutex,Mov_mutex;
  	extern pthread_cond_t Mov_cond,Pic_cond;
  	capFlag = 0;
  	if( videoIn.cameraname != NULL )
  	{
		 webcam_exit_flag = 1;
		 if( Pic_exit_flag == 1 )
		 {
		 	pthread_mutex_lock (&Pic_mutex);
			pthread_cond_signal (&Pic_cond);
			pthread_mutex_unlock (&Pic_mutex);
		 }
		 else
		 	Pic_exit_flag = 1;
		 if( Mov_exit_flag == 1 )
		 {
		 	pthread_mutex_lock (&Mov_mutex);
			pthread_cond_signal (&Mov_cond);
			pthread_mutex_unlock (&Mov_mutex);
		 }
		 else
		 	Mov_exit_flag = 1;
	}
  	
  }
  extern int scanDir_flag;
  if (refresh && ut->contentlist && !scanDir_flag)
  {
  	scanDir_flag = 1;
    free_metadata_list (ut);
    build_metadata_list (ut);
    scanDir_flag = 0;
  }

  if (ut->presentation)
    buffer_free (ut->presentation);
  ut->presentation = buffer_new ();

  buffer_append (ut->presentation, "<html>");
  buffer_append (ut->presentation, "<head>");
  buffer_appendf (ut->presentation, "<title>%s</title>",
                  _("uShare Information Page"));
  buffer_append (ut->presentation,
                 "<meta http-equiv=\"pragma\" content=\"no-cache\"/>");
  buffer_append (ut->presentation,
                 "<meta http-equiv=\"expires\" content=\"1970-01-01\"/>");
  buffer_append (ut->presentation,
                 "<meta http-equiv=\"refresh\" content=\"0; URL=/web/ushare.html\"/>");
  buffer_append (ut->presentation, "</head>");
  buffer_append (ut->presentation, "</html>");

  return 0;
}