Ejemplo n.º 1
0
/**
 *
 * initialization
 *
 */
void Prepare(int argc, char** argv)
{
openlog("dtmfserver ", LOG_NDELAY | LOG_PID, LOG_USER);
syslog(LOG_INFO, "Старт службы dtmf\n");

// смотрим чего от нас требуется
analize_opts(argc, argv);

// простая проверка
if((algo.params.head!=0)&&(demon!=0))
  {
  //wtf
  syslog(LOG_ERR, "Невозможно выводить заголовок в режиме демона\n");
  go_out();
  };

// демонизация
if(demon!=0)
  {
  if(!dodaemon())
    {
    go_out();
    };
  };

//для паузы
init_buffer();

// для звука
open_device();
setup_device();
//simple_setup();
// dtmf
dtmf_prepare();
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
    umask(027);

    chdir(BBSHOME);
    setuid(BBSUID);
    setreuid(BBSUID, BBSUID);
    setgid(BBSGID);
    setregid(BBSGID, BBSGID);

    if (!debug && dodaemon("bbslogd", true, true)) {
        bbslog("3error", "bbslogd had already been started!");
        return 0;
    }

    signal(SIGALRM , on_log_alarm );
    signal(SIGTERM , on_log_exit  );
    signal(SIGINT  , on_log_exit  );
    signal(SIGABRT , on_log_exit  );
    signal(SIGHUP  , on_log_exit  );
    signal(SIGPIPE , SIG_IGN      );

    int msqid = init_bbslog();
    if (msqid < 0) {
        fprintf (stderr, "init_bbslog: %d\n", msqid);
        return -1;
    }
    fprintf (stderr, "message queue of bbsd is ok: %d\n", msqid);

    // init redis
    if (redis_open(&redis) == REDIS_OK) {
        fprintf (stderr, "Redis opened\n");
    }

    // init logs
    log_init();
    alarm(flush_interval);

    // enter event loop
    struct bbs_msgbuf *msg;
    while ((msg = log_rcv(msqid)) != NULL) {
        if (debug) {
            fprintf (stderr, "msg: %d %s\n", (int)msg->mtype, msg->mtext);
        }

        log_write(msg);
    }

    // clean everything
    on_log_exit(0);

    return 0;
}
Ejemplo n.º 3
0
int main()
{
    int msqid, i;
    struct bbs_msgbuf *msg;

    struct sigaction act;

    umask(027);

    chdir(BBSHOME);
    setuid(BBSUID);
    setreuid(BBSUID, BBSUID);
    setgid(BBSGID);
    setregid(BBSGID, BBSGID);
    if (dodaemon("bbslogd", true, true)) {
        bbslog("3error", "bbslogd had already been started!");
        return 0;
    }
    atexit(flushBBSlog_exit);
    bzero(&act, sizeof(act));
    act.sa_handler = flushlog;
    sigaction(SIGTERM, &act, NULL);
    sigaction(SIGABRT, &act, NULL);
    sigaction(SIGHUP, &act, NULL);
    act.sa_handler = flushBBSlog_time;
    sigaction(SIGALRM, &act, NULL);
    act.sa_handler = trunclog;
    sigaction(SIGUSR1, &act, NULL);
    act.sa_handler = truncboardlog;
    sigaction(SIGUSR2, &act, NULL);
    alarm(60*10); /*十分钟flush一次*/

    msqid = init_bbslog();
    if (msqid < 0)
        return -1;

    gb_trunclog=false;
    truncboard=false;
    openbbslog(1);
    while (1) {
        if ((msg = rcvlog(msqid)) != NULL)
            writelog(msg);
        if (gb_trunclog)
        	do_trunclog();
		else if(truncboard)
			do_truncboardlog();
    }
    flushlog(-1);
    for (i = 0; i < sizeof(logconfig) / sizeof(struct taglogconfig); i++) {
        free(logconfig[i].buf);
    }
}