/* returns failure */ const char *parse_config(char *progname, int custom_config, char *req_config, struct rs_config *rs_config) { char *specificconfig, *specific_pkg_config; const char *l; /* Config file specified? */ if(custom_config) return do_config(progname, req_config, rs_config); /* No specific config file. */ if(asprintf(&specificconfig, "%s/%s", _PATH_SYSTEM_CONF_DIR, progname) < 0) { errx(1, "no memory"); } if(asprintf(&specific_pkg_config, "%s/%s", _PATH_SYSTEM_CONF_PKG_DIR, progname) < 0) { errx(1, "no memory"); } /* Try specific config filename first, in base system * and package locations, * and only if it fails, the global * system one. */ if((l=do_config(progname, specific_pkg_config, rs_config))) return l; if((l=do_config(progname, specificconfig, rs_config))) return l; if((l=do_config(progname, req_config, rs_config))) return l; return NULL; }
int main(void) { char buf[1024]; int ret; do_config(); setup(); sleep(2); while (1) { memset(buf, 0, sizeof(buf)); ret = read_until(read_fd, buf, sizeof(buf) - 1, '\n'); if (ret == -1) exit(4); if (ret > 0) { if (buf[0] == 0) { exit(0); } ret = morris_pratt(buf, strlen(buf)); if (ret == 1) { printf(write_fd, "%s\n", buf); } } } exit(1); }
int main(void) { char buf[1024]; int ret; do_config(); setup(); sleep(2); while (1) { cgc_memset(buf, 0, sizeof(buf)); ret = read_until(read_fd, buf, sizeof(buf), '\n'); if (ret == -1) cgc_exit(4); if (ret > 0) { if (buf[0] == 0) { cgc_exit(0); } ret = search(buf, cgc_strlen(buf)); if (ret != 1) { printf(write_fd, "%s\n", buf); } } } cgc_exit(1); }
/** * Initialize fax components * @param module_interface * @param pool memory pool to allocate from * @param config_file to use * @return SWITCH_STATUS_SUCCESS if successful */ switch_status_t rayo_fax_components_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool, const char *config_file) { if (do_config(pool, config_file) != SWITCH_STATUS_SUCCESS) { return SWITCH_STATUS_TERM; } switch_event_bind("rayo_fax_components", SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE, NULL, on_execute_complete_event, NULL); rayo_actor_command_handler_add(RAT_CALL, "", "set:"RAYO_FAX_NS":receivefax", start_receivefax_component); rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "receivefax", "set:"RAYO_EXT_NS":stop", stop_fax_component); rayo_actor_command_handler_add(RAT_CALL, "", "set:"RAYO_FAX_NS":sendfax", start_sendfax_component); rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "sendfax", "set:"RAYO_EXT_NS":stop", stop_fax_component); return SWITCH_STATUS_SUCCESS; }
/** * Start a server. * * port: The port the server will run on. * argc: Number of arguments to the program. * argv: Array containing arguments to program. */ int start_server(char *port, int argc, char *argv[]) { if (do_config(port) < 0) return -1; /* Keep track of program to start and its arguments. */ if (argc - optind > 0) { run_program = true; config->program = argv[optind]; config->argc = argc - optind; config->argv = argv + optind; } fprintf(stderr, "[INFO] Server started\n"); setup_poll(); do_loop(); return 0; }
static void maintainr_projectbox_init (MaintainrProjectbox *item) { GtkWidget *mainbox; item->priv = MAINTAINR_PROJECTBOX_GET_PRIVATE (item); gtk_container_set_border_width (GTK_CONTAINER (item), 10); gtk_notebook_set_show_tabs (GTK_NOTEBOOK (item), FALSE); mainbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_notebook_append_page (GTK_NOTEBOOK (item), mainbox, NULL); gtk_box_pack_start (GTK_BOX (mainbox), do_head (item), FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (mainbox), do_todos (item), TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (mainbox), do_buttons (item), FALSE, FALSE, 0); gtk_notebook_append_page (GTK_NOTEBOOK (item), do_config (item), NULL); }
/** * Initialize record component * @param pool memory pool to allocate from * @param config_file to use * @return SWITCH_STATUS_SUCCESS if successful */ switch_status_t rayo_record_component_load(switch_memory_pool_t *pool, const char *config_file) { if (do_config(pool, config_file) != SWITCH_STATUS_SUCCESS) { return SWITCH_STATUS_TERM; } switch_event_bind("rayo_record_component", SWITCH_EVENT_RECORD_STOP, NULL, on_call_record_stop_event, NULL); rayo_actor_command_handler_add(RAT_CALL, "", "set:"RAYO_RECORD_NS":record", start_call_record_component); rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "record", "set:"RAYO_RECORD_NS":pause", pause_record_component); rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "record", "set:"RAYO_RECORD_NS":resume", resume_record_component); rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "record", "set:"RAYO_EXT_NS":stop", stop_call_record_component); switch_event_bind("rayo_record_component", SWITCH_EVENT_CUSTOM, "conference::maintenance", on_mixer_record_event, NULL); rayo_actor_command_handler_add(RAT_MIXER, "", "set:"RAYO_RECORD_NS":record", start_mixer_record_component); rayo_actor_command_handler_add(RAT_MIXER_COMPONENT, "record", "set:"RAYO_RECORD_NS":pause", pause_record_component); rayo_actor_command_handler_add(RAT_MIXER_COMPONENT, "record", "set:"RAYO_RECORD_NS":resume", resume_record_component); rayo_actor_command_handler_add(RAT_MIXER_COMPONENT, "record", "set:"RAYO_EXT_NS":stop", stop_mixer_record_component); return SWITCH_STATUS_SUCCESS; }
/** * Start a client. * * server: String containing the server to connect to. * port: The port the client will run on. */ int start_client(char *server, char *port) { if (do_config_server(server) < 0 || do_config(port) < 0) return -1; /* Initialize connection with server. Go to student code. */ conn_t *conn = tcp_handshake(); ctcp_config_t *config_copy = calloc(sizeof(ctcp_config_t), 1); memcpy(config_copy, ctcp_cfg, sizeof(ctcp_config_t)); ctcp_state_t *state = ctcp_init(conn, config_copy); if (state == NULL) { fprintf(stderr, "[ERROR] Could not connect to server!\n"); return -1; } fprintf(stderr, "[INFO] Connected to server\n"); config->sconn->state = state; setup_poll(); do_loop(); return 0; }
void simple_file_logger::asynch_configure() { try { config_data config = do_config(false); format_ = config.format; max_size_ = config.max_size; file_ = settings_manager::get_proxy()->expand_path(config.file); if (file_.empty()) file_ = base_path() + "nsclient.log"; if (file_.find('\\') == std::string::npos && file_.find('/') == std::string::npos) { file_ = base_path() + file_; } if (file_ == "none") { file_ = ""; } } catch (const std::exception &e) { // ignored, since this might be after shutdown... } catch (...) { // ignored, since this might be after shutdown... } }
/* * -- configure * * do a first pass of the command line parameters to find all * configuration files. the options in those files are processed * before any other command line parameter. command line will * overwrite any other configuration, as well as the last config * file will overwrite previous config files. * */ void configure(struct _como * m, int argc, char ** argv) { static cli_args_t cli_args; int config_file_exists; int c, i, j; DIR *d; if (cli_args.done == 0) { parse_cmdline(&cli_args, argc, argv); } m->running = cli_args.running; /* * build list of config files */ config_file_exists = 0; for (c = 0; c < cli_args.cfg_files_count; c++) { config_file_exists = 1; parse_cfgfile(m, cli_args.cfg_files[c]); } if (!config_file_exists && m->running == NORMAL) parse_cfgfile(m, DEFAULT_CFGFILE); /* add default config file */ /* use cli args to override cfg file settings */ if (cli_args.basedir != NULL) safe_dup(&m->basedir, cli_args.basedir); if (cli_args.libdir != NULL) safe_dup(&m->libdir, cli_args.libdir); if (cli_args.query_port != -1) m->node->query_port = cli_args.query_port; if (cli_args.mem_size != 0) m->mem_size = cli_args.mem_size; if (cli_args.logflags != -1) m->logflags = cli_args.logflags; m->debug = cli_args.debug; if (m->running == INLINE) { char *conf_argv[2]; if (cli_args.sniffer != NULL) { add_sniffer(m, cli_args.sniffer, NULL, NULL); } /* prepare the arguments for do_config() */ conf_argv[0] = "module"; conf_argv[1] = cli_args.module; do_config(m, 2, conf_argv); if (cli_args.module_args != NULL) { conf_argv[0] = "args"; conf_argv[1] = cli_args.module_args; do_config(m, 2, conf_argv); } if (cli_args.filter != NULL) { conf_argv[0] = "filter"; conf_argv[1] = cli_args.filter; do_config(m, 2, conf_argv); } conf_argv[0] = "end"; do_config(m, 1, conf_argv); } /* * now look into the virtual nodes and replicate * all modules that have been found in the config file(s) * * these new modules will have the same name but will be * running the additional filter associated with the virtual * node and save data in the virtual node basedir. */ for (i = 0, j = m->module_last; i <= j; i++) { node_t * node; module_t * orig; orig = &m->modules[i]; for (node = m->node; node; node = node->next) { module_t * mdl; char * nm; if (node->id == 0) break; /* master node. nothing to do */ /* create a new module and copy it from new module */ mdl = copy_module(m, orig, node->id, -1, NULL); /* append node id to module's output file */ asprintf(&nm, "%s-%d", mdl->output, mdl->node); safe_dup(&mdl->output, nm); free(nm); /* add the node filter to the module filter */ if (node->filter_str) { char * flt; if (!strcmp(mdl->filter_str, "all")) asprintf(&flt, "%s", node->filter_str); else asprintf(&flt,"(%s) and (%s)", node->filter_str, mdl->filter_str); mdl->filter_str = flt; /* FIXME: possible leak */ } logmsg(LOGUI, "... module %s [%d][%d] ", mdl->name, mdl->node, mdl->priority); logmsg(LOGUI, " filter %s; out %s (%uMB)\n", mdl->filter_str, mdl->output, mdl->streamsize/(1024*1024)); if (mdl->description != NULL) logmsg(LOGUI, " -- %s\n", mdl->description); } } /* * open the basedir for all nodes (virtual ones included) */ if (m->basedir == NULL) panicx("missing basedir"); d = opendir(m->basedir); if (d == NULL) createdir(m->basedir); else closedir(d); }
/* * Process the command line. */ void CmdLineHandler::process_cmdline(LPSTR cmdline) { USES_CONVERSION; char *p; int got_host = 0; /* By default, we bring up the config dialog, rather than launching * a session. This gets set to TRUE if something happens to change * that (e.g., a hostname is specified on the command-line). */ int allow_launch = FALSE; default_protocol = be_default_protocol; /* Find the appropriate default port. */ { Backend *b = backend_from_proto(default_protocol); default_port = 0; /* illegal */ if (b) default_port = b->default_port; } cfg.logtype = LGTYP_NONE; do_defaults(NULL, &cfg); p = cmdline; /* * Process a couple of command-line options which are more * easily dealt with before the line is broken up into words. * These are the old-fashioned but convenient @sessionname and * the internal-use-only &sharedmemoryhandle, neither of which * are combined with anything else. */ while (*p && isspace(*p)) p++; if (*p == '@') { /* * An initial @ means that the whole of the rest of the * command line should be treated as the name of a saved * session, with _no quoting or escaping_. This makes it a * very convenient means of automated saved-session * launching, via IDM_SAVEDSESS or Windows 7 jump lists. */ int i = strlen(p); while (i > 1 && isspace(p[i - 1])) i--; p[i] = '\0'; do_defaults(p + 1, &cfg); if (!cfg_launchable(&cfg) && !do_config()) { return; } allow_launch = TRUE; /* allow it to be launched directly */ } else if (*p == '&') { /* * An initial & means we've been given a command line * containing the hex value of a HANDLE for a file * mapping object, which we must then extract as a * config. */ HANDLE filemap; Config *cp; if (sscanf(p + 1, "%p", &filemap) == 1 && (cp = (Config*)MapViewOfFile(filemap, FILE_MAP_READ, 0, 0, sizeof(Config))) != NULL) { cfg = *cp; UnmapViewOfFile(cp); CloseHandle(filemap); } else if (!do_config()) { cleanup_exit(0); } allow_launch = TRUE; } else { /* * Otherwise, break up the command line and deal with * it sensibly. */ int argc, i; char **argv; split_into_argv(cmdline, &argc, &argv, NULL); for (i = 0; i < argc; i++) { char *p = argv[i]; int ret; ret = cmdline_process_param(p, i+1<argc?argv[i+1]:NULL, 1, &cfg); if (ret == -2) { cmdline_error("option \"%s\" requires an argument", p); } else if (ret == 2) { i++; /* skip next argument */ } else if (ret == 1) { continue; /* nothing further needs doing */ } else if (!strcmp(p, "-cleanup") || !strcmp(p, "-cleanup-during-uninstall")) { /* * `putty -cleanup'. Remove all registry * entries associated with PuTTY, and also find * and delete the random seed file. */ char *s1, *s2; /* Are we being invoked from an uninstaller? */ if (!strcmp(p, "-cleanup-during-uninstall")) { s1 = dupprintf("Remove saved sessions and random seed file?\n" "\n" "If you hit Yes, ALL Registry entries associated\n" "with %s will be removed, as well as the\n" "random seed file. THIS PROCESS WILL\n" "DESTROY YOUR SAVED SESSIONS.\n" "(This only affects the currently logged-in user.)\n" "\n" "If you hit No, uninstallation will proceed, but\n" "saved sessions etc will be left on the machine.", appname); s2 = dupprintf("%s Uninstallation", appname); } else { s1 = dupprintf("This procedure will remove ALL Registry entries\n" "associated with %s, and will also remove\n" "the random seed file. (This only affects the\n" "currently logged-in user.)\n" "\n" "THIS PROCESS WILL DESTROY YOUR SAVED SESSIONS.\n" "Are you really sure you want to continue?", appname); s2 = dupprintf("%s Warning", appname); } //if (message_box(A2W(s1), A2W(s2), // MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2, // HELPCTXID(option_cleanup)) == IDYES) { if (MessageBox(WindowInterface::GetInstance()->getNativeTopWnd(), A2W(s1), A2W(s2), MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) == IDYES) { gStorage->cleanup_all(); } sfree(s1); sfree(s2); exit(0); } else if (!strcmp(p, "-pgpfp")) { pgp_fingerprints(); exit(1); } else if (*p != '-') { char *q = p; if (got_host) { /* * If we already have a host name, treat * this argument as a port number. NB we * have to treat this as a saved -P * argument, so that it will be deferred * until it's a good moment to run it. */ int ret = cmdline_process_param("-P", p, 1, &cfg); assert(ret == 2); } else if (!strncmp(q, "telnet:", 7)) { /* * If the hostname starts with "telnet:", * set the protocol to Telnet and process * the string as a Telnet URL. */ char c; q += 7; if (q[0] == '/' && q[1] == '/') q += 2; cfg.protocol = PROT_TELNET; p = q; while (*p && *p != ':' && *p != '/') p++; c = *p; if (*p) *p++ = '\0'; if (c == ':') cfg.port = atoi(p); else cfg.port = -1; strncpy(cfg.host, q, sizeof(cfg.host) - 1); cfg.host[sizeof(cfg.host) - 1] = '\0'; got_host = 1; } else { /* * Otherwise, treat this argument as a host * name. */ while (*p && !isspace(*p)) p++; if (*p) *p++ = '\0'; strncpy(cfg.host, q, sizeof(cfg.host) - 1); cfg.host[sizeof(cfg.host) - 1] = '\0'; got_host = 1; } } else { cmdline_error("unknown option \"%s\"", p); } } } cmdline_run_saved(&cfg); if (loaded_session || got_host) allow_launch = TRUE; if ((!allow_launch || !cfg_launchable(&cfg)) && !do_config()) { return ; } adjust_host(&cfg); if (!strcmp(cfg.session_name, DEFAULT_SESSION_NAME)){ if (cfg.protocol == PROT_SERIAL) snprintf(cfg.session_name, sizeof(cfg.session_name), "tmp#%s:%d", cfg.serline, cfg.serspeed); else snprintf(cfg.session_name, sizeof(cfg.session_name), "tmp#%s:%d", cfg.host, cfg.port); save_settings(cfg.session_name, &cfg); } }
int main(int argc, char *argv[]) { #ifdef __FreeBSD__ extern char *__progname; FILE *fpid = NULL; struct stat dbstat; int pt, ge, we; /* make build on amd64/sparc happy */ #endif fd_set *fdsr = NULL, *fdsw = NULL; struct sockaddr_in sin; struct sockaddr_in lin; int ch, s, s2, conflisten = 0, syncfd = 0, i, omax = 0, one = 1; socklen_t sinlen; u_short port; struct servent *ent; struct rlimit rlp; char *bind_address = NULL; const char *errstr; char *sync_iface = NULL; char *sync_baddr = NULL; tzset(); openlog_r("spamd", LOG_PID | LOG_NDELAY, LOG_DAEMON, &sdata); if ((ent = getservbyname("spamd", "tcp")) == NULL) errx(1, "Can't find service \"spamd\" in /etc/services"); port = ntohs(ent->s_port); if ((ent = getservbyname("spamd-cfg", "tcp")) == NULL) errx(1, "Can't find service \"spamd-cfg\" in /etc/services"); cfg_port = ntohs(ent->s_port); if ((ent = getservbyname("spamd-sync", "udp")) == NULL) errx(1, "Can't find service \"spamd-sync\" in /etc/services"); sync_port = ntohs(ent->s_port); if (gethostname(hostname, sizeof hostname) == -1) err(1, "gethostname"); maxfiles = get_maxfiles(); if (maxcon > maxfiles) maxcon = maxfiles; if (maxblack > maxfiles) maxblack = maxfiles; while ((ch = #ifndef __FreeBSD__ getopt(argc, argv, "45l:c:B:p:bdG:h:s:S:M:n:vw:y:Y:")) != -1) { #else getopt(argc, argv, "45l:c:B:p:bdG:h:s:S:M:n:vw:y:Y:t:m:")) != -1) { #endif switch (ch) { case '4': nreply = "450"; break; case '5': nreply = "550"; break; case 'l': bind_address = optarg; break; case 'B': i = atoi(optarg); maxblack = i; break; case 'c': i = atoi(optarg); if (i > maxfiles) { fprintf(stderr, "%d > system max of %d connections\n", i, maxfiles); usage(); } maxcon = i; break; case 'p': i = atoi(optarg); port = i; break; case 'd': debug = 1; break; case 'b': greylist = 0; break; case 'G': if (sscanf(optarg, "%d:%d:%d", &pt, &ge, &we) != 3) usage(); /* convert to seconds from minutes */ passtime = pt * 60; /* convert to seconds from hours */ whiteexp = we * (60 * 60); /* convert to seconds from hours */ greyexp = ge * (60 * 60); break; case 'h': bzero(&hostname, sizeof(hostname)); if (strlcpy(hostname, optarg, sizeof(hostname)) >= sizeof(hostname)) errx(1, "-h arg too long"); break; case 's': i = strtonum(optarg, 0, 10, &errstr); if (errstr) usage(); stutter = i; break; case 'S': i = strtonum(optarg, 0, 90, &errstr); if (errstr) usage(); grey_stutter = i; break; case 'M': low_prio_mx_ip = optarg; break; case 'n': spamd = optarg; break; case 'v': verbose = 1; break; case 'w': window = atoi(optarg); if (window <= 0) usage(); break; case 'Y': if (sync_addhost(optarg, sync_port) != 0) sync_iface = optarg; syncsend++; break; case 'y': sync_baddr = optarg; syncrecv++; break; #ifdef __FreeBSD__ case 't': ipfw_tabno = atoi(optarg); break; case 'm': if (strcmp(optarg, "ipfw") == 0) use_pf=0; break; #endif default: usage(); break; } } #ifdef __FreeBSD__ /* check if PATH_SPAMD_DB is a regular file */ if (lstat(PATH_SPAMD_DB, &dbstat) == 0 && !S_ISREG(dbstat.st_mode)) { syslog(LOG_ERR, "error %s (Not a regular file)", PATH_SPAMD_DB); errx(1, "exit \"%s\" : Not a regular file", PATH_SPAMD_DB); } #endif setproctitle("[priv]%s%s", greylist ? " (greylist)" : "", (syncrecv || syncsend) ? " (sync)" : ""); if (!greylist) maxblack = maxcon; else if (maxblack > maxcon) usage(); rlp.rlim_cur = rlp.rlim_max = maxcon + 15; if (setrlimit(RLIMIT_NOFILE, &rlp) == -1) err(1, "setrlimit"); con = calloc(maxcon, sizeof(*con)); if (con == NULL) err(1, "calloc"); con->obuf = malloc(8192); if (con->obuf == NULL) err(1, "malloc"); con->osize = 8192; for (i = 0; i < maxcon; i++) con[i].fd = -1; signal(SIGPIPE, SIG_IGN); s = socket(AF_INET, SOCK_STREAM, 0); if (s == -1) err(1, "socket"); if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) == -1) return (-1); conflisten = socket(AF_INET, SOCK_STREAM, 0); if (conflisten == -1) err(1, "socket"); if (setsockopt(conflisten, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) == -1) return (-1); memset(&sin, 0, sizeof sin); sin.sin_len = sizeof(sin); if (bind_address) { if (inet_pton(AF_INET, bind_address, &sin.sin_addr) != 1) err(1, "inet_pton"); } else sin.sin_addr.s_addr = htonl(INADDR_ANY); sin.sin_family = AF_INET; sin.sin_port = htons(port); if (bind(s, (struct sockaddr *)&sin, sizeof sin) == -1) err(1, "bind"); memset(&lin, 0, sizeof sin); lin.sin_len = sizeof(sin); lin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); lin.sin_family = AF_INET; lin.sin_port = htons(cfg_port); if (bind(conflisten, (struct sockaddr *)&lin, sizeof lin) == -1) err(1, "bind local"); if (syncsend || syncrecv) { syncfd = sync_init(sync_iface, sync_baddr, sync_port); if (syncfd == -1) err(1, "sync init"); } if ((pw = getpwnam("_spamd")) == NULL) errx(1, "no such user _spamd"); #ifdef __FreeBSD__ /* open the pid file just before daemon */ fpid = fopen(pid_file, "w"); if (fpid == NULL) { syslog(LOG_ERR, "error can't create pid file %s (%m)", pid_file); err(1, "can't create pid file \"%s\"", pid_file); } #endif if (debug == 0) { if (daemon(1, 1) == -1) err(1, "daemon"); } if (greylist) { #ifdef __FreeBSD__ if(use_pf){ #endif pfdev = open("/dev/pf", O_RDWR); if (pfdev == -1) { syslog_r(LOG_ERR, &sdata, "open /dev/pf: %m"); exit(1); } #ifdef __FreeBSD__ } #endif maxblack = (maxblack >= maxcon) ? maxcon - 100 : maxblack; if (maxblack < 0) maxblack = 0; /* open pipe to talk to greylister */ if (pipe(greypipe) == -1) { syslog(LOG_ERR, "pipe (%m)"); exit(1); } /* open pipe to recieve spamtrap configs */ if (pipe(trappipe) == -1) { syslog(LOG_ERR, "pipe (%m)"); exit(1); } jail_pid = fork(); switch (jail_pid) { case -1: syslog(LOG_ERR, "fork (%m)"); exit(1); case 0: /* child - continue */ signal(SIGPIPE, SIG_IGN); grey = fdopen(greypipe[1], "w"); if (grey == NULL) { syslog(LOG_ERR, "fdopen (%m)"); _exit(1); } close(greypipe[0]); trapfd = trappipe[0]; trapcfg = fdopen(trappipe[0], "r"); if (trapcfg == NULL) { syslog(LOG_ERR, "fdopen (%m)"); _exit(1); } close(trappipe[1]); goto jail; } /* parent - run greylister */ grey = fdopen(greypipe[0], "r"); if (grey == NULL) { syslog(LOG_ERR, "fdopen (%m)"); exit(1); } close(greypipe[1]); trapcfg = fdopen(trappipe[1], "w"); if (trapcfg == NULL) { syslog(LOG_ERR, "fdopen (%m)"); exit(1); } close(trappipe[0]); return (greywatcher()); /* NOTREACHED */ } jail: #ifdef __FreeBSD__ /* after switch user and daemon write and close the pid file */ if (fpid) { fprintf(fpid, "%ld\n", (long) getpid()); if (fclose(fpid) == EOF) { syslog(LOG_ERR, "error can't close pid file %s (%m)", pid_file); exit(1); } } #endif if (chroot("/var/empty") == -1 || chdir("/") == -1) { syslog(LOG_ERR, "cannot chdir to /var/empty."); exit(1); } if (pw) if (setgroups(1, &pw->pw_gid) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) err(1, "failed to drop privs"); if (listen(s, 10) == -1) err(1, "listen"); if (listen(conflisten, 10) == -1) err(1, "listen"); if (debug != 0) printf("listening for incoming connections.\n"); syslog_r(LOG_WARNING, &sdata, "listening for incoming connections."); while (1) { struct timeval tv, *tvp; int max, n; int writers; max = MAX(s, conflisten); if (syncrecv) max = MAX(max, syncfd); max = MAX(max, conffd); max = MAX(max, trapfd); time(&t); for (i = 0; i < maxcon; i++) if (con[i].fd != -1) max = MAX(max, con[i].fd); if (max > omax) { free(fdsr); fdsr = NULL; free(fdsw); fdsw = NULL; fdsr = (fd_set *)calloc(howmany(max+1, NFDBITS), sizeof(fd_mask)); if (fdsr == NULL) err(1, "calloc"); fdsw = (fd_set *)calloc(howmany(max+1, NFDBITS), sizeof(fd_mask)); if (fdsw == NULL) err(1, "calloc"); omax = max; } else { memset(fdsr, 0, howmany(max+1, NFDBITS) * sizeof(fd_mask)); memset(fdsw, 0, howmany(max+1, NFDBITS) * sizeof(fd_mask)); } writers = 0; for (i = 0; i < maxcon; i++) { if (con[i].fd != -1 && con[i].r) { if (con[i].r + MAXTIME <= t) { closecon(&con[i]); continue; } FD_SET(con[i].fd, fdsr); } if (con[i].fd != -1 && con[i].w) { if (con[i].w + MAXTIME <= t) { closecon(&con[i]); continue; } if (con[i].w <= t) FD_SET(con[i].fd, fdsw); writers = 1; } } FD_SET(s, fdsr); /* only one active config conn at a time */ if (conffd == -1) FD_SET(conflisten, fdsr); else FD_SET(conffd, fdsr); if (trapfd != -1) FD_SET(trapfd, fdsr); if (syncrecv) FD_SET(syncfd, fdsr); if (writers == 0) { tvp = NULL; } else { tv.tv_sec = 1; tv.tv_usec = 0; tvp = &tv; } n = select(max+1, fdsr, fdsw, NULL, tvp); if (n == -1) { if (errno != EINTR) err(1, "select"); continue; } if (n == 0) continue; for (i = 0; i < maxcon; i++) { if (con[i].fd != -1 && FD_ISSET(con[i].fd, fdsr)) handler(&con[i]); if (con[i].fd != -1 && FD_ISSET(con[i].fd, fdsw)) handlew(&con[i], clients + 5 < maxcon); } if (FD_ISSET(s, fdsr)) { sinlen = sizeof(sin); s2 = accept(s, (struct sockaddr *)&sin, &sinlen); if (s2 == -1) /* accept failed, they may try again */ continue; for (i = 0; i < maxcon; i++) if (con[i].fd == -1) break; if (i == maxcon) close(s2); else { initcon(&con[i], s2, (struct sockaddr *)&sin); syslog_r(LOG_INFO, &sdata, "%s: connected (%d/%d)%s%s", con[i].addr, clients, blackcount, ((con[i].lists == NULL) ? "" : ", lists:"), ((con[i].lists == NULL) ? "": con[i].lists)); } } if (FD_ISSET(conflisten, fdsr)) { sinlen = sizeof(lin); conffd = accept(conflisten, (struct sockaddr *)&lin, &sinlen); if (conffd == -1) /* accept failed, they may try again */ continue; else if (ntohs(lin.sin_port) >= IPPORT_RESERVED) { close(conffd); conffd = -1; } } if (conffd != -1 && FD_ISSET(conffd, fdsr)) do_config(); if (trapfd != -1 && FD_ISSET(trapfd, fdsr)) read_configline(trapcfg); if (syncrecv && FD_ISSET(syncfd, fdsr)) sync_recv(); } exit(1); }
static void event_handler(switch_event_t *event) { do_config(SWITCH_TRUE); }
static int fbsplash_load() { fb_fd = -1; last_pos = 0; /* Kick start our TTF library */ if (TTF_Init() < 0) { printk("Couldn't initialise TTF.\n"); } /* Find out the FB size */ if (get_fb_settings(0)) { printk("Couldn't get fb settings.\n"); return 1; } arg_vc = get_active_vt(); arg_mode = 's'; /* Read theme config file */ if (arg_theme == NULL) arg_theme = DEFAULT_THEME; config_file = get_cfg_file(arg_theme); if (!config_file) { printk("Couldn't load config file %s.\n", arg_theme); return 1; } else printk("Using configuration file %s.\n", config_file); parse_cfg(config_file); /* Prime the font cache with glyphs so we don't need to allocate them later */ TTF_PrimeCache("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 -.", global_font, TTF_STYLE_NORMAL); boot_message = rendermessage; fb_fd = open_fb(); if (fb_fd == -1) { printk("Couldn't open framebuffer device.\n"); return 1; } if (fb_fix.visual == FB_VISUAL_DIRECTCOLOR) set_directcolor_cmap(fb_fd); fbsplash_fd = open(SPLASH_DEV, O_WRONLY); /* Don't worry if it fails */ do_getpic(FB_SPLASH_IO_ORIG_USER, 1, 'v'); /* Don't worry if it fails */ if (do_getpic(FB_SPLASH_IO_ORIG_USER, 0, 's') == -1) no_silent_image = 1; /* We do care if this fails. */ /* These next two touch the kernel and are needed even for silent mode, to * get the colours right (even on 32-bit depth displays funnily enough. */ do_config(FB_SPLASH_IO_ORIG_USER); cmd_setstate(1, FB_SPLASH_IO_ORIG_USER); /* copy the silent pic to base_image for safe keeping */ if (!no_silent_image) { base_image_size = silent_img.width * silent_img.height * (silent_img.depth >> 3); base_image = malloc(base_image_size); if (!base_image) { printk("Couldn't get enough memory for framebuffer image.\n"); return 1; } memcpy(base_image, (void*)silent_img.data, base_image_size); }
/* * -- parse_cfgline * * parses a line in the configuration file. the way it operates * is simple: split the line into NULL-separated keywords and then * call do_config() to actually update the global "map". * note that this function handles multiple lines as well. * it keeps quite a lot of state between calls in order to process * the multiple lines as a single one. * */ static void parse_cfgline(struct _como * m, const char *line) { static enum { IN_BLANK, IN_WORD, IN_QUOTES, END_QUOTES, IN_ML_COMMENT, ESCAPE, DONE } state = DONE; static int linenum; static uint dst; /* output buffer, size and pointers */ static uint len; static char *buf; int argc = 0; uint i, srclen; #define EOL "\n\r" /* end of line */ #define WHITESP " \t\f\v\n\r" /* whitespace */ #define COMMENT "#" /* comment markers */ #define QUOTE "\"" /* quote markers */ #define BACKSLASH "\\" /* backslash */ srclen = strlen(line); linenum++; /* * check for any leftover from the previous round. */ if (state == DONE) { dst = 0; state = IN_BLANK; } logmsg(V_LOGCONFIG, "parse [%3d] [%s]\n", linenum, line); for (i = 0; i < srclen && state != DONE ; i++) { char c = line[i]; int copy = 0; /* must copy this character */ int end_token = 0; /* and also this is the end of a token */ if (c == '\0') { logmsg(LOGWARN, "unexpected end of line\n"); break; } switch (state) { case DONE: /* we'll never get here, anyways */ break; case IN_BLANK: /* we are seeing blanks. Just skip until next keyword */ if (index(WHITESP, c)) /* keep skipping spaces */ break; if (index(COMMENT, c)) { /* end of line */ state = DONE; break; } if (index(QUOTE, c)) { /* start quote */ state = IN_QUOTES; break; } if (c == '/' && line[i + 1] == '*') { state = IN_ML_COMMENT; i++; break; } if (isalnum(c)) { copy = 1; state = IN_WORD; break; } if (c == '\\' && i == srclen-1) /* line cont */ return; logmsg(LOGCONFIG, "invalid char in line %d [%s]\n", linenum, line+i); dst = 0; return; /* error */ case IN_WORD: /* in a keyword. Keep reading until done. */ if (index(WHITESP, c)) { end_token = 1; state = IN_BLANK; break; } if (index(COMMENT, c)) { /* end of line */ end_token = 1; state = DONE; break; } if (index(QUOTE, c)) { /* start quote */ logmsg(LOGCONFIG, "invalid char in line %d [%s]\n", linenum, line+i); dst = 0; return; /* error */ } if (c == '/' && line[i + 1] == '*') { state = IN_ML_COMMENT; i++; break; } /* assume all the rest is valid (could be more restrictive). */ copy = 1; break; case IN_QUOTES: /* wait for end-quote */ if (index(BACKSLASH, c)) { state = ESCAPE; break; } if (index(QUOTE, c)) { /* end quote */ state = END_QUOTES; break; } /* anything is fine here */ copy = 1; break; case ESCAPE: copy = 1; state = IN_QUOTES; break; case END_QUOTES: end_token = 1; state = IN_BLANK; break; case IN_ML_COMMENT: if (c == '*' && line[i + 1] == '/') { state = DONE; i++; } break; } if (copy) buf = add_char(buf, c, &dst, &len); if (end_token) { buf[dst++] = '\0'; argc++; } } if (dst > 0 && buf[dst-1] == '\\') { buf = add_char(buf, '\n', &dst, &len); return; } switch(state) { case IN_QUOTES: case ESCAPE: logmsg(LOGCONFIG, "missing endquote in line %d [%s]\n", linenum, line); dst = 0; return; /* error */ case END_QUOTES: case IN_WORD: buf = add_char(buf, '\0', &dst, &len); argc++; /* FALLTHROUGH */ case DONE: case IN_BLANK: state = DONE; break; case IN_ML_COMMENT: break; } /* now we have NUL-separated keywords. */ if (argc == 0) { logmsg(V_LOGCONFIG, "empty line\n"); } else { char **argv; char * str; logmsg(V_LOGCONFIG, ""); /* start print */ argv = safe_malloc(argc * sizeof(char *)); for (i=0, argc = 0; i<dst;i++) { argv[argc++] = &buf[i]; logmsg(0, "<%s> ", buf+i); while (i<dst && buf[i] != '\0') i++; } logmsg(0, "\n"); str = do_config(m, argc, argv); if (str != NULL) logmsg(LOGWARN, "%s (line: %d): %s\n", line, linenum, str); free(argv); } }
/* * -- configure * * do a first pass of the command line parameters to find all * configuration files. the options in those files are processed * before any other command line parameter. command line will * overwrite any other configuration, as well as the last config * file will overwrite previous config files. * */ void configure(struct _como * m, int argc, char ** argv) { cli_args_t cli_args; int config_file_exists; int c, i, j; DIR *d; if (m->cli_args.done_flag == 0) { parse_cmdline(&cli_args, argc, argv); if (cli_args.logflags != -1) { m->logflags = cli_args.logflags; m->cli_args.logflags_set = 1; } if (cli_args.dbdir != NULL) { safe_dup(&m->dbdir, cli_args.dbdir); m->cli_args.dbdir_set = 1; } if (cli_args.libdir != NULL) { safe_dup(&m->libdir, cli_args.libdir); m->cli_args.libdir_set = 1; } if (cli_args.query_port != -1) { m->node->query_port = cli_args.query_port; m->cli_args.query_port_set = 1; } if (cli_args.mem_size != 0) { m->mem_size = cli_args.mem_size; m->cli_args.mem_size_set = 1; } m->exit_when_done = cli_args.exit_when_done; } m->runmode = cli_args.runmode; m->inline_fd = (m->runmode == RUNMODE_INLINE) ? 1 /* stdout */ : -1; m->debug = cli_args.debug; /* * build list of config files */ config_file_exists = 0; for (c = 0; c < cli_args.cfg_files_count; c++) { config_file_exists = 1; parse_cfgfile(m, cli_args.cfg_files[c]); } if (!config_file_exists && m->runmode != RUNMODE_INLINE) parse_cfgfile(m, DEFAULT_CFGFILE); /* add default config file */ if (m->runmode == RUNMODE_INLINE) { char *conf_argv[2]; m->exit_when_done = 1; if (cli_args.sniffer != NULL) { add_sniffer(m, cli_args.sniffer, NULL, NULL); } /* prepare the arguments for do_config() */ conf_argv[0] = "module"; conf_argv[1] = cli_args.module; do_config(m, 2, conf_argv); if (cli_args.module_args != NULL) { conf_argv[0] = "args"; conf_argv[1] = cli_args.module_args; do_config(m, 2, conf_argv); } if (cli_args.filter != NULL) { conf_argv[0] = "filter"; conf_argv[1] = cli_args.filter; do_config(m, 2, conf_argv); } conf_argv[0] = "end"; do_config(m, 1, conf_argv); } /* * now look into the virtual nodes and replicate * all modules that have been found in the config file(s) * * these new modules will have the same name but will be * running the additional filter associated with the virtual * node and save data in the virtual node dbdir. * * XXX all virtual nodes will be running on demand and * the source is defined in the configuration (or assumed to * be a trace module). later there shouldn't be a need * for defining the source module anyway... * */ for (i = 0, j = m->module_last; i <= j; i++) { module_t * orig; int node_id; orig = &m->modules[i]; for (node_id = 1; node_id < m->node_count; node_id++) { module_t * mdl; char * nm; /* create a new module and copy it from new module */ mdl = copy_module(m, orig, node_id, -1, m->node[node_id].args); mdl->running = RUNNING_ON_DEMAND; /* append node id to module's output file */ asprintf(&nm, "%s-%d", mdl->output, mdl->node); safe_dup(&mdl->output, nm); free(nm); /* add the node filter to the module filter */ if (m->node[node_id].filter_str) { char * flt; if (!strcmp(mdl->filter_str, "all")) asprintf(&flt, "%s", m->node[node_id].filter_str); else asprintf(&flt,"(%s) and (%s)", m->node[node_id].filter_str, mdl->filter_str); mdl->filter_str = flt; /* FIXME: possible leak */ } /* add the node arguments to the module arguments */ if (m->node[node_id].args) { int k; for (k = 0; m->node[node_id].args[k]; k++) { /* * XXX we copy one argument at a time to avoid * having to count them first. FIX THIS */ mdl->args = copy_args(mdl->args, &m->node[node_id].args[k], 1); } } logmsg(LOGUI, "... module%s %s [%d][%d] ", (mdl->running == RUNNING_ON_DEMAND) ? " on-demand" : "", mdl->name, mdl->node, mdl->priority); logmsg(LOGUI, " filter %s; out %s (%uMB)\n", mdl->filter_str, mdl->output, mdl->streamsize/(1024*1024)); if (mdl->description != NULL) logmsg(LOGUI, " -- %s\n", mdl->description); } } /* * open the dbdir for all nodes (virtual ones included) */ if (m->runmode == RUNMODE_NORMAL) { if (m->dbdir == NULL) panicx("missing db-path"); d = opendir(m->dbdir); if (d == NULL) createdir(m->dbdir); else closedir(d); } /* * process the AS file */ asn_readfile(m->asnfile); }
int main() { static char load_filename[512]; char *romname = NULL; float audioStart; // this is a float to count the half sample per frame needed ho have precise timing u32 audioTarget, audioEnd; srvInit(); aptInit(); hidInit(); APT_CheckNew3DS(&isN3DS); if(isN3DS) osSetSpeedupEnable(true); get_config_path(); sprintf(savename, "%s/Handy3ds.cfg", config_base_path); // using savename char buffer to save memory do_config(savename); handy_3ds_video_init(); sprintf(bios_path_and_name, "%s/%s", config_bios_path, "lynxboot.img"); // Call filebrowser if(gui_LoadFile(load_filename)!= -1) { romname = (char *)&load_filename; do { hidScanInput(); } while (hidKeysHeld()); } else { handy_3ds_quit(); } // Primary initalise of Handy - should be called AFTER _Init() but BEFORE handy_3ds_video_setup() handy_3ds_core_init(romname); // Initialise Handy 3ds video handy_3ds_video_setup(1, 0, 0, 32, LynxScale, 0, 0); // Initialise Handy 3ds audio printf("\nInitialising 3DS Audio... "); gAudioEnabled = handy_3ds_audio_init(); printf("[DONE]\n"); // Setup of Handy Core video handy_3ds_video_reinit(32); printf("Starting Lynx Emulation...\n"); bool touched = false; audioStart = gAudioBufferPointer; // both should be 0 at this point // initialize timers u64 tickcurr, syncticknext,synctickres; u64 fpsticknext,fpstickres; int frameSyncPeriod; if(isN3DS) frameSyncPeriod = 1; else frameSyncPeriod = 12; fpstickres= TICKS_PER_SEC; synctickres = TICKS_PER_FRAME * frameSyncPeriod; // on o3ds the sync is every 12 frame, i.e. 5 times every sec tickcurr=svcGetSystemTick(); fpsticknext = tickcurr + fpstickres; syncticknext = tickcurr + synctickres; int fpscnt = 0, synccnt = 0; gThrottleMaxPercentage = isN3DS?100:50; // !! TO DO: check if 50 is the best value. while(!emulation) { // Initialise Handy button events int OldKeyMask, KeyMask = mpLynx->GetButtonData(); OldKeyMask = KeyMask; // Getting events for keyboard and/or joypad handling hidScanInput(); if (hidKeysHeld() & KEY_TOUCH) { touched = true; } else { if (touched) { handy_3ds_audio_pause(); gui_Run(); KeyMask = 0; touched = false; // audioStart = gAudioBufferPointer; do { hidScanInput(); } while (hidKeysHeld()); gThrottleMaxPercentage = isN3DS?100:50; // !! Loading a savestate overrides this value, so we force it again exiting menu fpscnt = 0; synccnt = 0; tickcurr=svcGetSystemTick(); fpsticknext = tickcurr + fpstickres; syncticknext = tickcurr + synctickres; } else { touched = false; } } KeyMask = handy_3ds_on_key_down(hidKeysHeld(), KeyMask); // Check if there are handling events and then update the Handy button events. if (OldKeyMask != KeyMask) mpLynx->SetButtonData(KeyMask); // Update TimerCount gTimerCount++; while( handy_3ds_update() ) { //!! hidScanInput(); u32 held = hidKeysHeld(); if (held & KEY_SELECT) { // handy_3ds_video_quit(); // handy_3ds_audio_quit(); // exit(EXIT_SUCCESS); //break; touched = true; // enter menu } //!! if(!gSystemHalt) { if (!handy_3ds_audio_getstate()) { audioStart=0.0; // reset counter gAudioBufferPointer = 0; // reset buffer. really not needed since we set it to 0 in handy_3ds_audio_pause(). } // increase sound samples counter - 367,5 samples per frame at 60 fps audioEnd = (int)(audioStart + 367.5) % HANDY_AUDIO_BUFFER_SIZE; // filling 1 half of the buffer, roughly enough for slow frames on o3DS without risk of buffer head to reach the tail during the 10 frames before resync. audioTarget = (int)(audioStart + HANDY_AUDIO_BUFFER_SIZE/2.1) % HANDY_AUDIO_BUFFER_SIZE; if (audioTarget>audioStart) while (gAudioBufferPointer<audioTarget) mpLynx->Update(); else while ((gAudioBufferPointer>audioStart)||(gAudioBufferPointer<audioTarget)) mpLynx->Update(); if(Handy_cfg_Throttle && Handy_cfg_Sound && gAudioEnabled) { if (handy_3ds_audio_getstate()) handy_3ds_audio_callback(audioStart, (int)(audioTarget-audioStart)); else handy_3ds_audio_start(22050, audioStart); } audioStart = audioEnd; } else { printf("gSystemHalt : %ld\n", gSystemHalt); gTimerCount++; } system_checkPolls(); } // Timing fpscnt++; synccnt++; if (Handy_cfg_Throttle) { if (synccnt==frameSyncPeriod){ svcSleepThread((syncticknext - svcGetSystemTick()) / TICKS_PER_NSEC); } } tickcurr=svcGetSystemTick(); if (tickcurr >= syncticknext) { syncticknext += synctickres; synccnt = 0; } if (tickcurr >= fpsticknext) { fpsticknext += fpstickres; fps_counter = fpscnt; fpscnt = 0; } } // while(!emulation) osSetSpeedupEnable(true); return 0; }
int main(int argc, char *argv[]) { int c; char *config_file = DEFAULT_CONFIG_FILE; sigset_t sigset; static struct option long_options[] = { {"help", 0, 0, 'h'}, {"version", 0, 0, 'V'}, {0, 0, 0, 0} }; while ((c = getopt_long(argc, argv, "hVf:vi", long_options, 0)) != EOF) { switch (c) { case 'h': Usage(argv[0]); exit(0); case 'V': printf("beoserv version %s\n", PACKAGE_VERSION); exit(0); break; case 'i': ignore_version = 1; break; case 'f': config_file = optarg; break; case 'v': verbose++; break; default: exit(1); } } if (argc - optind != 0) { Usage(argv[0]); exit(1); } openlog(argv[0], LOG_PERROR, LOG_DAEMON); if (do_config(config_file)) exit(1); openlog(argv[0], verbose ? LOG_PERROR : 0, LOG_DAEMON); if (verbose == 0) daemonize(); sigemptyset(&sigset); sigaddset(&sigset, SIGHUP); sigaddset(&sigset, SIGCHLD); sigprocmask(SIG_BLOCK, &sigset, 0); signal(SIGCHLD, (void (*)(int))sigchld_handler); signal(SIGHUP, (void (*)(int))sighup_handler); while (1) { int r, maxfd; fd_set rset, wset, eset; maxfd = -1; FD_ZERO(&rset); FD_ZERO(&wset); FD_ZERO(&eset); tmo.tv_sec = 99999; /* bigger than anything we're gonna see. */ tmo.tv_usec = 0; send_select_1(&maxfd, &rset, &wset, &eset, &tmo); rarp_select_1(&maxfd, &rset, &wset, &eset, &tmo); nodeup_select_1(&maxfd, &rset, &wset, &eset, &tmo); sigprocmask(SIG_UNBLOCK, &sigset, 0); r = select(maxfd + 1, &rset, &wset, &eset, &tmo); sigprocmask(SIG_BLOCK, &sigset, 0); if (r == -1 && errno != EINTR) { syslog(LOG_ERR, "select(): %s", strerror(errno)); exit(1); } nodeup_everytime(); if (r > 0) { send_select_2(&rset, &wset, &eset); rarp_select_2(&rset, &wset, &eset); nodeup_select_2(&rset, &wset, &eset); } if (r == 0) { nodeup_timeout(); } if (do_config_reload) { syslog(LOG_INFO, "Re-reading configuration from %s", config_file); do_config(config_file); do_config_reload = 0; } } }
void simple_file_logger::synch_configure() { do_config(true); }