示例#1
0
文件: update.c 项目: andrewrk/mpd
static void * update_task(void *_path)
{
	const char *path = _path;

	if (path != NULL && *path != 0)
		g_debug("starting: %s", path);
	else
		g_debug("starting");

	modified = update_walk(path, discard);

	if (modified || !db_exists()) {
		GError *error = NULL;
		if (!db_save(&error)) {
			g_warning("Failed to save database: %s",
				  error->message);
			g_error_free(error);
		}
	}

	if (path != NULL && *path != 0)
		g_debug("finished: %s", path);
	else
		g_debug("finished");
	g_free(_path);

	progress = UPDATE_PROGRESS_DONE;
	event_pipe_emit(PIPE_EVENT_UPDATE);
	return NULL;
}
示例#2
0
int Dict::save(char* path, char* filename)
{
    if (1 != db_save((Sdict_build*)_wordDict, path, filename)) {
        return -1;
    }
    return 0;
}
示例#3
0
文件: update.c 项目: Gryllida/atheme
void os_cmd_update(sourceinfo_t *si, int parc, char *parv[])
{
	logcommand(si, CMDLOG_ADMIN, "UPDATE");
	wallops("Updating database by request of \2%s\2.", get_oper_name(si));
	expire_check(NULL);
	if (db_save)
		db_save(NULL);
	/* db_save() will wallops/snoop/log the error */
	command_success_nodata(si, _("UPDATE completed."));
}
示例#4
0
文件: uppg6.c 项目: h4xxel/algdat
int main(int argc, char **argv) {
	struct termios ttystate, ttysave;
	char c;
	srand(time(NULL));
	tcgetattr(STDIN_FILENO, &ttystate);
	ttysave=ttystate;
	ttystate.c_lflag&=~(ICANON);
	ttystate.c_cc[VMIN] = 1;
	tcsetattr(STDIN_FILENO, TCSANOW, &ttystate);
	db_load();
	puts("\"People\" 2013 Axel Isaksson");
	print_menu();
	for(;;) {
		putchar('>');
		c=getchar();
		putchar('\n');
		switch(c) {
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
				menu[c-'1'].action();
			case '\n':
				print_menu();
				break;
			case '6':
			case 'q':
			case 'Q':
				goto quit;
			case 's':
			case 'S':
				db_save();
				break;
			default:
				puts("?");
		}
	}
	quit:
	db_save();
	tcsetattr(STDIN_FILENO, TCSANOW, &ttysave);
	return 0;
}
示例#5
0
static void os_cmd_restart(char *origin)
{
	snoop("UPDATE: \2%s\2", origin);
	wallops("Updating database by request of \2%s\2.", origin);
	expire_check(NULL);
	db_save(NULL);

	logcommand(opersvs.me, user_find_named(origin), CMDLOG_ADMIN, "RESTART");
	snoop("RESTART: \2%s\2", origin);
	wallops("Restarting by request of \2%s\2.", origin);

	runflags |= RF_RESTART;
}
示例#6
0
void
os_cmd_update(struct sourceinfo *si, int parc, char *parv[])
{
	logcommand(si, CMDLOG_ADMIN, "UPDATE");
	wallops("Updating database by request of \2%s\2.", get_oper_name(si));
	expire_check(NULL);
	command_success_nodata(si, _("Updating database."));

	if (db_save)
		db_save(NULL, DB_SAVE_BG_IMPORTANT);

	// db_save() will wallops/snoop/log the error
}
示例#7
0
/* REHASH */
void os_cmd_rehash(sourceinfo_t *si, int parc, char *parv[])
{
	slog(LG_INFO, "UPDATE (due to REHASH): \2%s\2", get_oper_name(si));
	wallops("Updating database by request of \2%s\2.", get_oper_name(si));
	expire_check(NULL);
	if (db_save)
		db_save(NULL, DB_SAVE_BG_IMPORTANT);

	logcommand(si, CMDLOG_ADMIN, "REHASH");
	wallops("Rehashing \2%s\2 by request of \2%s\2.", config_file, get_oper_name(si));

	if (conf_rehash())
		command_success_nodata(si, _("REHASH completed."));
	else
		command_fail(si, fault_nosuch_target, _("REHASH of \2%s\2 failed. Please correct any errors in the file and try again."), config_file);
}
示例#8
0
文件: check_db.c 项目: ryjen/muddled
END_TEST

