int main(int argc, char *argv[]) { service_register("com.baidu.ime"); puts("init service...."); g_main_loop_run(loop); return 0; }
int main(int argc, char **argv) { printf("%s: HelenOS VFS server\n", NAME); /* * Initialize VFS node hash table. */ if (!vfs_nodes_init()) { printf("%s: Failed to initialize VFS node hash table\n", NAME); return ENOMEM; } /* * Allocate and initialize the Path Lookup Buffer. */ plb = as_area_create(AS_AREA_ANY, PLB_SIZE, AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE); if (plb == AS_MAP_FAILED) { printf("%s: Cannot create address space area\n", NAME); return ENOMEM; } memset(plb, 0, PLB_SIZE); /* * Set client data constructor and destructor. */ async_set_client_data_constructor(vfs_client_data_create); async_set_client_data_destructor(vfs_client_data_destroy); /* * Set a connection handling function/fibril. */ async_set_client_connection(vfs_connection); /* * Set notification handler and subscribe to notifications. */ async_set_interrupt_received(notification_received); event_task_subscribe(EVENT_TASK_STATE_CHANGE, VFS_TASK_STATE_CHANGE); /* * Register at the naming service. */ int rc = service_register(SERVICE_VFS); if (rc != EOK) { printf("%s: Cannot register VFS service\n", NAME); return rc; } /* * Start accepting connections. */ printf("%s: Accepting connections\n", NAME); async_manager(); return 0; }
/* Register a VFS service provider. */ return_t vfs_register (service_register_t *service_register_info, service_method_t *service_method) { service_register_info->protocol_name = "vfs"; service_register_info->major_version = VFS_PROTOCOL_MAJOR_VERSION; service_register_info->minor_version = VFS_PROTOCOL_MINOR_VERSION; return service_register (service_register_info, service_method); }
/* Register an exec service provider. */ return_t exec_register (service_register_t *service_register_info, service_method_t *service_method) { service_register_info->protocol_name = "exec"; service_register_info->major_version = EXEC_PROTOCOL_MAJOR_VERSION; service_register_info->minor_version = EXEC_PROTOCOL_MINOR_VERSION; return service_register (service_register_info, service_method); }
/* Register a block service provider. */ return_t block_register (service_register_t *service_register_info, service_method_t *service_method) { service_register_info->protocol_name = "block"; service_register_info->major_version = BLOCK_PROTOCOL_MAJOR_VERSION; service_register_info->minor_version = BLOCK_PROTOCOL_MINOR_VERSION; return service_register (service_register_info, service_method); }
int tcp_sock_init(void) { socket_ports_initialize(&gsock); async_set_client_connection(tcp_sock_connection); int rc = service_register(SERVICE_TCP); if (rc != EOK) return EEXIST; return EOK; }
static void parse_dynamic(char *line, time_t mtime) { char *x; /* Skip comments, i.e. lines beginning with # */ if (MATCH_CMD(line, "#", x)) return; /* Monitored daemon, will be respawned on exit, as * long as the (optional) service callback returns * non-zero */ if (MATCH_CMD(line, "service ", x)) { service_register(SVC_TYPE_SERVICE, x, mtime, NULL); return; } /* One-shot task, will not be respawned. Only runs if * the (optional) service callback returns true */ if (MATCH_CMD(line, "task ", x)) { service_register(SVC_TYPE_TASK, x, mtime, NULL); return; } /* Like task but waits for completion, useful w/ [S] */ if (MATCH_CMD(line, "run ", x)) { service_register(SVC_TYPE_RUN, x, mtime, NULL); return; } /* Classic inetd service */ if (MATCH_CMD(line, "inetd ", x)) { #ifndef INETD_DISABLED service_register(SVC_TYPE_INETD, x, mtime, NULL); #else _e("Finit built with inetd support disabled, cannot register service inetd %s!", x); #endif return; } }
/** Program loader main function. */ int main(int argc, char *argv[]) { /* Set a handler of incomming connections. */ async_set_client_connection(ldr_connection); /* Introduce this task to the NS (give it our task ID). */ task_id_t id = task_get_id(); int rc = ns_intro(id); if (rc != EOK) return rc; /* Register at naming service. */ rc = service_register(SERVICE_LOAD); if (rc != EOK) return rc; async_manager(); /* Never reached */ return 0; }
/** Initialize the APIC driver. * */ static bool apic_init(void) { sysarg_t apic; if ((sysinfo_get_value("apic", &apic) != EOK) || (!apic)) { printf("%s: No APIC found\n", NAME); return false; } int rc = pio_enable((void *) IO_APIC_BASE, IO_APIC_SIZE, (void **) &io_apic); if (rc != EOK) { printf("%s: Failed to enable PIO for APIC: %d\n", NAME, rc); return false; } async_set_fallback_port_handler(apic_connection, NULL); service_register(SERVICE_IRC); return true; }
int main(int argc, char *argv[]) { printf(NAME ": HelenOS Logging Service\n"); parse_initial_settings(); for (int i = 1; i < argc; i++) { parse_level_settings(argv[i]); } async_set_client_connection(connection_handler); int rc = service_register(SERVICE_LOGGER); if (rc != EOK) { printf(NAME ": failed to register: %s.\n", str_error(rc)); return -1; } printf(NAME ": Accepting connections\n"); async_manager(); /* Never reached */ return 0; }
void init_global(const char *nick) { struct chanNode *chan; unsigned int i; G_LOG = log_register_type("Global", "file:global.log"); reg_new_user_func(global_process_user, NULL); reg_auth_func(global_process_auth, NULL); reg_oper_func(global_process_oper, NULL); conf_register_reload(global_conf_read); global_module = module_register("Global", G_LOG, "global.help", NULL); modcmd_register(global_module, "LIST", cmd_list, 1, 0, "flags", "+oper", NULL); modcmd_register(global_module, "MESSAGE", cmd_message, 3, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL); modcmd_register(global_module, "MESSAGES", cmd_messages, 1, 0, NULL); modcmd_register(global_module, "NOTICE", cmd_notice, 3, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL); modcmd_register(global_module, "REMOVE", cmd_remove, 2, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL); if(nick) { const char *modes = conf_get_data("services/global/modes", RECDB_QSTRING); global = AddLocalUser(nick, nick, NULL, "Global Services", modes); global_service = service_register(global); } if(autojoin_channels && global) { for (i = 0; i < autojoin_channels->used; i++) { chan = AddChannel(autojoin_channels->list[i], now, "+nt", NULL, NULL); AddChannelUser(global, chan)->modes |= MODE_CHANOP; } } saxdb_register("Global", global_saxdb_read, global_saxdb_write); reg_exit_func(global_db_cleanup, NULL); message_register_table(msgtab); }
int main(int argc, char* argv[]) { char *path; char cmd[256]; int udev = 0; uev_t timer; /* Bootstrap timer, on timeout call finalize() */ uev_ctx_t loop; /* * finit/init/telinit client tool uses /dev/initctl pipe * for compatibility but initctl client tool uses socket */ if (getpid() != 1) return client(argc, argv); /* * Initalize event context. */ uev_init(&loop); ctx = &loop; /* * Set PATH and SHELL early to something sane */ setenv("PATH", _PATH_STDPATH, 1); setenv("SHELL", _PATH_BSHELL, 1); /* * Mount base file system, kernel is assumed to run devtmpfs for /dev */ chdir("/"); umask(0); mount("none", "/proc", "proc", 0, NULL); mount("none", "/sys", "sysfs", 0, NULL); if (fisdir("/proc/bus/usb")) mount("none", "/proc/bus/usb", "usbfs", 0, NULL); /* * Parse kernel command line (debug, rescue, splash, etc.) * Also calls log_init() to set correct log level */ conf_parse_cmdline(); /* Set up canvas */ if (!rescue && !log_is_debug()) screen_init(); /* * In case of emergency. */ emergency_shell(); /* * Initial setup of signals, ignore all until we're up. */ sig_init(); /* * Load plugins early, finit.conf may contain references to * features implemented by plugins. */ plugin_init(&loop); /* * Hello world. */ banner(); /* * Check file filesystems in /etc/fstab */ for (int pass = 1; pass < 10 && !rescue; pass++) { if (fsck(pass)) break; } /* * Initialize .conf system and load static /etc/finit.conf * Also initializes global_rlimit[] for udevd, below. */ conf_init(); /* * Some non-embedded systems without an initramfs may not have /dev mounted yet * If they do, check if system has udevadm and perform cleanup from initramfs */ if (!fismnt("/dev")) mount("udev", "/dev", "devtmpfs", MS_RELATIME, "size=10%,nr_inodes=61156,mode=755"); else if (whichp("udevadm")) run_interactive("udevadm info --cleanup-db", "Cleaning up udev db"); /* Some systems use /dev/pts */ makedir("/dev/pts", 0755); mount("devpts", "/dev/pts", "devpts", 0, "gid=5,mode=620"); /* * Some systems rely on us to both create /dev/shm and, to mount * a tmpfs there. Any system with dbus needs shared memory, so * mount it, unless its already mounted, but not if listed in * the /etc/fstab file already. */ makedir("/dev/shm", 0755); if (!fismnt("/dev/shm") && !ismnt("/etc/fstab", "/dev/shm")) mount("shm", "/dev/shm", "tmpfs", 0, NULL); /* * New tmpfs based /run for volatile runtime data * For details, see http://lwn.net/Articles/436012/ */ if (fisdir("/run") && !fismnt("/run")) mount("tmpfs", "/run", "tmpfs", MS_NODEV, "mode=0755,size=10%"); umask(022); /* Bootstrap conditions, needed for hooks */ cond_init(); /* * Populate /dev and prepare for runtime events from kernel. * Prefer udev if mdev is also available on the system. */ path = which("udevd"); if (!path) path = which("/lib/systemd/systemd-udevd"); if (path) { /* Desktop and server distros usually have a variant of udev */ udev = 1; /* Register udevd as a monitored service */ snprintf(cmd, sizeof(cmd), "[S12345789] pid:udevd %s -- Device event managing daemon", path); if (service_register(SVC_TYPE_SERVICE, cmd, global_rlimit, NULL)) { _pe("Failed registering %s", path); udev = 0; } else { snprintf(cmd, sizeof(cmd), ":1 [S] <svc%s> " "udevadm trigger -c add -t devices " "-- Requesting device events", path); service_register(SVC_TYPE_RUN, cmd, global_rlimit, NULL); snprintf(cmd, sizeof(cmd), ":2 [S] <svc%s> " "udevadm trigger -c add -t subsystems " "-- Requesting subsystem events", path); service_register(SVC_TYPE_RUN, cmd, global_rlimit, NULL); } free(path); } else { path = which("mdev"); if (path) { /* Embedded Linux systems usually have BusyBox mdev */ if (log_is_debug()) touch("/dev/mdev.log"); snprintf(cmd, sizeof(cmd), "%s -s", path); free(path); run_interactive(cmd, "Populating device tree"); } } /* * Start built-in watchdog as soon as possible, if enabled */ wdogpid = watchdog(argv[0]); /* * Mount filesystems */ if (!rescue) { #ifdef REMOUNT_ROOTFS run("mount -n -o remount,rw /"); #endif #ifdef SYSROOT mount(SYSROOT, "/", NULL, MS_MOVE, NULL); #endif } if (!rescue) { _d("Root FS up, calling hooks ..."); plugin_run_hooks(HOOK_ROOTFS_UP); umask(0); if (run_interactive("mount -na", "Mounting filesystems")) plugin_run_hooks(HOOK_MOUNT_ERROR); _d("Calling extra mount hook, after mount -a ..."); plugin_run_hooks(HOOK_MOUNT_POST); run("swapon -ea"); umask(0022); } /* Base FS up, enable standard SysV init signals */ sig_setup(&loop); if (!rescue) { _d("Base FS up, calling hooks ..."); plugin_run_hooks(HOOK_BASEFS_UP); } /* * Set up inotify watcher for /etc/finit.d and read all .conf * files to figure out how to bootstrap the system. */ conf_monitor(&loop); /* * Initalize state machine and start all bootstrap tasks * NOTE: no network available! */ sm_init(&sm); sm_step(&sm); /* Debian has this little script to copy generated rules while the system was read-only */ if (udev && fexist("/lib/udev/udev-finish")) run_interactive("/lib/udev/udev-finish", "Finalizing udev"); /* Start new initctl API responder */ api_init(&loop); umask(022); /* * Wait for all SVC_TYPE_RUNTASK to have completed their work in * [S], or timeout, before calling finalize() */ _d("Starting bootstrap finalize timer ..."); uev_timer_init(&loop, &timer, service_bootstrap_cb, finalize, 1000, 1000); /* * Enter main loop to monior /dev/initctl and services */ _d("Entering main loop ..."); return uev_run(&loop, 0); }
int main( int argc, char *argv[]) { mkdir( "/media/internal/record", 0); service_register("chomper.service.recorder"); g_main_loop_run(loop); }
static void parse_static(char *line) { char *x; char cmd[CMD_SIZE]; /* Do this before mounting / read-write * XXX: Move to plugin which checks /etc/fstab instead */ if (MATCH_CMD(line, "check ", x)) { char *dev = strip_line(x); strcpy(cmd, "/sbin/fsck -C -a "); strlcat(cmd, dev, sizeof(cmd)); run_interactive(cmd, "Checking file system %s", dev); return; } if (MATCH_CMD(line, "user ", x)) { if (username) free(username); username = strdup(strip_line(x)); return; } if (MATCH_CMD(line, "host ", x)) { if (hostname) free(hostname); hostname = strdup(strip_line(x)); return; } if (MATCH_CMD(line, "module ", x)) { char *mod = strip_line(x); strcpy(cmd, "/sbin/modprobe "); strlcat(cmd, mod, sizeof(cmd)); run_interactive(cmd, "Loading kernel module %s", mod); return; } if (MATCH_CMD(line, "mknod ", x)) { char *dev = strip_line(x); strcpy(cmd, "/bin/mknod "); strlcat(cmd, dev, sizeof(cmd)); run_interactive(cmd, "Creating device node %s", dev); return; } if (MATCH_CMD(line, "network ", x)) { if (network) free(network); network = strdup(strip_line(x)); return; } if (MATCH_CMD(line, "runparts ", x)) { if (runparts) free(runparts); runparts = strdup(strip_line(x)); return; } if (MATCH_CMD(line, "include ", x)) { char *file = strip_line(x); strlcpy(cmd, file, sizeof(cmd)); if (!fexist(cmd)) { _e("Cannot find include file %s, absolute path required!", x); return; } parse_conf(cmd); return; } if (MATCH_CMD(line, "startx ", x)) { service_register(SVC_TYPE_SERVICE, strip_line(x), 0, username); return; } if (MATCH_CMD(line, "shutdown ", x)) { if (sdown) free(sdown); sdown = strdup(strip_line(x)); return; } /* The desired runlevel to start when leaving bootstrap (S). * Finit supports 1-9, but most systems only use 1-6, where * 6 is reserved for reboot */ if (MATCH_CMD(line, "runlevel ", x)) { char *token = strip_line(x); const char *err = NULL; cfglevel = strtonum(token, 1, 9, &err); if (err) cfglevel = RUNLEVEL; if (cfglevel < 1 || cfglevel > 9 || cfglevel == 6) cfglevel = 2; /* Fallback */ return; } /* TODO: Make console & tty dynamically loadable from /etc/finit.d */ if (MATCH_CMD(line, "console ", x)) { if (console) free(console); console = strdup(strip_line(x)); return; } /* TODO: Make console & tty dynamically loadable from /etc/finit.d */ if (MATCH_CMD(line, "tty ", x)) { tty_register(strip_line(x)); return; } }