void aibs_refresh(void *arg) { struct aibs_softc *sc = arg; struct aibs_sensor *as; SIMPLEQ_FOREACH(as, &sc->sc_sensorlist, entry) aibs_refresh_r(sc, as); }
/* * 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) { struct bindmnt *bmnt; uid_t uid = getuid(); gid_t gid = getgid(); const char *chrootdir, *cmd, *argv0; char **cmdargs, buf[32]; int c, fd; const struct option longopts[] = { { NULL, 0, NULL, 0 } }; chrootdir = cmd = NULL; argv0 = argv[0]; while ((c = getopt_long(argc, argv, "b:V", longopts, NULL)) != -1) { switch (c) { case 'b': if (optarg == NULL || *optarg == '\0') break; add_bindmount(optarg); break; case 'V': printf("%s\n", XBPS_RELVER); exit(EXIT_SUCCESS); case '?': default: usage(argv0); } } argc -= optind; argv += optind; if (argc < 2) usage(argv0); chrootdir = argv[0]; cmd = argv[1]; cmdargs = argv + 1; /* Never allow chrootdir == / */ if (strcmp(chrootdir, "/") == 0) die("/ is not allowed to be used as chrootdir"); /* Make chrootdir absolute */ if (chrootdir[0] != '/') { char cwd[PATH_MAX-1]; if (getcwd(cwd, sizeof(cwd)) == NULL) die("getcwd"); chrootdir = xbps_xasprintf("%s/%s", cwd, chrootdir); } /* * Unshare from the current process namespaces and set ours. */ if (unshare(CLONE_NEWUSER|CLONE_NEWNS|CLONE_NEWIPC|CLONE_NEWUTS) == -1) { errval = 99; die("unshare"); } /* * Setup uid/gid user mappings and restrict setgroups(). */ if ((fd = open("/proc/self/uid_map", O_RDWR)) == -1) die("failed to open /proc/self/uidmap rw"); if (write(fd, buf, snprintf(buf, sizeof buf, "%u %u 1\n", uid, uid)) == -1) die("failed to write to /proc/self/uid_map"); close(fd); if ((fd = open("/proc/self/setgroups", O_RDWR)) != -1) { if (write(fd, "deny", 4) == -1) die("failed to write to /proc/self/setgroups"); close(fd); } if ((fd = open("/proc/self/gid_map", O_RDWR)) == -1) die("failed to open /proc/self/gid_map rw"); if (write(fd, buf, snprintf(buf, sizeof buf, "%u %u 1\n", gid, gid)) == -1) die("failed to write to /proc/self/gid_map"); close(fd); /* bind mount /proc */ bindmount(chrootdir, "/proc", NULL); /* bind mount /sys */ bindmount(chrootdir, "/sys", NULL); /* bind mount /dev */ bindmount(chrootdir, "/dev", NULL); /* bind mount all user specified mnts */ SIMPLEQ_FOREACH(bmnt, &bindmnt_queue, entries) bindmount(chrootdir, bmnt->src, bmnt->dest); /* move chrootdir to / and chroot to it */ if (chdir(chrootdir) == -1) die("chdir to %s", chrootdir); if (mount(".", ".", NULL, MS_BIND|MS_PRIVATE, NULL) == -1) die("Failed to bind mount %s", chrootdir); if (mount(chrootdir, "/", NULL, MS_MOVE, NULL) == -1) die("Failed to move %s as rootfs", chrootdir); if (chroot(".") == -1) die("Failed to chroot to %s", chrootdir); if (execvp(cmd, cmdargs) == -1) die("Failed to execute command %s", cmd); /* NOTREACHED */ exit(EXIT_FAILURE); }