START_TEST(test_field_map)
{
    struct test
    {
        long id;
        const char *name;
        int value;
    };

    struct test T;

    T.id = 0;
    T.name = str_dup("testA");
    T.value = number_percent();

    field_map table[] =
    {
        {"name", &T.name, SQL_TEXT},
        {"intval", &T.value, SQL_INT},
        {0}
    };

    fail_if(T.value != fm_int(&table[1]));

    T.id = db_save(table, DBNAME, T.id);

    int check = number_percent();

    char buf[BUF_SIZ];

    sprintf(buf, "update "DBNAME" set intval=%d where %s=%ld and name='%s' and intval='%d'", check, tablenameid(DBNAME), T.id, T.name, T.value);

    if (sql_exec(buf) != SQL_OK)
    {
        fail("could not update saved data entry");
    }

    db_load_by_id(table, DBNAME, T.id);

    fail_if(T.value != check);
}
示例#9
0
static void * update_task(void *_path)
{
	const char *path = _path;

	if (path != NULL && *path != 0)
		g_debug("starting: %s", path);
	else
		g_debug("starting");

	modified = update_walk(path, discard);

	if (modified || !db_exists())
		db_save();

	if (path != NULL && *path != 0)
		g_debug("finished: %s", path);
	else
		g_debug("finished");
	g_free(_path);

	progress = UPDATE_PROGRESS_DONE;
	event_pipe_emit(PIPE_EVENT_UPDATE);
	return NULL;
}
示例#10
0
int main(int argc, char *argv[])
{
#define ADD_COUNT    100
#define SEEK_COUNT   100

    sodict_build_t *sdb;
    sodict_snode_t snode;
 
    Sdict_build    *udb;
    Sdict_snode    unode;

    struct timeval ss, se, us, ue;

    printf("Comparison between odict and uldict!\n");

    printf("Create a odict dictionary object ... \t");
    sdb = odb_creat(10000000);
    if (sdb != NULL) {
        printf("OK\n");
    }
    else {
        printf("FAIL\n");
        return 1;
    }

    printf("Create a uldict dictionary object ... \t");
    udb = db_creat(10000000, 0);
    if (sdb != NULL) {
        printf("OK\n");
    }
    else {
        printf("FAIL\n");
        return 1;
    }

    // add node
    printf("Insert %d nodes into odict dictionary object ... \t", ADD_COUNT);
    snode.sign1 = 25;
    snode.sign2 = 30;
    snode.cuint1 = 28;
    snode.cuint2 = 0xffffffff;
    gettimeofday(&ss, NULL);
    for (int i = 0 ; i < ADD_COUNT ; i++) {
        snode.sign1 = 25 + i;
        snode.sign2 = 30 + i;
        if (ODB_ADD_OK != odb_add(sdb, &snode, 1)) {
            printf("FAIL\n");
        }
    }
    gettimeofday(&se, NULL);
    printf("Finished!\n");

    printf("Insert %d nodes into uldict dictionary object ... \t", ADD_COUNT);
    unode.sign1 = 25;
    unode.sign2 = 30;
    unode.code = 28;
    unode.other = 0x00ffffff;
    gettimeofday(&us, NULL);
    for (int i = 0 ; i < ADD_COUNT ; i++) {
        unode.sign1 = 25 + i;
        unode.sign2 = 30 + i;
        db_op1(udb, &unode, ADD);
    }
    gettimeofday(&ue, NULL);
    printf("Finished!\n");
    
    printf("odict add operation: %f ms, %f us per req\n", 
        (se.tv_sec - ss.tv_sec) * 1000 + (se.tv_usec - ss.tv_usec) / 1000.0,
        ((se.tv_sec - ss.tv_sec) * 1000000.0 + (se.tv_usec - ss.tv_usec)) / ADD_COUNT);
    printf("uldict add operation: %f ms, %f us per req\n", 
        (ue.tv_sec - us.tv_sec) * 1000 + (ue.tv_usec - us.tv_usec) / 1000.0,
        ((ue.tv_sec - us.tv_sec) * 1000000.0 + (ue.tv_usec - us.tv_usec)) / ADD_COUNT);

    // seek node
    printf("Seek %d nodes from odict dictionary object ... \t", SEEK_COUNT);
    snode.sign1 = 25;
    snode.sign2 = 30;
    snode.cuint1 = 28;
    snode.cuint2 = 0xffffffff;
    gettimeofday(&ss, NULL);
    for (int i = 0 ; i < SEEK_COUNT ; i++) {
        snode.sign1 = 25 + i;
        snode.sign2 = 30 + i;
        if (ODB_ADD_OK != odb_seek(sdb, &snode)) {
            printf("FAIL\n");
        }
    }
    gettimeofday(&se, NULL);
    printf("Finished!\n");

    odb_adjust(sdb);
    snode.sign1 = 25;
    snode.sign2 = 30;
    snode.cuint1 = 28;
    snode.cuint2 = 0xffffffff;
    for (int i = 0 ; i < SEEK_COUNT ; i++) {
	snode.sign1 = 25 + i;
	snode.sign2 = 30 + i;
	if (ODB_ADD_OK != odb_seek(sdb, &snode)) {
	     printf("FAIL\n");
	}
    }
    
    odb_del(sdb,&snode);
    odb_add(sdb,&snode,1);
    if (ODB_ADD_OK != odb_seek(sdb, &snode)){
    	printf ("fail\n");
    }
    printf("Seek %d nodes from uldict dictionary object ... \t", SEEK_COUNT);
    unode.sign1 = 25;
    unode.sign2 = 30;
    unode.code = 28;
    unode.other = 0x00ffffff;
    gettimeofday(&us, NULL);
    for (int i = 0 ; i < SEEK_COUNT ; i++) {
        unode.sign1 = 25 + i;
        unode.sign2 = 30 + i;
        db_op1(udb, &unode, SEEK);
    }
    gettimeofday(&ue, NULL);
    printf("Finished!\n");

    printf("odict seek operation: %f ms, %f us per req\n", 
        (se.tv_sec - ss.tv_sec) * 1000 + (se.tv_usec - ss.tv_usec) / 1000.0,
        ((se.tv_sec - ss.tv_sec) * 1000000.0 + (se.tv_usec - ss.tv_usec)) / SEEK_COUNT);
    printf("uldict seek operation: %f ms, %f us per req\n", 
        (ue.tv_sec - us.tv_sec) * 1000 + (ue.tv_usec - us.tv_usec) / 1000.0,
        ((ue.tv_sec - us.tv_sec) * 1000000.0 + (ue.tv_usec - us.tv_usec)) / SEEK_COUNT);


    // save operation
    printf("Save odict dictionary to file ... \t");
    gettimeofday(&ss, NULL);
    odb_save(sdb, "./", "com.test.dict.odict");
    gettimeofday(&se, NULL);
    printf("OK\n");
    printf("Save uldict dictionary to file ... \t");
    gettimeofday(&us, NULL);
    db_save(udb, "./", "com.test.dict.uldict");
    gettimeofday(&ue, NULL);
    printf("OK\n");

    printf("odict save operation: %f ms, %f us per req\n", 
        (se.tv_sec - ss.tv_sec) * 1000 + (se.tv_usec - ss.tv_usec) / 1000.0,
        ((se.tv_sec - ss.tv_sec) * 1000000.0 + (se.tv_usec - ss.tv_usec)) / SEEK_COUNT);
    printf("uldict save operation: %f ms, %f us per req\n", 
        (ue.tv_sec - us.tv_sec) * 1000 + (ue.tv_usec - us.tv_usec) / 1000.0,
        ((ue.tv_sec - us.tv_sec) * 1000000.0 + (ue.tv_usec - us.tv_usec)) / SEEK_COUNT);
    odb_adjust(sdb);
    printf ("hash %d\n",odb_get_hashnum(sdb));
 
    /* return */
    return 0;
}
示例#11
0
int main(int argc, char *argv[])
{
	bool have_conf = false;
	bool have_log = false;
	char buf[32];
	int i, pid, r;
	FILE *pid_file;
	const char *pidfilename = RUNDIR "/atheme.pid";
#ifdef HAVE_GETRLIMIT
	struct rlimit rlim;
#endif
	curr_uplink = NULL;

	mowgli_init();

	/* Prepare gettext */
#ifdef ENABLE_NLS
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE_NAME, LOCALEDIR);
	textdomain(PACKAGE_NAME);
