/* set an initial default environment for our boot-time children */ static void init_environ(void) { int r; /* PATH=/arch/sbin */ char pathstr[64]; snprintf(pathstr, sizeof(pathstr), "/%s/sbin", cpu_type_to_archstr(CURRENT_CPU_TYPE)); pathstr[sizeof(pathstr) - 1] = '\0'; r = setenv("PATH", pathstr, 0); if (r != 0) { USER_PANIC("failed to set PATH"); } /* HOME=/ */ r = setenv("HOME", "/", 0); if (r != 0) { USER_PANIC("failed to set HOME"); } }
errval_t start_boot_driver(coreid_t where, struct module_info* mi, char* record) { assert(mi != NULL); errval_t err = SYS_ERR_OK; if (!is_auto_driver(mi)) { return KALUGA_ERR_DRIVER_NOT_AUTO; } // Construct additional command line arguments containing pci-id. // We need one extra entry for the new argument. uint64_t barrelfish_id, apic_id, cpu_type; char **argv = mi->argv; bool cleanup = false; char barrelfish_id_s[10]; size_t argc = mi->argc; KALUGA_DEBUG("Starting corectrl for %s\n", record); err = oct_read(record, "_ { apic_id: %d, barrelfish_id: %d, type: %d }", &apic_id, &barrelfish_id, &cpu_type); if (err_is_ok(err)) { skb_add_fact("corename(%"PRIu64", %s, apic(%"PRIu64")).", barrelfish_id, cpu_type_to_archstr(cpu_type), apic_id); if (barrelfish_id == my_core_id) { return SYS_ERR_OK; } argv = malloc((argc+5) * sizeof(char *)); memcpy(argv, mi->argv, argc * sizeof(char *)); snprintf(barrelfish_id_s, 10, "%"PRIu64"", barrelfish_id); argv[argc] = "boot"; argc += 1; argv[argc] = barrelfish_id_s; argc += 1; // Copy kernel args over to new core struct module_info* cpu_module = find_module("cpu"); if (cpu_module != NULL && strlen(cpu_module->args) > 1) { KALUGA_DEBUG("%s:%s:%d: Boot with cpu arg %s and barrelfish_id_s=%s\n", __FILE__, __FUNCTION__, __LINE__, cpu_module->args, barrelfish_id_s); argv[argc] = "-a"; argc += 1; argv[argc] = cpu_module->args; argc += 1; } argv[argc] = NULL; cleanup = true; } else { DEBUG_ERR(err, "Malformed CPU record?"); return err; } struct capref task_cap_kernel; task_cap_kernel.cnode = cnode_task; task_cap_kernel.slot = TASKCN_SLOT_KERNELCAP; #ifdef KALUGA_SERVICE_DEBUG struct capability info; err = debug_cap_identify(task_cap_kernel, &info); if (err_is_fail(err)) { USER_PANIC_ERR(err, "Can not identify the capability."); } char buffer[1024]; debug_print_cap(buffer, 1024, &info); KALUGA_DEBUG("%s:%d: capability=%s\n", __FILE__, __LINE__, buffer); #endif struct capref inheritcn_cap; err = alloc_inheritcn_with_caps(&inheritcn_cap, NULL_CAP, NULL_CAP, task_cap_kernel); if (err_is_fail(err)) { DEBUG_ERR(err, "alloc_inheritcn_with_caps failed."); } err = spawn_program_with_caps(where, mi->path, argv, environ, inheritcn_cap, NULL_CAP, SPAWN_FLAGS_NEW_DOMAIN, &mi->did[0]); if (err_is_fail(err)) { DEBUG_ERR(err, "Spawning %s failed.", mi->path); } if (cleanup) { free(argv); } return err; }