Esempio n. 1
0
int main(int argc, char *argv[])
{
    chdir(BBSHOME);
    setuid(BBSUID);
    setgid(BBSGID);
    setreuid(BBSUID, BBSUID);
    setregid(BBSGID, BBSGID);

#ifndef CYGWIN
#undef time
    bbssettime(time(0));
    sleep(1);
#define time(x) bbstime(x)
#endif

    setpublicshmreadonly(0);

#ifndef CYGWIN
    setpublicshmreadonly(1);
#endif
    init_bbslog();
    if (argc > 1) {
        if (strcasecmp(argv[1], "killuser") == 0) {
			//Added by Marvel
            resolve_utmp(); 

            if (resolve_ucache() != 0)
                return -1;
            return dokilluser();
        }
        if (strcasecmp(argv[1], "giveup") == 0) {
            if (resolve_ucache() != 0)
                return -1;
            return doupdategiveupuser();
        }
        if (strcasecmp(argv[1], "allboards") == 0)
            return dokillalldir();
        if (strcasecmp(argv[1], "daemon") == 0)
            return miscd_dodaemon(argv[1], argv[2]);
        if (strcasecmp(argv[1], "killdir") == 0)
            return dokilldir(argv[2]);
        if (strcasecmp(argv[1], "flush") == 0) {
            if (resolve_ucache() != 0)
	              return -1;
            resolve_boards();
            flushdata();
            return 0;
        }
        return miscd_dodaemon(NULL, argv[1]);
    }
    printf("Usage : %s daemon: to run as a daemon (this is the most common use)\n", argv[0]);
    printf("        %s killuser: to kill old users\n", argv[0]);
    printf("        %s giveup: to unlock given-up users\n", argv[0]);
    printf("        %s killdir <BOARDNAME>: to delete old file in <BOARDNAME>\n", argv[0]);
    printf("        %s allboards: to delete old files in all boards\n", argv[0]);
    printf("        %s flush: to synchronize .PASSWDS and .BOARDS to disk\n", argv[0]);
    printf("That's all, folks. See doc/README.SYSOP for more details\n");

    return 0;
}
Esempio 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;
}
Esempio 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);
    }
}
Esempio n. 4
0
static int initialize_ext()
{
    char old_cwd[256];
    getcwd(old_cwd, sizeof(old_cwd));

    chdir(BBSHOME);
    get_publicshm();
    resolve_ucache();
    resolve_utmp();
    resolve_boards();
    init_bbslog();
    www_data_init();
    ext_init = 1;

    chdir(old_cwd);
    return ext_init;
}