#endif

	/* change to our local directory */
	if (chdir(PREFIX) < 0)
	{
		perror(PREFIX);
		return 20;
	}

#ifdef HAVE_GETRLIMIT
	/* it appears certian systems *ahem*linux*ahem*
	 * don't dump cores by default, so we do this here.
	 */
	if (!getrlimit(RLIMIT_CORE, &rlim))
	{
		rlim.rlim_cur = rlim.rlim_max;
		setrlimit(RLIMIT_CORE, &rlim);
	}
#endif
	
	/* do command-line options */
	while ((r = getopt(argc, argv, "c:dhrl:np:v")) != -1)
	{
		switch (r)
		{
		  case 'c':
			  config_file = sstrdup(optarg);
			  have_conf = true;
			  break;
		  case 'd':
			  log_force = true;
			  break;
		  case 'h':
			  print_help();
			  exit(EXIT_SUCCESS);
			  break;
		  case 'r':
			  readonly = true;
			  break;
		  case 'l':
			  log_path = sstrdup(optarg);
			  have_log = true;
			  break;
		  case 'n':
			  runflags |= RF_LIVE;
			  break;
		  case 'p':
			  pidfilename = optarg;
			  break;
		  case 'v':
			  print_version();
			  exit(EXIT_SUCCESS);
			  break;
		  default:
			  printf("usage: atheme [-dhnvr] [-c conf] [-l logfile] [-p pidfile]\n");
			  exit(EXIT_SUCCESS);
			  break;
		}
	}

	if (!have_conf)
		config_file = sstrdup(SYSCONFDIR "/atheme.conf");

	if (!have_log)
		log_path = sstrdup(LOGDIR "/atheme.log");

	cold_start = true;

	runflags |= RF_STARTING;

	me.kline_id = 0;
	me.start = time(NULL);
	CURRTIME = me.start;
	srand(arc4random());
	me.execname = argv[0];

	/* set signal handlers */
	init_signal_handlers();

	/* initialize strshare */
	strshare_init();

	/* open log */
	log_open();
	mowgli_log_set_cb(process_mowgli_log);

	slog(LG_INFO, "%s is starting up...", PACKAGE_STRING);

	/* check for pid file */
	if ((pid_file = fopen(pidfilename, "r")))
	{
		if (fgets(buf, 32, pid_file))
		{
			pid = atoi(buf);

			if (!kill(pid, 0))
			{
				fprintf(stderr, "atheme: daemon is already running\n");
				exit(EXIT_FAILURE);
			}
		}

		fclose(pid_file);
	}

