int select_unique_device(char *device, char *name) { char devices[8][ADHOC_BUFFER_SIZE], names[8][ADHOC_BUFFER_SIZE]; int r = scan_devices(devices, names, 8); if (r < 0) { perror("select_devices failed"); return r; } if (r == 0) { fprintf(stderr, "No supported device found! Do you have access right?\n"); return -1; } if (r > 1) { fprintf(stderr, "Multiple supported devices found! Which one should we open?\n"); for (int i = 0; i != r; ++i) fprintf(stderr, "%s: %s", devices[i], names[i]); return -1; } strcpy(device, devices[0]); if (name != NULL) strcpy(name, names[0]); return 0; }
int do_rescan(struct params_t *params) { int i; /* Clean top menu level except system menu item */ /* FIXME should be done by some function from menu module */ kx_menu_item *mi; for (i = 1; i < params->menu->top->count; i++) { mi = params->menu->top->list[i]; if (mi) { dispose(mi->label); dispose(mi->description); free(mi); } params->menu->top->list[i] = NULL; } params->menu->top->count = 1; #ifdef USE_ICONS /* Destroy icons */ /* FIXME should be done by some function from devicescan module */ for (i = 0; i < params->bootcfg->fill; i++) { fb_destroy_picture(params->bootcfg->list[i]->icondata); } #endif free_bootcfg(params->bootcfg); params->bootcfg = NULL; scan_devices(params); return fill_menu(params); }
/* * Init function for virtio * devices are in a single page above top of "normal" mem */ static int __init kvm_devices_init(void) { int rc; if (!MACHINE_IS_KVM) return -ENODEV; kvm_root = root_device_register("kvm_s390"); if (IS_ERR(kvm_root)) { rc = PTR_ERR(kvm_root); printk(KERN_ERR "Could not register kvm_s390 root device"); return rc; } rc = vmem_add_mapping(real_memory_size, PAGE_SIZE); if (rc) { root_device_unregister(kvm_root); return rc; } kvm_devices = (void *) real_memory_size; INIT_WORK(&hotplug_work, hotplug_devices); service_subclass_irq_register(); register_external_interrupt(0x2603, kvm_extint_handler); scan_devices(); return 0; }
static int start_input(srs_plugin_t *plugin) { context_t *ctx = (context_t *)plugin->plugin_data; mrp_log_info("starting input plugin"); if (ctx->key) { scan_devices(ctx); } return TRUE; }
/*D:105 Fairly early in boot, lguest_devices_init() is called to set up the * lguest device infrastructure. We check that we are a Guest by checking * pv_info.name: there are other ways of checking, but this seems most * obvious to me. * * So we can access the "struct lguest_device_desc"s easily, we map that memory * and store the pointer in the global "lguest_devices". Then we register a * root device from which all our devices will hang (this seems to be the * correct sysfs incantation). * * Finally we call scan_devices() which adds all the devices found in the * lguest_devices page. */ static int __init lguest_devices_init(void) { if (strcmp(pv_info.name, "lguest") != 0) return 0; if (device_register(&lguest_root) != 0) panic("Could not register lguest root"); /* Devices are in a single page above top of "normal" mem */ lguest_devices = lguest_map(max_pfn<<PAGE_SHIFT, 1); scan_devices(); return 0; }
int main(int argc, char *argv[]) { /* Link to event server */ // memsection_lookup(iguana_getenv(0x90b), &server_); // event_server = thread_l4tid(server_); //Set up any system drivers that we may link against scan_devices(); devicecore_server_loop(); }
static int do_capture(const char *device) { int fd; char *filename; if (!device) { fprintf(stderr, "No device specified, trying to scan all of %s/%s*\n", DEV_INPUT_EVENT, EVENT_DEV_NAME); if (getuid() != 0) fprintf(stderr, "Not running as root, no devices may be available.\n"); filename = scan_devices(); if (!filename) return usage(); } else filename = strdup(device); if (!filename) return EXIT_FAILURE; if ((fd = open(filename, O_RDONLY)) < 0) { perror("evtest"); if (errno == EACCES && getuid() != 0) fprintf(stderr, "You do not have access to %s. Try " "running as root instead.\n", filename); return EXIT_FAILURE; } free(filename); if (!isatty(fileno(stdout))) setbuf(stdout, NULL); if (test_grab(fd)) { return 0; } return print_events(fd); }
/* * Init function for virtio. * devices are in a single page above the top of "normal" mem. */ static int __init kvm_devices_init(void) { int rc = -ENOMEM; kvm_root = root_device_register("kvm_tile"); if (IS_ERR(kvm_root)) { rc = PTR_ERR(kvm_root); pr_err("Could not register kvm_tile root device"); return rc; } kvm_devices = generic_remap_prot(PFN_PHYS(max_pfn), PAGE_SIZE, 0, io_prot()); if (!kvm_devices) { kvm_devices = NULL; root_device_unregister(kvm_root); return rc; } scan_devices(); return 0; }
int main () { int fd, grabbed; char *filename; if (getuid() != 0) { fprintf(stderr, "Not running as root, no devices may be available.\n"); } filename = scan_devices(); if (!filename) { fprintf(stderr, "Device not found\n"); return EXIT_FAILURE; } if ((fd = open(filename, O_RDONLY)) < 0) { perror(""); if (errno == EACCES && getuid() != 0) { fprintf(stderr, "You do not have access to %s. Try " "running as root instead.\n", filename); } return EXIT_FAILURE; } free(filename); if (print_device_info(fd)) { return EXIT_FAILURE; } grabbed = ioctl(fd, EVIOCGRAB, (void *) 1); ioctl(fd, EVIOCGRAB, (void *) 0); if (grabbed) { printf("This device is grabbed by another process. Try switching VT.\n"); return EXIT_FAILURE; } return print_events(fd); }
int /* O - Exit status */ main(int argc, /* I - Number of command-line arguments (6 or 7) */ char *argv[]) /* I - Command-line arguments */ { int ipv4, /* SNMP IPv4 socket */ ipv6; /* SNMP IPv6 socket */ #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET) struct sigaction action; /* Actions for POSIX signals */ #endif /* HAVE_SIGACTION && !HAVE_SIGSET */ /* * Check command-line options... */ if (argc > 2) { _cupsLangPuts(stderr, _("Usage: snmp [host-or-ip-address]")); return (1); } /* * Set the password callback for IPP operations... */ cupsSetPasswordCB(password_cb); /* * Catch SIGALRM signals... */ #ifdef HAVE_SIGSET sigset(SIGALRM, alarm_handler); #elif defined(HAVE_SIGACTION) memset(&action, 0, sizeof(action)); sigemptyset(&action.sa_mask); sigaddset(&action.sa_mask, SIGALRM); action.sa_handler = alarm_handler; sigaction(SIGALRM, &action, NULL); #else signal(SIGALRM, alarm_handler); #endif /* HAVE_SIGSET */ /* * Open the SNMP socket... */ if ((ipv4 = _cupsSNMPOpen(AF_INET)) < 0) return (1); #ifdef AF_INET6 if ((ipv6 = _cupsSNMPOpen(AF_INET6)) < 0) perror("DEBUG: Unable to create IPv6 socket"); #else ipv6 = -1; #endif /* AF_INET6 */ /* * Read the configuration file and any cache data... */ read_snmp_conf(argv[1]); _cupsSNMPSetDebug(DebugLevel); Devices = cupsArrayNew((cups_array_func_t)compare_cache, NULL); /* * Scan for devices... */ scan_devices(ipv4, ipv6); /* * Close, free, and return with no errors... */ _cupsSNMPClose(ipv4); if (ipv6 >= 0) _cupsSNMPClose(ipv6); free_array(Addresses); free_array(Communities); free_cache(); return (0); }
/* * The main ! */ int main(int argc, char ** argv) { int skfd = -1; /* generic raw socket desc. */ int format = FORMAT_DEFAULT; int ret = -1; /* Create a channel to the NET kernel. */ if((skfd = sockets_open()) < 0) { perror("socket"); return(-1); } /* No argument */ if(argc == 1) { /* Look on all devices */ ret = scan_devices(skfd, format); close(skfd); return(ret); } /* Only ask for first AP address */ if((!strcmp(argv[1], "--ap")) || (!strcmp(argv[1], "-a"))) { /* Look on all devices */ ret = scan_ap(skfd, format); close(skfd); return(ret); } /* Only the format, no interface name */ if((!strncmp(argv[1], "--scheme", 4)) || (!strcmp(argv[1], "-s"))) { /* Look on all devices */ format = FORMAT_SCHEME; ret = scan_devices(skfd, format); close(skfd); return(ret); } /* Help */ if((argc > 3) || (!strncmp(argv[1], "-h", 9)) || (!strcmp(argv[1], "--help"))) { fprintf(stderr, "Usage: iwgetid [interface]\n"); fprintf(stderr, " [interface] --scheme\n"); return(-1); } /* If at least a device name */ if(argc > 1) { /* Check extra format argument */ if(argc > 2) { /* Only ask for first AP address */ if((!strcmp(argv[2], "--ap")) || (!strcmp(argv[2], "-a"))) { ret = print_ap(skfd, argv[1], format); close(skfd); return(ret); } /* Want scheme format */ if((!strncmp(argv[2], "--scheme", 4)) || (!strcmp(argv[2], "-s"))) format = FORMAT_SCHEME; } /* Try to print an ESSID */ ret = print_essid(skfd, argv[1], format); if(ret == -1) { /* Try to print a nwid */ ret = print_nwid(skfd, argv[1], format); } } /* Close the socket. */ close(skfd); return(ret); }
int main(void) { scan_devices(); devicecore_server_loop(); }
int main(int argc, char **argv) { int rc = 0; struct cfgdata_t cfg; struct params_t params; kx_inputs inputs; lg = log_open(16); log_msg(lg, "%s starting", PACKAGE_STRING); initmode = do_init(); /* Get cmdline parameters */ params.cfg = &cfg; init_cfgdata(&cfg); cfg.angle = 0; /* No rotation by default */ parse_cmdline(&cfg); kxb_ttydev = cfg.ttydev; setup_terminal(kxb_ttydev, &kxb_echo_state, 1); /* Setup function that will restore terminal when exit() will called */ atexit(atexit_restore_terminal); log_msg(lg, "FB angle is %d, tty is %s", cfg.angle, cfg.ttydev); #ifdef USE_MACHINE_KERNEL machine_kernel = get_machine_kernelpath(); /* FIXME should be passed as arg to get_bootinfo() */ #endif #ifdef USE_DELAY /* extra delay for initializing slow SD/CF */ sleep(USE_DELAY); #endif int no_ui = 1; /* UI presence flag */ #ifdef USE_FBMENU params.gui = NULL; if (no_ui) { params.gui = gui_init(cfg.angle); if (NULL == params.gui) { log_msg(lg, "Can't initialize GUI"); } else no_ui = 0; } #endif #ifdef USE_TEXTUI FILE *ttyfp; params.tui = NULL; if (no_ui) { if (cfg.ttydev) ttyfp = fopen(cfg.ttydev, "w"); else ttyfp = stdout; params.tui = tui_init(ttyfp); if (NULL == params.tui) { log_msg(lg, "Can't initialize TUI"); if (ttyfp != stdout) fclose(ttyfp); } else no_ui = 0; } #endif if (no_ui) exit(-1); /* Exit if no one UI was initialized */ params.menu = build_menu(¶ms); params.bootcfg = NULL; scan_devices(¶ms); if (-1 == fill_menu(¶ms)) { exit(-1); } /* Collect input devices */ inputs_init(&inputs, 8); inputs_open(&inputs); inputs_preprocess(&inputs); /* Run main event loop * Return values: <0 - error, >=0 - selected item id */ rc = do_main_loop(¶ms, &inputs); #ifdef USE_FBMENU if (params.gui) { if (rc < 0) gui_clear(params.gui); gui_destroy(params.gui); } #endif #ifdef USE_TEXTUI if (params.tui) { tui_destroy(params.tui); if (ttyfp != stdout) fclose(ttyfp); } #endif inputs_close(&inputs); inputs_clean(&inputs); log_close(lg); lg = NULL; /* rc < 0 indicate error */ if (rc < 0) exit(rc); menu_destroy(params.menu, 0); if (rc >= A_DEVICES) { start_kernel(¶ms, rc - A_DEVICES); } /* When we reach this point then some error has occured */ DPRINTF("We should not reach this point!"); exit(-1); }
/* * The main ! */ int main(int argc, char ** argv) { int skfd; /* generic raw socket desc. */ int format = FORMAT_DEFAULT; int wtype = WTYPE_ESSID; int opt; int ret = -1; /* Check command line arguments */ while((opt = getopt_long(argc, argv, "acfhmprs", long_opts, NULL)) > 0) { switch(opt) { case 'a': /* User wants AP/Cell Address */ wtype = WTYPE_AP; break; case 'c': /* User wants channel only */ wtype = WTYPE_CHANNEL; break; case 'f': /* User wants frequency/channel */ wtype = WTYPE_FREQ; break; case 'm': /* User wants the mode */ wtype = WTYPE_MODE; break; case 'p': /* User wants the protocol */ wtype = WTYPE_PROTO; break; case 'h': iw_usage(0); break; case 'r': /* User wants a Raw format */ format = FORMAT_RAW; break; case 's': /* User wants a Scheme format */ format = FORMAT_SCHEME; break; default: iw_usage(1); break; } } if(optind + 1 < argc) { fputs("Too many arguments.\n", stderr); iw_usage(1); } /* Create a channel to the NET kernel. */ if((skfd = iw_sockets_open()) < 0) { perror("socket"); return(-1); } /* Check if first argument is a device name */ if(optind < argc) { /* Yes : query only this device */ ret = print_one_device(skfd, format, wtype, argv[optind]); } else { /* No : query all devices and print first found */ ret = scan_devices(skfd, format, wtype); } fflush(stdout); iw_sockets_close(skfd); return(ret); }