int main(int argc, char *argv[]) { int fd; int err; prop_dictionary_t dict_in, dict_out; struct plistref prefp; char *xml; err = rump_init(); if (err != 0) printf("rump_init failed with %s\n", strerror(err)); fd = rump_sys_open("/dev/mapper/control", O_RDWR, 0); if (fd == -1) printf("Cannot open control device.\n"); dict_in = prop_dictionary_internalize_from_file("prop2.plist"); dict_out = prop_dictionary_create(); prop_dictionary_externalize_to_pref(dict_in, &prefp); err = rump_sys_ioctl(fd, NETBSD_DM_IOCTL, &prefp); if ( err < 0) printf("ioctl failed %d\n", err); dict_out = prop_dictionary_internalize(prefp.pref_plist); xml = prop_dictionary_externalize(dict_out); printf("%s\n",xml); rump_sys_close(fd); }
int main(int argc, char **argv) { modctl_load_t cmdargs; prop_dictionary_t props; char *propsstr; int ch; int flags; flags = 0; props = prop_dictionary_create(); while ((ch = getopt(argc, argv, "b:fi:s:")) != -1) { switch (ch) { case 'b': parse_param(props, optarg, parse_bool_param); break; case 'f': flags |= MODCTL_LOAD_FORCE; break; case 'i': parse_param(props, optarg, parse_int_param); break; case 's': parse_param(props, optarg, parse_string_param); break; default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; if (argc != 1) usage(); propsstr = prop_dictionary_externalize(props); if (propsstr == NULL) errx(EXIT_FAILURE, "Failed to process properties"); cmdargs.ml_filename = argv[0]; cmdargs.ml_flags = flags; cmdargs.ml_props = propsstr; cmdargs.ml_propslen = strlen(propsstr); if (modctl(MODCTL_LOAD, &cmdargs)) { err(EXIT_FAILURE, NULL); } free(propsstr); prop_object_release(props); exit(EXIT_SUCCESS); }
void * npf_rule_export(nl_rule_t *rl, size_t *length) { prop_dictionary_t rldict = rl->nrl_dict; void *xml; if ((xml = prop_dictionary_externalize(rldict)) == NULL) { return NULL; } *length = strlen(xml); return xml; }
static void dispatch_power_event_state_change(int fd, power_event_t *pev) { prop_dictionary_t dict; prop_object_t obj; const char *argv[6]; char *buf = NULL; int error; error = prop_dictionary_recv_ioctl(fd, POWER_EVENT_RECVDICT, &dict); if (error) { if (debug) printf("%s: prop_dictionary_recv_ioctl error=%d\n", __func__, error); return; } if (debug) { buf = prop_dictionary_externalize(dict); printf("%s", buf); free(buf); } obj = prop_dictionary_get(dict, "powerd-script-name"); argv[0] = prop_string_cstring_nocopy(obj); obj = prop_dictionary_get(dict, "driver-name"); argv[1] = prop_string_cstring_nocopy(obj); obj = prop_dictionary_get(dict, "powerd-event-name"); argv[2] = prop_string_cstring_nocopy(obj); obj = prop_dictionary_get(dict, "sensor-name"); argv[3] = prop_string_cstring_nocopy(obj); obj = prop_dictionary_get(dict, "state-description"); argv[4] = prop_string_cstring_nocopy(obj); argv[5] = NULL; run_script(argv); }
/* * Attach the mainbus. */ void mainbus_attach(device_t parent, device_t self, void *aux) { union mainbus_attach_args mba; struct confargs ca; #if NPCI > 0 struct genppc_pci_chipset_businfo *pbi; #ifdef PCI_NETBSD_CONFIGURE struct extent *ioext, *memext; #endif #endif mainbus_found = 1; aprint_normal("\n"); #if defined(RESIDUAL_DATA_DUMP) print_residual_device_info(); #endif /* * Always find the CPU */ ca.ca_name = "cpu"; ca.ca_node = 0; config_found_ia(self, "mainbus", &ca, mainbus_print); ca.ca_name = "cpu"; ca.ca_node = 1; config_found_ia(self, "mainbus", &ca, mainbus_print); /* * XXX Note also that the presence of a PCI bus should * XXX _always_ be checked, and if present the bus should be * XXX 'found'. However, because of the structure of the code, * XXX that's not currently possible. */ #if NPCI > 0 genppc_pct = malloc(sizeof(struct genppc_pci_chipset), M_DEVBUF, M_NOWAIT); KASSERT(genppc_pct != NULL); bebox_pci_get_chipset_tag(genppc_pct); pbi = malloc(sizeof(struct genppc_pci_chipset_businfo), M_DEVBUF, M_NOWAIT); KASSERT(pbi != NULL); pbi->pbi_properties = prop_dictionary_create(); KASSERT(pbi->pbi_properties != NULL); SIMPLEQ_INIT(&genppc_pct->pc_pbi); SIMPLEQ_INSERT_TAIL(&genppc_pct->pc_pbi, pbi, next); #ifdef PCI_NETBSD_CONFIGURE ioext = extent_create("pciio", 0x00008000, 0x0000ffff, NULL, 0, EX_NOWAIT); memext = extent_create("pcimem", 0x00000000, 0x0fffffff, NULL, 0, EX_NOWAIT); pci_configure_bus(genppc_pct, ioext, memext, NULL, 0, CACHELINESIZE); extent_destroy(ioext); extent_destroy(memext); #endif /* PCI_NETBSD_CONFIGURE */ #endif /* NPCI */ #if NPCI > 0 memset(&mba, 0, sizeof(mba)); mba.mba_pba.pba_iot = &prep_io_space_tag; mba.mba_pba.pba_memt = &prep_mem_space_tag; mba.mba_pba.pba_dmat = &pci_bus_dma_tag; mba.mba_pba.pba_dmat64 = NULL; mba.mba_pba.pba_pc = genppc_pct; mba.mba_pba.pba_bus = 0; mba.mba_pba.pba_bridgetag = NULL; mba.mba_pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY; config_found_ia(self, "pcibus", &mba.mba_pba, pcibusprint); #endif /* NPCI */ #ifdef RESIDUAL_DATA_DUMP SIMPLEQ_FOREACH(pbi, &genppc_pct->pc_pbi, next) printf("%s\n", prop_dictionary_externalize(pbi->pbi_properties)); #endif }
int main(int argc, char **argv) { int c, mode; char *attr = 0; extern char *optarg; extern int optind; int fd, res; size_t children; struct devpmargs paa = {.devname = "", .flags = 0}; struct devlistargs laa = {.l_devname = "", .l_childname = NULL, .l_children = 0}; struct devdetachargs daa; struct devrescanargs raa; int *locs, i; prop_dictionary_t command_dict, args_dict, results_dict, data_dict; prop_string_t string; prop_number_t number; char *xml; mode = 0; while ((c = getopt(argc, argv, OPTS)) != -1) { switch (c) { case 'Q': case 'R': case 'S': case 'd': case 'l': case 'p': case 'r': mode = c; break; case 'a': attr = optarg; break; case '?': default: usage(); } } argc -= optind; argv += optind; if (argc < 1 || mode == 0) usage(); fd = open(DRVCTLDEV, OPEN_MODE(mode), 0); if (fd < 0) err(2, "open %s", DRVCTLDEV); switch (mode) { case 'Q': paa.flags = DEVPM_F_SUBTREE; /*FALLTHROUGH*/ case 'R': strlcpy(paa.devname, argv[0], sizeof(paa.devname)); if (ioctl(fd, DRVRESUMEDEV, &paa) == -1) err(3, "DRVRESUMEDEV"); break; case 'S': strlcpy(paa.devname, argv[0], sizeof(paa.devname)); if (ioctl(fd, DRVSUSPENDDEV, &paa) == -1) err(3, "DRVSUSPENDDEV"); break; case 'd': strlcpy(daa.devname, argv[0], sizeof(daa.devname)); if (ioctl(fd, DRVDETACHDEV, &daa) == -1) err(3, "DRVDETACHDEV"); break; case 'l': strlcpy(laa.l_devname, argv[0], sizeof(laa.l_devname)); if (ioctl(fd, DRVLISTDEV, &laa) == -1) err(3, "DRVLISTDEV"); children = laa.l_children; laa.l_childname = malloc(children * sizeof(laa.l_childname[0])); if (laa.l_childname == NULL) err(5, "DRVLISTDEV"); if (ioctl(fd, DRVLISTDEV, &laa) == -1) err(3, "DRVLISTDEV"); if (laa.l_children > children) err(6, "DRVLISTDEV: number of children grew"); for (i = 0; i < laa.l_children; i++) printf("%s %s\n", laa.l_devname, laa.l_childname[i]); break; case 'r': memset(&raa, 0, sizeof(raa)); strlcpy(raa.busname, argv[0], sizeof(raa.busname)); if (attr) strlcpy(raa.ifattr, attr, sizeof(raa.ifattr)); if (argc > 1) { locs = malloc((argc - 1) * sizeof(int)); if (!locs) err(5, "malloc int[%d]", argc - 1); for (i = 0; i < argc - 1; i++) locs[i] = atoi(argv[i + 1]); raa.numlocators = argc - 1; raa.locators = locs; } if (ioctl(fd, DRVRESCANBUS, &raa) == -1) err(3, "DRVRESCANBUS"); break; case 'p': command_dict = prop_dictionary_create(); args_dict = prop_dictionary_create(); string = prop_string_create_cstring_nocopy("get-properties"); prop_dictionary_set(command_dict, "drvctl-command", string); prop_object_release(string); string = prop_string_create_cstring(argv[0]); prop_dictionary_set(args_dict, "device-name", string); prop_object_release(string); prop_dictionary_set(command_dict, "drvctl-arguments", args_dict); prop_object_release(args_dict); res = prop_dictionary_sendrecv_ioctl(command_dict, fd, DRVCTLCOMMAND, &results_dict); prop_object_release(command_dict); if (res) errx(3, "DRVCTLCOMMAND: %s", strerror(res)); number = prop_dictionary_get(results_dict, "drvctl-error"); if (prop_number_integer_value(number) != 0) { errx(3, "get-properties: %s", strerror((int)prop_number_integer_value(number))); } data_dict = prop_dictionary_get(results_dict, "drvctl-result-data"); if (data_dict == NULL) { errx(3, "get-properties: failed to return result data"); } xml = prop_dictionary_externalize(data_dict); prop_object_release(results_dict); printf("Properties for device `%s':\n%s", argv[0], xml); free(xml); break; default: errx(4, "unknown command"); } return (0); }