#if HAVE_UMASK
	/* file creation mask */
	umask(077);
#endif

        event_init();
        hooks_init();
        init_netio();
        init_socket_queues();
	db_init();

	translation_init();
#ifdef ENABLE_NLS
	language_init();
#endif
	init_nodes();
	init_confprocess();
	init_newconf();
	servtree_init();

	modules_init();
	pcommand_init();

	conf_init();
	if (!conf_parse(config_file))
	{
		slog(LG_ERROR, "Error loading config file %s, aborting",
				config_file);
		exit(EXIT_FAILURE);
	}

	if (config_options.languagefile)
	{
		slog(LG_DEBUG, "Using language: %s", config_options.languagefile);
		if (!conf_parse(config_options.languagefile))
			slog(LG_INFO, "Error loading language file %s, continuing",
					config_options.languagefile);
	}

	authcookie_init();
	common_ctcp_init();

	if (!backend_loaded && authservice_loaded)
	{
		slog(LG_ERROR, "atheme: no backend modules loaded, see your configuration file.");
		exit(EXIT_FAILURE);
	}

	/* we've done the critical startup steps now */
	cold_start = false;

	/* load our db */
	if (db_load)
		db_load();
	else if (backend_loaded)
	{
		slog(LG_ERROR, "atheme: backend module does not provide db_load()!");
		exit(EXIT_FAILURE);
	}
	db_check();

#ifdef HAVE_FORK
	/* fork into the background */
	if (!(runflags & RF_LIVE))
	{
		close(0);
		if (open("/dev/null", O_RDWR) != 0)
		{
			slog(LG_ERROR, "unable to open /dev/null??");
			exit(EXIT_FAILURE);
		}
		if ((i = fork()) < 0)
		{
			slog(LG_ERROR, "can't fork into the background");
			exit(EXIT_FAILURE);
		}

		/* parent */
		else if (i != 0)
		{
			slog(LG_INFO, "pid %d", i);
			slog(LG_INFO, "running in background mode from %s", PREFIX);
			exit(EXIT_SUCCESS);
		}

		/* parent is gone, just us now */
		if (setsid() < 0)
		{
			slog(LG_ERROR, "unable to create new session: %s", strerror(errno));
			exit(EXIT_FAILURE);
		}
		dup2(0, 1);
		dup2(0, 2);
	}
	else
	{
		slog(LG_INFO, "pid %d", getpid());
		slog(LG_INFO, "running in foreground mode from %s", PREFIX);
	}
#else
	slog(LG_INFO, "running in foreground mode from %s", PREFIX);
#endif

#ifdef HAVE_GETPID
	/* write pid */
	if ((pid_file = fopen(pidfilename, "w")))
	{
		fprintf(pid_file, "%d\n", getpid());
		fclose(pid_file);
	}
	else
	{
		fprintf(stderr, "atheme: unable to write pid file\n");
		exit(EXIT_FAILURE);
	}
