int main (int argc, char * argv[]) { if (argc != 3) { fprintf(stderr, "Usage: %s hostname port\n", argv[0]); return -1; } char * hostname = argv[1]; char * port = argv[2]; int length = strlen(hostname) + strlen(port) + 1; //+ 1 for ':' char result[length]; bzero(result, length); strcpy(result, hostname); strcat(result, ":"); strcat(result, port); const char * TRACKER_NAME = "Tracker0"; int CONNECTION_PORT = vrpn_DEFAULT_LISTEN_PORT_NO; vrpn_Connection * connection = vrpn_get_connection_by_name(result); //create a dummy server vrpn_Tracker_NULL * null_tracker = new vrpn_Tracker_NULL(TRACKER_NAME, connection, 1, 60.0); vrpn_Tracker_Remote * tracker = new vrpn_Tracker_Remote(TRACKER_NAME, connection); tracker->register_change_handler(NULL, handle_data); while (1) { null_tracker->mainloop(); tracker->mainloop(); connection->mainloop(); vrpn_SleepMsecs(1000); } disconn(socketfd); return 0; }
int init(int ac, char **av) { int i; int openlog_failed = 0, openlog_errno = 0; int started_from_term = isatty(0) && isatty(1) && isatty(2); /* Imported from main.c */ extern void sighandler(int signum); /* Set file creation mask and group ID. */ #if defined(DEFUMASK) && HAVE_UMASK umask(DEFUMASK); #endif if (set_group() < 0) return -1; /* Parse command line for -dir option. */ parse_dir_options(ac, av); /* Chdir to Services data directory. */ if (chdir(services_dir) < 0) { fprintf(stderr, "chdir(%s): %s\n", services_dir, strerror(errno)); return -1; } /* Open logfile, and complain if we didn't. */ if (open_log() < 0) { openlog_errno = errno; if (started_from_term) { fprintf(stderr, "ATENCION: No puedo abrir el archivo de log %s: %s\n", log_filename, strerror(errno)); } else { openlog_failed = 1; } } /* Read configuration file; exit if there are problems. */ if (!read_config()) return -1; /* Parse all remaining command-line options. */ parse_options(ac, av); /* Detach ourselves if requested. */ if (!nofork) { if ((i = fork()) < 0) { perror("fork()"); return -1; } else if (i != 0) { exit(0); } if (started_from_term) { close(0); close(1); close(2); } if (setpgid(0, 0) < 0) { perror("setpgid()"); return -1; } } /* Write our PID to the PID file. */ write_pidfile(); /* Announce ourselves to the logfile. */ if (debug || readonly || skeleton) { log("euskalirc-services-bdd %s (compilados para %s) iniciados (opciones:%s%s%s)", version_number, version_protocol, debug ? " debug" : "", readonly ? " readonly" : "", skeleton ? " skeleton" : ""); } else { log("euskalirc-services-bdd %s (compilados para %s) iniciados.", version_number, version_protocol); } start_time = time(NULL); /* If in read-only mode, close the logfile again. */ if (readonly) close_log(); /* Set signal handlers. Catch certain signals to let us do things or * panic as necessary, and ignore all others. */ #ifdef NSIG for (i = 1; i <= NSIG; i++) #else for (i = 1; i <= 32; i++) #endif signal(i, SIG_IGN); signal(SIGINT, sighandler); signal(SIGTERM, sighandler); signal(SIGQUIT, sighandler); signal(SIGSEGV, sighandler); signal(SIGBUS, sighandler); signal(SIGQUIT, sighandler); signal(SIGHUP, sighandler); signal(SIGILL, sighandler); signal(SIGTRAP, sighandler); #ifdef SIGIOT signal(SIGIOT, sighandler); #endif signal(SIGFPE, sighandler); signal(SIGUSR1, sighandler); /* This is our "out-of-memory" panic switch */ /* Initialize multi-language support */ lang_init(); if (debug) log("debug: Cargando lenguajes"); /* Initialiize subservices */ ns_init(); cs_init(); #ifdef CREGSERV cr_init(); #endif ms_init(); os_init(); load_spam(); load_ipv(); /*leyendo datos de frases*/ /* Load up databases */ if (!skeleton) { load_ns_dbase(); if (debug) log("debug: Cargando la DB de %s (1/7)", s_NickServ); load_cs_dbase(); if (debug) log("debug: Cargando la DB de %s (2/7)", s_ChanServ); load_cr_dbase(); if (debug) log("debug: Cargando la DB de %s (3/7)", s_CregServ); } load_os_dbase(); if (debug) log("debug: Cargando la DB de %s (4/7)", s_OperServ); load_akill(); if (debug) log("debug: Cargando la DB de GLINES (5/7)"); load_news(); if (debug) log("debug: Cargando la DB de NOTICIAS (6/7)"); if (debug) log("debug: Cargando la DB de SPAM (7/7)"); load_cr_dbase(); load_ipv(); log("Cargadas las bases de datos"); /* Connect to the remote server */ servsock = conn(RemoteServer, RemotePort, LocalHost, LocalPort); if (servsock < 0) fatal_perror("No puedo conectar al servidor"); send_cmd(NULL, "PASS :%s", RemotePassword); #ifdef IRC_UNDERNET_P09 send_cmd(NULL, "SERVER %s 1 %lu %lu P09 :%s", ServerName, start_time, start_time, ServerDesc); #else /* IRC_UNDERNET_P10 */ send_cmd(NULL, "SERVER %s %d 0 %ld J10 %cD] :%s", ServerName, 2, start_time, convert2y[ServerNumerico], ServerDesc); #endif sgets2(inbuf, sizeof(inbuf), servsock); if (strnicmp(inbuf, "ERROR", 5) == 0) { /* Close server socket first to stop wallops, since the other * server doesn't want to listen to us anyway */ disconn(servsock); servsock = -1; fatal("El servidor ha devuelto: %s", inbuf); } /* Announce a logfile error if there was one */ if (openlog_failed) { canalopers(NULL, "4ATENCION: No puedo abrir el fichero de log: 12%s", strerror(openlog_errno)); } /* Bring in our pseudo-clients */ introduce_user(NULL); send_cmd(ServerName, "SETTIME %lu", time(NULL)); #if HAVE_ALLWILD_NOTICE send_cmd(s_OperServ, "NOTICE $*.%s :Establecidos los servicios de la RED.", NETWORK_DOMAIN); #else # ifdef NETWORK_DOMAIN send_cmd(s_OperServ, "NOTICE $*.%s :Establecidos los servicios de la RED.", NETWORK_DOMAIN); # else Go through all common top-level domains. If you have others, * add them here. send_cmd(s_OperServ, "NOTICE $*.es :Establecidos los servicios de la RED."); send_cmd(s_OperServ, "NOTICE $*.com :Establecidos los servicios de la RED."); send_cmd(s_OperServ, "NOTICE $*.net :Establecidos los servicios de la RED."); send_cmd(s_OperServ, "NOTICE $*.org :Establecidos los servicios de la RED."); send_cmd(s_OperServ, "NOTICE $*.edu :Establecidos los servicios de la RED."); send_cmd(s_OperServ, "NOTICE $*.tk :Establecidos los servicios de la RED."); # endif #endif join_chanserv(); /* Success! */ return 0; }
int init(int ac, char **av) { /* temporary ChannelInfo *ci; NickInfo *ni; */ int i; int openlog_failed = 0, openlog_errno = 0; int started_from_term = isatty(0) && isatty(1) && isatty(2); /* Initialize pseudo-random number generator. */ srand(time(NULL) ^ getppid() ^ getpid()<<16); /* Set file creation mask and group ID. */ #if defined(DEFUMASK) && HAVE_UMASK umask(DEFUMASK); #endif if (set_group() < 0) return -1; /* Parse command-line options; exit if an error occurs. */ if (parse_options(ac, av) < 0) return -1; /* Chdir to Services data directory. */ if (chdir(services_dir) < 0) { fprintf(stderr, "chdir(%s): %s\n", services_dir, strerror(errno)); return -1; } /* Open logfile, and complain if we didn't. */ if (open_log() < 0) { openlog_errno = errno; if (started_from_term) { fprintf(stderr, "Warning: unable to open log file %s: %s\n", log_filename, strerror(errno)); } else { openlog_failed = 1; } } /* Read configuration file; exit if there are problems. */ if (!read_config()) return -1; /* Re-parse command-line options (to override configuration file). */ parse_options(ac, av); /* Detach ourselves if requested. */ if (!nofork) { if ((i = fork()) < 0) { perror("fork()"); return -1; } else if (i != 0) { exit(0); } if (started_from_term) { close(0); close(1); close(2); } if (setpgid(0, 0) < 0) { perror("setpgid()"); return -1; } } #ifdef MEMCHECKS /* Account for runtime memory. Do this after forking to avoid a bogus * "XXX bytes leaked on exit" message when the parent exits. */ init_memory(); #endif /* Write our PID to the PID file. */ write_pidfile(); /* Announce ourselves to the logfile. */ if (debug || readonly || skeleton || noexpire) { log("Services %s (compiled for %s) starting up (options:%s%s%s%s)", version_number, version_protocol, debug ? " debug" : "", readonly ? " readonly" : "", skeleton ? " skeleton" : "", noexpire ? " noexpire" : ""); } else { log("Services %s (compiled for %s) starting up", version_number, version_protocol); } start_time = time(NULL); /* If in read-only mode, close the logfile again. */ if (readonly) close_log(); /* Set signal handlers. Catch certain signals to let us do things or * panic as necessary, and ignore all others. */ #ifdef NSIG for (i = 1; i <= NSIG; i++) { #else for (i = 1; i <= 32; i++) { #endif if (i != SIGPROF) signal(i, SIG_IGN); } signal(SIGINT, weirdsig_handler); signal(SIGTERM, weirdsig_handler); signal(SIGQUIT, weirdsig_handler); #ifndef DUMPCORE signal(SIGSEGV, weirdsig_handler); #endif signal(SIGBUS, weirdsig_handler); signal(SIGQUIT, weirdsig_handler); signal(SIGHUP, weirdsig_handler); signal(SIGILL, weirdsig_handler); signal(SIGTRAP, weirdsig_handler); signal(SIGFPE, weirdsig_handler); #ifdef SIGIOT signal(SIGIOT, weirdsig_handler); #endif /* This is our "out-of-memory" panic switch */ signal(SIGUSR1, weirdsig_handler); /* Initialize multi-language support */ lang_init(); if (debug) log("debug: Loaded languages"); /* Initialiize subservices */ ns_init(); cs_init(); #ifdef USE_MYSQL if(!db_connect(1)) fatal("could not connect to mysql database"); #endif /* Load up databases */ if (!skeleton) { db_load_ns(); //load_ns_dbase(); if (debug) log("debug: Loaded %s database (1/7)", s_NickServ); db_load_cs(); //load_cs_dbase(); if (debug) log("debug: Loaded %s database (2/7)", s_ChanServ); /* start: temporary code */ /* for (ni = firstnick(); ni; ni = nextnick()) { genpass(ni->pass); email_pass(ni->email ? ni->email : "invalid", ni->pass, ni->nick); log("debug: genpass for [%s]", ni->nick); #ifdef USE_ENCRYPTION encrypt_in_place(ni->pass, PASSMAX - 1); #endif db_nick_set(ni, "pass", ni->pass); } for(ci = cs_firstchan(); ci; ci = cs_nextchan()) { genpass(ci->founderpass); email_pass(ci->email ? ci->email : "invalid", ci->founderpass, ci->name); log("debug: genpass for [%s]", ci->name); #ifdef USE_ENCRYPTION encrypt_in_place(ci->founderpass, PASSMAX - 1); #endif db_chan_set(ci, "founderpass", ci->founderpass); } exit(0); */ /* for (ni = firstnick(); ni; ni = nextnick()) { if(db_add_nick(ni) == -1) log("dberror: while adding nicks. continuing"); } for(ci = cs_firstchan(); ci; ci = cs_nextchan()) { if(db_add_channel(ci) == -1) log("dberror: while adding channels. continuing"); } exit(1); */ /* end: temporary code */ } log("Databases loaded"); /* Connect to the remote server */ servsock = conn(RemoteServer, RemotePort, LocalHost, LocalPort); if (servsock < 0) fatal_perror("Can't connect to server"); send_server(); sgets2(inbuf, sizeof(inbuf), servsock); if (strnicmp(inbuf, "ERROR", 5) == 0) { /* Close server socket first to stop wallops, since the other * server doesn't want to listen to us anyway */ disconn(servsock); servsock = -1; fatal("Remote server returned: %s", inbuf); } /* Announce a logfile error if there was one */ if (openlog_failed) { wallops(NULL, "Warning: couldn't open logfile: %s", strerror(openlog_errno)); } /* Bring in our pseudo-clients */ introduce_user(NULL); /* Success! */ return 0; }