int MCAPSocketDB::get_flash_seqnum( const char* this_host, int& last_seq_no) { if( !strlen(this_host) ) { return FAILURE; } arb_dbcmd(m_dbp, " select last_seq_no from MCAP_FLASH_SEQUENCE_NUMBERS "); arb_dbfcmd(m_dbp, " where host_name = '%s' ", this_host); arb_exec_string(m_dbp, "", SQL_DEFER_EXECUTE); arb_dbbind(m_dbp, 1, ARB_TYPE_INT32, 0, &last_seq_no); int num_rows = 0; while( arb_next_row(m_dbp) == ARB_MORE_DATA) { num_rows++; } if(arb_query_status(m_dbp) != SUCCESS) { log_err2(ERRLOC, "fail selecting MCAP_FLASH_SEQUENCE_NUMBERS"); return FAILURE; } if(num_rows == 1) { set_has_seqno(TRUE); set_hostname(this_host); } else if( num_rows == 0) { last_seq_no = -1; set_has_seqno(TRUE); set_hostname(this_host); // set seqno to default. if(insert_flash_seqnum(this_host, last_seq_no) != SUCCESS) { log_err2(ERRLOC, "Error inserting flashseqno row"); return FAILURE; } } if( num_rows > 1 ) { log_err2(ERRLOC, "MCAP_FLASH_SEQUENCE_NUMBERS"); return FAILURE; } return SUCCESS; }
/** * cmd_hostname - change/list avaliable virtual hosts * @cmd: normal command struct * @args: command argument string * * Without any arguments, list the avaliable virtual hosts. * Given one argument, try to set the default host for outgoing * connections. **/ void cmd_hostname(struct command *cmd, char *args) { if (args && *args && *args != '#') { set_hostname(args); } else { ifaces(iface_callback, NULL); } }
static int get_hostname_info (void) { char *host; host = get_hostname (); if (host != NULL) { if (-1 == set_hostname (host)) { SLang_free_slstring (host); return -1; } SLang_free_slstring (host); return 0; } if (SLang_get_error ()) return -1; return set_hostname ("localhost"); }
int main(int argc, char * argv[]) { /* stdin/out/err */ set_console(); /* Hostname */ set_hostname(); if (argc > 1) { char * args = NULL; if (argc > 2) { args = argv[2]; } if (!strcmp(argv[1],"--single")) { return start_options((char *[]){"/bin/compositor","--","/bin/terminal","-Fl",args,NULL}); } else if (!strcmp(argv[1], "--vga")) {
/* Reload all *.conf in /etc/finit.d/ */ void conf_reload_dynamic(void) { int i, num; char *dir = rcsd; struct dirent **e; /* Mark and sweep */ svc_mark_dynamic(); num = scandir(dir, &e, NULL, alphasort); if (num < 0) { _d("No files found in %s, skipping ...", dir); return; } for (i = 0; i < num; i++) { char *name = e[i]->d_name; char path[CMD_SIZE]; struct stat st; snprintf(path, sizeof(path), "%s/%s", dir, name); /* Check that it's an actual file ... */ if (stat(path, &st)) { _d("Cannot even read .conf file %s, skipping ...", path); continue; } if (S_ISEXEC(st.st_mode) || S_ISDIR(st.st_mode)) continue; /* Check that file ends with '.conf' */ if (strcmp(&path[strlen(path) - 5], ".conf")) { _d("File %s is not a .conf, skipping ... ", path); continue; } parse_conf_dynamic(path, st.st_mtime); } while (num--) free(e[num]); free(e); set_hostname(&hostname); }
result_t Url::format(v8::Local<v8::Object> args) { clear(); Isolate* isolate = holder(); exlib::string str; v8::Local<v8::Value> v; if (getString(isolate, args, "protocol", str)) set_protocol(str); if (getString(isolate, args, "username", str)) set_username(str); if (getString(isolate, args, "password", str)) set_password(str); if (getString(isolate, args, "host", str)) set_host(str); if (getString(isolate, args, "port", str)) set_port(str); if (getString(isolate, args, "hostname", str)) set_hostname(str); if (getString(isolate, args, "pathname", str)) set_pathname(str); v = args->Get(holder()->NewString("query")); if (!IsEmpty(v)) set_query(v); if (getString(isolate, args, "hash", str)) set_hash(str); if (m_slashes && m_protocol.compare("file:") && m_hostname.length() == 0) m_slashes = false; v = args->Get(holder()->NewString("slashes")); if (!IsEmpty(v)) set_slashes(v->BooleanValue()); return 0; }
int MCAPSocketDB::find_hostname(const char *host) { char hname[64]; if( !strlen(host) ) { return FAILURE; } arb_dbcmd(m_dbp, " select host_name from MCAP_FLASH_SEQUENCE_NUMBERS "); arb_dbfcmd(m_dbp, " where host_name = '%s' ", host); arb_exec_string(m_dbp, "", SQL_DEFER_EXECUTE); arb_dbbind(m_dbp, 1, ARB_TYPE_STRING, 64, hname); int num_rows = 0; while( arb_next_row(m_dbp) == ARB_MORE_DATA) { num_rows++; } if(arb_query_status(m_dbp) != SUCCESS) { log_err2(ERRLOC, "fail selecting MCAP_FLASH_SEQUENCE_NUMBERS"); return FAILURE; } if(num_rows == 1) { set_hostname(host); } else if(num_rows == 0) { return FAILURE; } else { log_err2(ERRLOC, "fail selecting MCAP_FLASH_SEQUENCE_NUMBERS Error"); return FAILURE; } return SUCCESS; }
int MCAPSocketDB::get_has_seqno(const char *host) { if(strcmp(m_host, host) == 0 ) { return m_has_seqno; } else { if(find_hostname(host) == SUCCESS) { set_hostname(host); set_has_seqno(TRUE); } else { return FALSE; } } }
int main(int argc, char * argv[]) { /* Hostname */ set_hostname(); if (argc > 1) { char * args = NULL; if (argc > 2) { args = argv[2]; } if (!strcmp(argv[1],"--single")) { start_terminal(args); return 0; } else if (!strcmp(argv[1], "--vga")) { start_vga_terminal(args); return 0; } else if (!strcmp(argv[1], "--special")) { start_terminal_no_freetype(args); return 0; } } start_compositor(); }
nsapi_error_t DTLSSocket::connect(const char *host, uint16_t port) { SocketAddress addr; nsapi_error_t ret; ret = _udp_socket.getpeername(&addr); if (ret != NSAPI_ERROR_NO_CONNECTION) { return ret; } if (!addr || ret == NSAPI_ERROR_NO_CONNECTION) { nsapi_error_t err = _udp_socket._stack->gethostbyname(host, &addr); if (err) { return NSAPI_ERROR_DNS_FAILURE; } addr.set_port(port); set_hostname(host); _udp_socket.connect(addr); // UDPSocket::connect() cannot fail } return connect(addr); }
/** * ソケット作成 * * @return なし */ static int inet_sock_client(void) { struct sockaddr_in server; /* ソケットアドレス情報構造体 */ int sockfd = 0; /* ソケット */ int retval = 0; /* 戻り値 */ dbglog("start"); /* 初期化 */ (void)memset(&server, 0, sizeof(struct sockaddr_in)); server.sin_family = AF_INET; if (set_hostname(&server, hostname) < 0) return EX_NG; if (set_port(&server, port) < 0) return EX_NG; /* ソケット生成 */ sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { outlog("sock=%d", sockfd); return EX_NG; } /* コネクト */ retval = connect(sockfd, (struct sockaddr *)&server, sizeof(struct sockaddr_in)); if (retval < 0) { outlog("connect=%d, sock=%d", retval, sockfd); /* ソケットクローズ */ close_sock(&sockfd); return EX_NG; } return sockfd; }
int main(int argc, char* argv[]) { if (getpid() != 1) return client(argc, argv); /* * Hello world. */ banner(); /* * Initial setup of signals, ignore all until we're up. */ sig_init(); /* * Mount base file system, kernel is assumed to run devtmpfs for /dev */ chdir("/"); umask(0); mount("none", "/proc", "proc", 0, NULL); mount("none", "/proc/bus/usb", "usbfs", 0, NULL); mount("none", "/sys", "sysfs", 0, NULL); mkdir("/dev/pts", 0755); mkdir("/dev/shm", 0755); mount("none", "/dev/pts", "devpts", 0, "gid=5,mode=620"); mount("none", "/dev/shm", "tmpfs", 0, NULL); umask(022); /* * Parse kernel parameters */ parse_kernel_cmdline(); /* * Populate /dev and prepare for runtime events from kernel. */ run_interactive(SETUP_DEVFS, "Populating device tree"); /* * Parse configuration file */ parse_finit_conf(FINIT_CONF); /* * Load plugins. Must run after finit.conf has registered * all services, or service plugins won't have anything to * hook on to. */ print_desc("Loading plugins", NULL); print_result(plugin_load_all(PLUGIN_PATH)); /* * Mount filesystems */ #ifdef REMOUNT_ROOTFS_RW run("/bin/mount -n -o remount,rw /"); #endif #ifdef SYSROOT run(SYSROOT, "/", NULL, MS_MOVE, NULL); #endif _d("Root FS up, calling hooks ..."); plugin_run_hooks(HOOK_ROOTFS_UP); umask(0); run("/bin/mount -na"); run("/sbin/swapon -ea"); umask(0022); /* Cleanup stale files, if any still linger on. */ run_interactive("rm -rf /tmp/* /var/run/* /var/lock/*", "Cleanup temporary directories"); /* Base FS up, enable standard SysV init signals */ sig_setup(); _d("Base FS up, calling hooks ..."); plugin_run_hooks(HOOK_BASEFS_UP); /* * Start all bootstrap tasks, no network available! */ svc_bootstrap(); /* * Network stuff */ /* Setup kernel specific settings, e.g. allow broadcast ping, etc. */ run("/sbin/sysctl -e -p /etc/sysctl.conf >/dev/null"); /* Set initial hostname. */ set_hostname(hostname); ifconfig("lo", "127.0.0.1", "255.0.0.0", 1); if (network) run_interactive(network, "Starting networking: %s", network); umask(022); /* Hooks that rely on loopback, or basic networking being up. */ plugin_run_hooks(HOOK_NETWORK_UP); /* * Start all tasks/services in the configured runlevel */ svc_runlevel(cfglevel); _d("Running svc up hooks ..."); plugin_run_hooks(HOOK_SVC_UP); /* * Run startup scripts in /etc/finit.d/, if any. */ if (rcsd && fisdir(rcsd)) { _d("Running startup scripts in %s ...", rcsd); run_parts(rcsd, NULL); } /* Hooks that should run at the very end */ plugin_run_hooks(HOOK_SYSTEM_UP); /* * Enter main loop to monior /dev/initctl and services */ return run_loop(); }
static void set_hostname_cmd (char *s) { (void) set_hostname (s); }
int main(int UNUSED(args), char *argv[]) { /* * Initial setup of signals, ignore all until we're up. */ sig_init(); /* * Mount base file system, kernel is assumed to run devtmpfs for /dev */ chdir("/"); umask(0); mount("none", "/proc", "proc", 0, NULL); mount("none", "/proc/bus/usb", "usbfs", 0, NULL); mount("none", "/sys", "sysfs", 0, NULL); mkdir("/dev/pts", 0755); mkdir("/dev/shm", 0755); mount("none", "/dev/pts", "devpts", 0, "gid=5,mode=620"); mount("none", "/dev/shm", "tmpfs", 0, NULL); umask(022); /* * Parse kernel parameters */ parse_kernel_cmdline(); cls(); echo("finit " VERSION " (built " __DATE__ " " __TIME__ " by " WHOAMI ")"); /* * Populate /dev and prepare for runtime events from kernel. */ #if defined(USE_UDEV) run_interactive("udevd --daemon", "Populating device tree"); #elif defined (MDEV) run_interactive(MDEV " -s", "Populating device tree"); #endif /* * Parse configuration file */ parse_finit_conf(FINIT_CONF); /* * Load plugins. Must run after finit.conf has registered * all services, or service plugins won't have anything to * hook on to. */ print_desc("", "Loading plugins"); print_result(plugin_load_all(PLUGIN_PATH)); /* * Mount filesystems */ _d("Mount filesystems in /etc/fstab ..."); #ifdef REMOUNT_ROOTFS_RW run("/bin/mount -n -o remount,rw /"); #endif #ifdef SYSROOT run(SYSROOT, "/", NULL, MS_MOVE, NULL); #endif _d("Root FS up, calling hooks ..."); plugin_run_hooks(HOOK_ROOTFS_UP); umask(0); run("/bin/mount -na"); run("/sbin/swapon -ea"); umask(0022); /* Cleanup stale files, if any still linger on. */ run_interactive("rm -rf /tmp/* /var/run/* /var/lock/*", "Cleanup temporary directories"); /* * Base FS up, enable standard SysV init signals */ sig_setup(); _d("Base FS up, calling hooks ..."); plugin_run_hooks(HOOK_BASEFS_UP); /* * Network stuff */ /* Setup kernel specific settings, e.g. allow broadcast ping, etc. */ run("/sbin/sysctl -e -p /etc/sysctl.conf >/dev/null"); /* Set initial hostname. */ set_hostname(hostname); ifconfig("lo", "127.0.0.1", "255.0.0.0", 1); if (network) run_interactive(network, "Starting networking: %s", network); umask(022); /* * Hooks that rely on loopback, or basic networking being up. */ plugin_run_hooks(HOOK_NETWORK_UP); /* * Start service monitor framework */ _d("Starting all static services from %s", FINIT_CONF); svc_start_all(); /* * Run startup scripts in /etc/finit.d/, if any. */ if (rcsd && fisdir(rcsd)) { _d("Running startup scripts in %s ...", rcsd); run_parts(rcsd, NULL); } /* * Hooks that should run at the very end */ plugin_run_hooks(HOOK_SYSTEM_UP); /* Start GETTY on console */ _d("Starting getty on console ..."); run_getty(GETTY, argv); /* * Enter main loop to monior /dev/initctl and services */ _d("Entering main loop ..."); return run_loop(); }
static int init(const char* target) { init_early(); set_hostname(); set_kblayout(); set_videomode(); prepare_block_devices(); load_fstab(); if ( atexit(mountpoints_unmount) != 0 ) fatal("atexit: %m"); mountpoints_mount(false); sigset_t oldset, sigttou; sigemptyset(&sigttou); sigaddset(&sigttou, SIGTTOU); int result; while ( true ) { struct termios tio; if ( tcgetattr(0, &tio) ) fatal("tcgetattr: %m"); pid_t child_pid = fork(); if ( child_pid < 0 ) fatal("fork: %m"); if ( !child_pid ) { uid_t uid = getuid(); pid_t pid = getpid(); pid_t ppid = getppid(); if ( setpgid(0, 0) < 0 ) fatal("setpgid: %m"); sigprocmask(SIG_BLOCK, &sigttou, &oldset); if ( tcsetpgrp(0, pid) < 0 ) fatal("tcsetpgrp: %m"); sigprocmask(SIG_SETMASK, &oldset, NULL); struct passwd* pwd = getpwuid(uid); if ( !pwd ) fatal("looking up user by uid %" PRIuUID ": %m", uid); const char* home = pwd->pw_dir[0] ? pwd->pw_dir : "/"; const char* shell = pwd->pw_shell[0] ? pwd->pw_shell : "sh"; char ppid_str[sizeof(pid_t) * 3]; snprintf(ppid_str, sizeof(ppid_str), "%" PRIiPID, ppid); if ( setenv("INIT_PID", ppid_str, 1) < 0 || setenv("LOGNAME", pwd->pw_name, 1) < 0 || setenv("USER", pwd->pw_name, 1) < 0 || setenv("HOME", home, 1) < 0 || setenv("SHELL", shell, 1) < 0 ) fatal("setenv: %m"); if ( chdir(home) < 0 ) warning("chdir: %s: %m", home); const char* program = "login"; bool activate_terminal = false; if ( !strcmp(target, "single-user") ) { activate_terminal = true; program = shell; } if ( !strcmp(target, "sysinstall") ) { activate_terminal = true; program = "sysinstall"; } if ( !strcmp(target, "sysupgrade") ) { program = "sysupgrade"; activate_terminal = true; } if ( activate_terminal ) { tio.c_cflag |= CREAD; if ( tcsetattr(0, TCSANOW, &tio) ) fatal("tcgetattr: %m"); } const char* argv[] = { program, NULL }; execvp(program, (char* const*) argv); fatal("%s: %m", program); } int status; if ( waitpid(child_pid, &status, 0) < 0 ) fatal("waitpid"); sigprocmask(SIG_BLOCK, &sigttou, &oldset); if ( tcsetattr(0, TCSAFLUSH, &tio) ) fatal("tcgetattr: %m"); if ( tcsetpgrp(0, getpgid(0)) < 0 ) fatal("tcsetpgrp: %m"); sigprocmask(SIG_SETMASK, &oldset, NULL); const char* back = ": Trying to bring it back up again"; if ( WIFEXITED(status) ) { result = WEXITSTATUS(status); break; } else if ( WIFSIGNALED(status) ) note("session: %s%s", strsignal(WTERMSIG(status)), back); else note("session: Unexpected unusual termination%s", back); } mountpoints_unmount(); return result; }