#endif
	/* no longer starting */
	runflags &= ~RF_STARTING;

	/* we probably have a few open already... */
	me.maxfd = 3;

	/* DB commit interval is configurable */
	if (db_save && !readonly)
		event_add("db_save", db_save, NULL, config_options.commit_interval);

	/* check expires every hour */
	event_add("expire_check", expire_check, NULL, 3600);

	/* check k/x/q line expires every minute */
	event_add("kline_expire", kline_expire, NULL, 60);
	event_add("xline_expire", xline_expire, NULL, 60);
	event_add("qline_expire", qline_expire, NULL, 60);

	/* check authcookie expires every ten minutes */
	event_add("authcookie_expire", authcookie_expire, NULL, 600);

	/* reseed rng a little every five minutes */
	event_add("rng_reseed", rng_reseed, NULL, 293);

	me.connected = false;
	uplink_connect();

	/* main loop */
	io_loop();

	/* we're shutting down */
	hook_call_shutdown();

	if (db_save && !readonly)
		db_save(NULL);

	remove(pidfilename);
	errno = 0;
	if (curr_uplink != NULL && curr_uplink->conn != NULL)
		sendq_flush(curr_uplink->conn);
	connection_close_all();

	me.connected = false;

	/* should we restart? */
	if (runflags & RF_RESTART)
	{
		slog(LG_INFO, "main(): restarting");

#ifdef HAVE_EXECVE
		execv(BINDIR "/atheme-services", argv);
#endif
	}

	slog(LG_INFO, "main(): shutting down");

	log_shutdown();

	return 0;
}
示例#12
0
void db_exec(char cmd[])
{
	uint32_t tmp;
	uint32_t i, pos;
	uint32_t len = strlen(cmd);
	bool is_valid = false;
	char name[CMD_BUF_LEN];
	uint8_t data[CMD_BUF_LEN];

	switch(cmd[0]) {
		case 'h': 
			for(i = 2; i < NAME_MAX_LEN; i++) {
				if('=' == cmd[i]) {
					is_valid = true;
					cmd[i] = 0;
					break;
				}
			}
			if(is_valid) {
				for(i = 0; 0 != cmd[i + 1]; i++) {
					name[i] = cmd[i + 1];
				}
				sscanf(cmd + 2 + i, "%32x", &tmp);
				db_save(name, (uint8_t*)(&tmp), sizeof(uint32_t));
				tmp = 0;
				db_read(name, (uint8_t*)(&tmp));
				printf("\nname:%s\nhex:0x%x saved.\n", name, tmp);
			} else {
				printf("\nInvalid hex\n");
			}
			break;
		case 'w':
			for(i = 1; i < NAME_MAX_LEN; i++) {
				if('=' == cmd[i]) {
					is_valid = true;
					cmd[i] = 0;
					break;
				}
			}
			if(is_valid) {
				for(i = 1; cmd[i] != 0; i++) {
					name[i - 1] = cmd[i];
				}
				name[i - 1] = 0;

				pos = i + 1;
				for(i = 0; '\n' != cmd[pos + i]; i++) {
					data[i] = cmd[pos + i];
				}
				data[i] = 0;

				printf("\nname:%s,data:%s\n", (char*)name, (char*)data);

				db_save((char*)name, data, i);
			} else {
				printf("\nWrong code to write\n");
			}
			break;
		case 'r':
			for(i = 1; i < NAME_MAX_LEN; i++) {
				name[i - 1] = cmd[i];
				if('\n' == cmd[i]) {
					name[i - 1] = 0;
					break;
				}
			}
			db_read((char*)name, data);
			printf("\n%s=%s\n", name, data);
			break;
		case 'd':
			for(i = 1; i < NAME_MAX_LEN; i++) {
				name[i - 1] = cmd[i];
				if('\n' == cmd[i]) {
					name[i - 1] = 0;
					break;
				}
			}
			db_delete((char*)name);
			printf("\n%s deleted\n", name);
			break;
		case 's':
			db_sync();
			printf("\nsync done\n");
			break;
		default:
			#ifdef DEBUG_DB_EXEC
			printf("\nUnrecognised code\n");
			#endif
			break;
	}
	
}
示例#13
0
文件: advexe.c 项目: dbremner/advsys
/* exe_one - execute one instruction */
void exe_one(void)
{
    /* get the opcode */
    opcode = getcbyte(pc); pc++;

    /* execute the instruction */
    switch (opcode) {
    case OP_CALL:
		*--sp = getboperand();
		*--sp = pc;
		*--sp = (int)(top - fp);
		fp = sp;
		pc = getafield(fp[fp[2]+3],A_CODE);
		break;
    case OP_SEND:
		*--sp = getboperand();
		*--sp = pc;
		*--sp = (int)(top - fp);
		fp = sp;
		if (p2 = fp[fp[2]+3])
		    p2 = getofield(p2,O_CLASS);
		else
		    p2 = fp[fp[2]+2];
		if (p2 && (p2 = getp(p2,fp[fp[2]+1]))) {
		    pc = getafield(p2,A_CODE);
		    break;
		}
		*sp = NIL;
		/* return NIL if there is no method for this message */
    case OP_RETURN:
		if (fp == top)
		    sts = CHAIN;
		else {
		    p2 = *sp;
		    sp = fp;
		    fp = top - *sp++;
		    pc = *sp++;
		    p3 = *sp++;
		    sp += p3;
		    *sp = p2;
		}
		break;
    case OP_TSPACE:
		sp -= getboperand();
		break;
    case OP_TMP:
		p2 = getboperand();
		*sp = fp[-p2-1];
		break;
    case OP_TSET:
		p2 = getboperand();
		fp[-p2-1] = *sp;
		break;
    case OP_ARG:
		p2 = getboperand();
		if (p2 >= fp[2])
		    error("too few arguments");
		*sp = fp[p2+3];
		break;
    case OP_ASET:
		p2 = getboperand();
		if (p2 >= fp[2])
		    error("too few arguments");
		fp[p2+3] = *sp;
		break;
    case OP_BRT:
		pc = (*sp ? getwoperand() : pc+2);
		break;
    case OP_BRF:
		pc = (*sp ? pc+2 : getwoperand());
		break;
    case OP_BR:
		pc = getwoperand();
		break;
    case OP_T:
		*sp = T;
		break;
    case OP_NIL:
		*sp = NIL;
		break;
    case OP_PUSH:
		*--sp = NIL;
		break;
    case OP_NOT:
		*sp = (*sp ? NIL : T);
		break;
    case OP_ADD:
		p2 = *sp++;
		*sp += p2;
		break;
    case OP_SUB:
		p2 = *sp++;
		*sp -= p2;
		break;
    case OP_MUL:
		p2 = *sp++;
		*sp *= p2;
		break;
    case OP_DIV:
		p2 = *sp++;
		*sp = (p2 == 0 ? 0 : *sp / p2);
		break;
    case OP_REM:
		p2 = *sp++;
		*sp = (p2 == 0 ? 0 : *sp % p2);
		break;
    case OP_BAND:
		p2 = *sp++;
		*sp &= p2;
		break;
    case OP_BOR:
		p2 = *sp++;
		*sp |= p2;
		break;
    case OP_BNOT:
		*sp = ~*sp;
		break;
    case OP_LT:
		p2 = *sp++;
		*sp = (*sp < p2 ? T : NIL);
		break;
    case OP_EQ:
		p2 = *sp++;
		*sp = (*sp == p2 ? T : NIL);
		break;
    case OP_GT:
		p2 = *sp++;
		*sp = (*sp > p2 ? T : NIL);
		break;
    case OP_LIT:
		*sp = getwoperand();
		break;
    case OP_SPLIT:
		*sp = getboperand();
		break;
    case OP_SNLIT:
		*sp = -getboperand();
		break;
    case OP_VAR:
		*sp = getvalue(getwoperand());
		break;
    case OP_SVAR:
		*sp = getvalue(getboperand());
		break;
    case OP_SET:
		setvalue(getwoperand(),*sp);
		break;
    case OP_SSET:
		setvalue(getboperand(),*sp);
		break;
    case OP_GETP:
		p2 = *sp++;
		*sp = getp(*sp,p2);
		break;
    case OP_SETP:
		p3 = *sp++;
		p2 = *sp++;
		*sp = setp(*sp,p2,p3);
		break;
    case OP_PRINT:
		print(*sp);
		break;
    case OP_PNUMBER:
    		pnumber(*sp);
    		break;
    case OP_PNOUN:
		show_noun(*sp);
		break;
    case OP_TERPRI:
		trm_chr('\n');
		break;
    case OP_FINISH:
		sts = FINISH;
		break;
    case OP_CHAIN:
		sts = CHAIN;
		break;
    case OP_ABORT:
		sts = ABORT;
		break;
    case OP_EXIT:
#ifdef MAC
		macpause();
#endif
		trm_done();
		exit();
		break;
    case OP_YORN:
		trm_get(line);
		*sp = (line[0] == 'Y' || line[0] == 'y' ? T : NIL);
    		break;
    case OP_CLASS:
		*sp = getofield(*sp,O_CLASS);
		break;
    case OP_MATCH:
		p2 = *sp++;
		*sp = (match(*sp,nouns[p2-1],adjectives[p2-1]) ? T : NIL);
		break;
    case OP_SAVE:
		*sp = db_save();
		break;
    case OP_RESTORE:
		*sp = db_restore();
		break;
    case OP_RESTART:
		*sp = db_restart();
		break;
    case OP_RAND:
		*sp = getrand(*sp);
		break;
    case OP_RNDMIZE:
		setrand(time(0L));
		*sp = NIL;
		break;
    default:
	    if (opcode >= OP_XVAR && opcode < OP_XSET)
		*sp = getvalue(opcode - OP_XVAR);
	    else if (opcode >= OP_XSET && opcode < OP_XPLIT)
		setvalue(opcode - OP_XSET,*sp);
	    else if (opcode >= OP_XPLIT && opcode < OP_XNLIT)
		*sp = opcode - OP_XPLIT;
	    else if (opcode >= OP_XNLIT && opcode < 256)
		*sp = OP_XNLIT - opcode;
	    else
		trm_str("Bad opcode\n");
	    break;
    }
}
示例#14
0
文件: atheme.c 项目: XthemeOrg/Xtheme
static void db_save_periodic(void *unused)
{
	slog(LG_DEBUG, "db_save_periodic(): initiating periodic database write");
	db_save(unused, DB_SAVE_BG_REGULAR);
}
示例#15
0
文件: app.c 项目: vovach777/shipDB
void process_commands(enum CID cid) {
    cursor_t old_c;
    char * dbName;
    switch (cid) {
        case NOPE:
              puts("-- команда не распознана --");
              break;
        case SET_NAME:              
              if (db_ship()) {
                printf("Имя>");
                strncpy(db_ship()->name,input_str(),64);
                show();
          }
            break;
        case SET_YEAR:
              if (db_ship()) {
                printf("Год>");
                db_ship()->year = strtoul( input_str(),NULL, 10);
                show();
          }
            break;
        case COPY:
             db_copy();
             break;
        case PASTE:
             db_paste();
             show();
             break;
        case ALL:
             old_c = db_get_cursor();
             db_first();             
             while (db_get_cursor() != db_get_end()) {
                 db_load();
                 if (!db_is_deleted())
                    show();
                 db_next();
             }
             db_set_cursor(old_c);
             db_load();
             break;
        case REFRESH:
             db_load();
        case SHOW:
            show();
            break;

        case NEW:
             db_new();
             show();            
             break;
        case REMOVE:
                db_delete();        
                break;
        case SAVE:
              db_save();
             break; 

        case HELP:
              show_help();
              break;
        case OPEN:        
                printf("Файл>");
                dbName = input_str();
                db_open( strlen(dbName) == 0 ?  "ships.db" : dbName);
                break;
        case CLOSE:
                db_close();
                break;
        case  FIRST:
                first:
                db_first();
                while (db_get_cursor() != db_get_end()) {                   
                   db_load();
                   if (!db_is_deleted()) {
                       show();
                       return;
                   }                   
                   db_next();
                }
                puts("-- в базе нет записей. --");                
                break;
        case  NEXT: 
                db_next();
                while (db_get_cursor() != db_get_end()) {
                    db_load();
                    if (!db_is_deleted()) {
                       show();
                       return;
                   }
                   db_next();
                }
                puts("-- больше записей нет. перемотка в начало. --");
                goto first;                 
        case PREV:              
                while (db_get_cursor() != db_get_begin()) {
                   db_prev();
                   db_load();
                   if (!db_is_deleted()) {
                       show();
                       return;
                   }
                }
                puts("-- первая запись --");                
                goto first;             
                break;
        default:
            puts("== команда не обработана ==");

    }    
}
示例#16
0
int atheme_main(int argc, char *argv[])
{
	int daemonize_pipe[2];
	bool have_conf = false;
	bool have_log = false;
	bool have_datadir = false;
	char buf[32];
	int pid, r;
	FILE *pid_file;
	const char *pidfilename = RUNDIR "/atheme.pid";
	char *log_p = NULL;
	mowgli_getopt_option_t long_opts[] = {
		{ NULL, 0, NULL, 0, 0 },
	};

	atheme_bootstrap();

	/* do command-line options */
	while ((r = mowgli_getopt_long(argc, argv, "c:dhrl:np:D:v", long_opts, NULL)) != -1)
	{
		switch (r)
		{
		  case 'c':
			  config_file = sstrdup(mowgli_optarg);
			  have_conf = true;
			  break;
		  case 'd':
			  log_force = true;
			  break;
		  case 'h':
			  print_help();
			  exit(EXIT_SUCCESS);
			  break;
		  case 'r':
			  readonly = true;
			  break;
		  case 'l':
			  log_p = sstrdup(mowgli_optarg);
			  have_log = true;
			  break;
		  case 'n':
			  runflags |= RF_LIVE;
			  break;
		  case 'p':
			  pidfilename = mowgli_optarg;
			  break;
		  case 'D':
			  datadir = mowgli_optarg;
			  have_datadir = true;
			  break;
		  case 'v':
			  print_version();
			  exit(EXIT_SUCCESS);
			  break;
		  default:
			  printf("usage: atheme [-dhnvr] [-c conf] [-l logfile] [-p pidfile]\n");
			  exit(EXIT_FAILURE);
			  break;
		}
	}

	if (!have_conf)
		config_file = sstrdup(SYSCONFDIR "/atheme.conf");

	if (!have_log)
		log_p = sstrdup(LOGDIR "/atheme.log");

	if (!have_datadir)
		datadir = sstrdup(DATADIR);

	cold_start = true;

	runflags |= RF_STARTING;

	atheme_init(argv[0], log_p);

	slog(LG_INFO, "%s is starting up...", PACKAGE_STRING);

	/* check for pid file */
#ifndef MOWGLI_OS_WIN
	if ((pid_file = fopen(pidfilename, "r")))
	{
		if (fgets(buf, 32, pid_file))
		{
			pid = atoi(buf);

			if (!kill(pid, 0))
			{
				fprintf(stderr, "atheme: daemon is already running\n");
				exit(EXIT_FAILURE);
			}
		}

		fclose(pid_file);
	}
#endif

	if (!(runflags & RF_LIVE))
		daemonize(daemonize_pipe);

	atheme_setup();

	conf_init();
	if (!conf_parse(config_file))
	{
		slog(LG_ERROR, "Error loading config file %s, aborting",
				config_file);
		exit(EXIT_FAILURE);
	}

	if (config_options.languagefile)
	{
		slog(LG_DEBUG, "Using language: %s", config_options.languagefile);
		if (!conf_parse(config_options.languagefile))
			slog(LG_INFO, "Error loading language file %s, continuing",
					config_options.languagefile);
	}

	if (!backend_loaded && authservice_loaded)
	{
		slog(LG_ERROR, "atheme: no backend modules loaded, see your configuration file.");
		exit(EXIT_FAILURE);
	}

	/* we've done the critical startup steps now */
	cold_start = false;

	/* load our db */
	if (db_load)
		db_load(NULL);
	else if (backend_loaded)
	{
		slog(LG_ERROR, "atheme: backend module does not provide db_load()!");
		exit(EXIT_FAILURE);
	}
	db_check();

#ifdef HAVE_GETPID
	/* write pid */
	if ((pid_file = fopen(pidfilename, "w")))
	{
		fprintf(pid_file, "%d\n", getpid());
		fclose(pid_file);
	}
	else
	{
		fprintf(stderr, "atheme: unable to write pid file\n");
		exit(EXIT_FAILURE);
	}
#endif

	/* detach from terminal */
	if ((runflags & RF_LIVE) || !detach_console(daemonize_pipe))
	{
#ifdef HAVE_GETPID
		slog(LG_INFO, "pid %d", getpid());
#endif
		slog(LG_INFO, "running in foreground mode from %s", PREFIX);
	}

	/* no longer starting */
	runflags &= ~RF_STARTING;

	/* we probably have a few open already... */
	me.maxfd = 3;

	/* DB commit interval is configurable */
	if (db_save && !readonly)
		mowgli_timer_add(base_eventloop, "db_save", db_save, NULL, config_options.commit_interval);

	/* check expires every hour */
	mowgli_timer_add(base_eventloop, "expire_check", expire_check, NULL, 3600);

	/* check k/x/q line expires every minute */
	mowgli_timer_add(base_eventloop, "kline_expire", kline_expire, NULL, 60);
	mowgli_timer_add(base_eventloop, "xline_expire", xline_expire, NULL, 60);
	mowgli_timer_add(base_eventloop, "qline_expire", qline_expire, NULL, 60);

	/* check authcookie expires every ten minutes */
	mowgli_timer_add(base_eventloop, "authcookie_expire", authcookie_expire, NULL, 600);

	/* reseed rng a little every five minutes */
	mowgli_timer_add(base_eventloop, "rng_reseed", rng_reseed, NULL, 293);

	me.connected = false;
	uplink_connect();

	/* main loop */
	io_loop();

	/* we're shutting down */
	hook_call_shutdown();

	if (db_save && !readonly)
		db_save(NULL);

	remove(pidfilename);
	errno = 0;
	if (curr_uplink != NULL && curr_uplink->conn != NULL)
		sendq_flush(curr_uplink->conn);
	connection_close_all();

	me.connected = false;

	/* should we restart? */
	if (runflags & RF_RESTART)
	{
		slog(LG_INFO, "main(): restarting");

#ifdef HAVE_EXECVE
		execv(BINDIR "/atheme-services", argv);
#endif
	}

	slog(LG_INFO, "main(): shutting down");

	mowgli_eventloop_destroy(base_eventloop);
	log_shutdown();

	return 0;
}
示例#17
0
int analyze_line(char *line[]) {
  char sec[LINE_COLUMNS];
  struct tm *tm;
  struct sockaddr_in sa;
  char *l[LINE_COLUMNS];
  char date[9];
  char host[30];
  //char cn_host[CN_LENGTH];
  long i_tmp = 0;
  char *c_tmp;
  struct in_addr addr;

  memset(sec, 0, sizeof(sec));
  memset(date, 0, sizeof(date));
  sscanf(line[0], "%[^-]", sec);
  i_tmp = atol(sec);
  tm = localtime(&i_tmp);
  if(tm == NULL) {
    fprintf(stderr, "  Error to parse time %s\n", sec);
    return EXIT_FAILURE;
  }

  if(strftime(date, sizeof(date), "%Y%m%d", tm) == 0) {
    fprintf(stderr, "  Error to change time to human readable strings\n");
    return EXIT_FAILURE;
  }
  l[0] = date;
  
  if(ip4insubnet(line[2], LOCAL_NET, LOCAL_NETBITS) == 1) {
    c_tmp = line[2];
    l[2] = line[3];
    if(line[6] != NULL && strcasecmp(line[4], "TCP") == 0) {
      l[5] = line[6];
    }
  }
  else{
    c_tmp = line[3];
    l[2] = line[2];
    if(line[5] != NULL && strcasecmp(line[4], "TCP") == 0) {
      l[5] = line[5];
    }
  } 
  
  memset(host, 0, sizeof(host));
  bzero(&sa, sizeof(struct sockaddr_in));
  sa.sin_family = AF_INET;
  sa.sin_addr.s_addr = inet_addr(c_tmp);
  getnameinfo((struct sockaddr *)&sa, sizeof(sa), host, sizeof(host), NULL, 0, NI_NOFQDN);
  if(strlen(host) <= 0) l[1] = c_tmp;
  else l[1] = host;

  l[3] = line[4];
  l[4] = line[1];

  l[7] = "\0";
  if(strcasecmp(line[4], "TCP") == 0) {
    if(strcasecmp(line[7], "FA") == 0) l[6] = "1";
    else l[6] = "0";

    for(i_tmp = 8; i_tmp < LINE_COLUMNS; i_tmp++) {
      if(strcmp(line[i_tmp], "\n") == 0) {
        l[i_tmp] = NULL;
        break;  
      }
      l[i_tmp] = line[i_tmp]; 
    }

    /*
    if(i_tmp == 8 && (atoi(l[5]) == 443 || atoi(l[5]) == 8443)) {
      cn_host[0] = '\0';
      pthread_mutex_lock(&mutex);
      get_crt_cn(l[2], l[5], cn_host); 
      pthread_mutex_unlock(&mutex);
      l[7] = cn_host;
    }
    */

  } else {
    l[5] = NULL;
    l[6] = NULL;
  }

  db_save(l);
}