Beispiel #1
0
/* IN: orders: sequence of orders
   OUT: points received on test */
int test(t_order orders[], unsigned orders_len, t_execution execs[], unsigned execs_len) {
  int ok = 1;
  set_globals();
  init();
  ok = ok && feed_orders(orders, orders_len);
  ok = ok && assert_exec_count(execs_len);
  ok = ok && assert_execs(execs, execs_len);
  destroy();
  if (!ok) printf("test %i failed.\n\n", totaltests);
  return ok;
}
Beispiel #2
0
/* IN: orders: sequence of orders
   OUT: points received on test */
int test_cancel(t_order orders1[], unsigned orders1_len, t_orderid cancels[], unsigned cancels_len, t_order orders2[], unsigned orders2_len, t_execution execs[], unsigned execs_len) {
  int ok = 1;
  set_globals();
  init();
  ok = ok && feed_orders(orders1, orders1_len);
  feed_cancels(cancels, cancels_len);
  ok = ok && feed_orders(orders2, orders2_len);
  ok = ok && assert_exec_count(execs_len);
  ok = ok && assert_execs(execs, execs_len);
  destroy();
  if (!ok) printf("test %i failed.\n\n", totaltests);
  return ok;
}
Beispiel #3
0
/* kill a bts process running in background mode */
int kill_background(void)
{
	FILE *fp;				/* FILE handle to open the pid file */
	int fd;					/* file descriptor */
	char *lockfile;			     	/* full path of the PID file */
	pid_t pid = 0;				/* pid from the pid file */
	int ret;

	/* duhet te egzistoj ne rast se thirret bts kur processi eshte i aktivizuem */
	set_globals();

	/* get the full path of the lockfile lockfile. */
	lockfile = g_strjoin(NULL,directory.log_dir,BTS_PATH_SEPARATOR,LOCK_FILE,NULL);

	/* open the lock file */
	if ((fp = fopen(lockfile, "r")) == 0) {
		/* lock file does not exist */
		fprintf(stderr, "Unable to open pid file %s errorno  %d - %s\n",lockfile, errno, strerror(errno));
		return 1;
	}

	/* pull the pid from the file */
	if (fscanf(fp, "%d", (int *)(intptr_t)&pid)!=1) { 
	   fprintf(stderr,"Unable to get the pid!\n");
	}

	/* if we have a valid pid */
	if (pid > 0) {
		/* find file descriptor, unlock and remove file*/
		fd = fileno(fp);
		ret = lockf(fd,F_ULOCK ,0);
		if ( ret == -1){
			fprintf(stderr, "Unable to lock file %s errorno  %d - %s\n",lockfile, errno, strerror(errno));
		}
		if( remove(lockfile ) == -1 ){
        	  	fprintf(stderr, "Error deleting lock file%s\n",lockfile );
		}
		/*  send the signal to kill process */
		kill(pid, SIGTERM);

	}
	else {
		fprintf(stderr,"No valid pid found\n");
	}
	/* close the file handle to the lock file */
	fclose(fp);
	return 0;
}
Beispiel #4
0
void sig_handler(int sig) {
	/* basically:
	 * HUP: re-read config file
	 * INT: die
	 * TERM: die
	 * everything else: ignore */
	if (sig == SIGHUP) {
		read_config();
		set_globals();
	}

	if (sig == SIGINT || sig == SIGTERM) {
		exit(0);
	}

	return;
}
Beispiel #5
0
	void set_options(const wchar_t* url)
	{
		TraceFunc();
		auto urlCopy = cstr::dup(url);

		TraceFunc();
		URL_COMPONENTSW info;
		bool res = url::crack(urlCopy, &info);
		if (res && cstr::compare_ci(L"logger", info.lpszScheme, info.dwSchemeLength) == 0) {
			if (cstr::compare_ci(L"/default", info.lpszUrlPath, info.dwUrlPathLength) == 0) {
				set_defaults(info.lpszExtraInfo, info.dwExtraInfoLength);
			} else if (cstr::compare_ci(L"/global", info.lpszUrlPath, info.dwUrlPathLength) == 0) {
				set_globals(info.lpszExtraInfo, info.dwExtraInfoLength);
			} else if (cstr::compare_ci(L"/module", info.lpszUrlPath, info.dwUrlPathLength) == 0) {
				set_module(info.lpszExtraInfo, info.dwExtraInfoLength);
			}
		}

		HostFree(memory::heap::DefaultStat, urlCopy);
		TraceFunc();
	}
Beispiel #6
0
int main(int argc, char** argv)

{

	tall_bts_ctx = talloc_named_const(NULL, 1, "softBTS");

	handle_options(argc, argv);
	set_globals();
	bts_core_set_rlimits();
	daemonize();
	/* Initialize */
	srand(time(NULL));
	telnet_init(TELNET_PORT);
	
	
	socket_init(&oml.addr, &oml.socket, BSC_OML_PORT);
	socket_init(&rsl.addr, &rsl.socket, BSC_RSL_PORT);	
	trx_socket_init(TRX_PORT);

	while(1){
		socket_select_main(0);

	}
}
Beispiel #7
0
int main(int argc,char *argv[])
{
	char *filename = 0;
	int unasm = 0;
	int ptree = 0;
	int ptop = 0;
	int norun = 0;
	int trace = 0;
	int x;
	Ivy ivy[1];

	mk_ivy(ivy, error_print, NULL, stdin, stdout);
	set_globals(ivy, mk_globals(ivy));

	/* Parse options */
	for(x = 1; x != argc; ++x) {
		if (!strcmp(argv[x], "-u")) {
			/* Unassemble */
			unasm = 1;
		} else if (!strcmp(argv[x], "-t")) {
			/* Print tree */
			ptree = 1;
		} else if (!strcmp(argv[x], "-r")) {
			/* tRace while running */
			trace = 1;
		} else if (!strcmp(argv[x], "-c")) {
			/* Print result of each command */
			ptop = 1;
		} else if (!strcmp(argv[x], "-n")) {
			/* Compile only, don't run */
			norun = 1;
		} else if (!strcmp(argv[x], "-h")) {
			printf("ivy [options] [file]\n");
			printf("  -n   Compile, don't run\n");
			printf("  -u   Unassemble\n");
			printf("  -t   Print parse tree\n");
			printf("  -r   Trace\n");
			printf("  -c   Print result of each command\n");
			return 0;
		} else if (argv[x][0] == '-') {
			fprintf(stderr, "Unknown option %s\n", argv[x]);
			return -1;
		} else {
			if (filename) {
				fprintf(stderr, "Only one file may be given\n");
				return -1;
			} else {
				filename = argv[x];
			}
		}
	}

	if (filename) { /* Run a file */
		FILE *f = fopen(filename, "r");
		if (!f) {
			fprintf(stderr,"Couldn't open file \'%s\'\n", filename);
			return -1;
		} else {
			char buf[1024];
			Parser *parser = mkparser(ivy, filename);
			while (fgets(buf, sizeof(buf) - 1, f)) {
				parse(ivy, parser, buf, unasm, ptree, ptop, norun, trace);
			}
			parse_done(ivy, parser, unasm, ptree, ptop, norun, trace);
			rmparser(parser);
			fclose(f);
		}
	} else { /* Interactive */
		Parser *parser = mkparser(ivy, "Command Line");
		char *s;
		char prompt[100];
		printf("\nIvy\n\n");
		printf("type 'help' if you need it\n\n");
		for(;;) {
			if (parser->paren_level)
				sprintf(prompt, "%d>", parser->paren_level);
			else
				sprintf(prompt, ">");
			s = readline(prompt);
			if (!s)
				break;
			add_history(s);
			parse(ivy, parser, s, unasm, ptree, ptop, norun, trace);
			parse_done(ivy, parser, unasm, ptree, ptop, norun, trace);
			free(s);
		}
		rmparser(parser);
	}
	return 0;
}
Beispiel #8
0
void read_config(void) {
	// our config file search path:
	// CUR_USER/.spider/spider.conf
	// /root/.spider/spider.conf
	// /etc/spider/spider.conf
  char *home;
	char path_buf[PATH_MAX];
  char path_buf2[PATH_MAX];
	FILE *fp = NULL;
	char config_buf[4096];
	char s1[4096];
	char s2[4096];
	struct regstruct *cregp;
	struct regstruct *tregp;
	struct skiptypes *cskip;
	struct skiptypes *tskip;
	struct skippaths *cskipp;
	struct skippaths *tskipp;
	int first_regex = 1;
	int first_skip = 1;
	int first_skipp = 1;

	home = getenv("HOME");

	cregp = startregp;
	cskip = startskip;
	cskipp = startskippath;

	snprintf(path_buf, PATH_MAX, "%s/.spider/%s", home, CONFIG_NAME);
  	snprintf(path_buf2, PATH_MAX, "%s/etc/spider/spider.conf", PREFIX);

	bzero(LogFooter, sizeof(LogFooter));
	bzero(Password, sizeof(Password));

	if (CONFIG_PATH[0]) {
		if (verbose) {
			fprintf(stderr, "Trying: %s\n", CONFIG_PATH);
		}
		fp = fopen(CONFIG_PATH, "r");
		snprintf(ConfPath, PATH_MAX, "%s", CONFIG_PATH);
	} 

	if (fp == NULL) {
		if (verbose) {
			fprintf(stderr, "Trying: %s\n", "./spider.conf");
		}
		fp = fopen("./spider.conf", "r");
		snprintf(ConfPath, PATH_MAX, "%s", "./spider.conf");
	}

	if (fp == NULL) {
		if (verbose) {
	  		fprintf(stderr, "Trying: %s\n", path_buf);
		}
  		// Try the $HOME/.spider/spider.conf
		fp = fopen(path_buf, "r");
		snprintf(ConfPath, PATH_MAX, "%s", path_buf);
	}

	if (fp == NULL) {
		if (verbose) {
			  fprintf(stderr, "Trying: %s\n", path_buf2);
		}
		fp = fopen(path_buf2, "r");
        	snprintf(ConfPath, PATH_MAX, "%s", path_buf2);
	}

	if (fp == NULL) {
		fprintf(stderr, "No config file!\n");
		exit(1);
	} 
  
 	if (verbose) {
		fprintf(stderr, "Using config from: %s\n", ConfPath);
	}

	// if we fall through to here, we're reading something
	while (fgets(config_buf, 4096, fp) != NULL) {
		if (strncmp(config_buf, "#", 1) && 
				strncmp(config_buf, "\n", 1)){

//			if (sscanf(config_buf, "%s %[ 0-9a-zA-Z:,\\/{($^)}.%]", s1, s2)	== 2) {	
			if (sscanf(config_buf, "%s %[ !-~]", s1, s2)	== 2) {	
				if (!strcasecmp(s1, "recurse")) {
					Recurse = atoi(s2);
				}
				if (!strcasecmp(s1, "preserveatime")) {
					PreserveAtime = atoi(s2);
				}
				if (!strcasecmp(s1, "followsymlinks")) {
					FollowSymlinks = atoi(s2);
				}
				if (!strcasecmp(s1, "logstdout")) {
					LogStdout = atoi(s2);
				}
				if (!strcasecmp(s1, "scandepth")) {
					ScanDepth = atoi(s2);
				}
				if (!strcasecmp(s1, "usessn")) {
					UseSSN = atoi(s2);
				}
				if (!strcasecmp(s1, "usevmcd")) {
					UseVMCD = atoi(s2);
				}
				if (!strcasecmp(s1, "useamex")) {
					UseAMEX = atoi(s2);
				}
				if (!strcasecmp(s1, "casesenspath")) {
					CaseSensPath = atoi(s2);
				}
				if (!strcasecmp(s1, "encrypt")) {
					Encrypt = atoi(s2);
				}
				if (!strcasecmp(s1, "password")) {
					snprintf(Password, 128, "%s", s2);
				}
				if (!strcasecmp(s1, "logsyslog")) {
					LogSyslog = atoi(s2);
				}
				if (!strcasecmp(s1, "logfac")) {
					// figure things out
					set_fac(s2);
				}
				if (!strcasecmp(s1, "minimize")) {
					Minimize = atoi(s2);
				}
				if (!strcasecmp(s1, "whendone")) {
					WhenDone = atoi(s2);
				}
				if (!strcasecmp(s1, "maxgroups")) {
					snprintf(MaxgroupPath, PATH_MAX,
							"%s", s2);
				}
				if (!strcasecmp(s1, "log2file")) {
					Log2File = atoi(s2);
				}
				if (!strcasecmp(s1, "startdir")) {
					snprintf(START_PATH, PATH_MAX,
							"%s", s2);
				}
				if (!strcasecmp(s1, "appendlog")) {
					AppendLog = atoi(s2);
				}
				if (!strcasecmp(s1, "csvlog")) {
					CSVLog = atoi(s2);
				}
				if (!strcasecmp(s1, "logattributes")) {
					LogAttributes = atoi(s2);
				}
				if (!strcasecmp(s1, "logpath")) {
					snprintf(LogPath, PATH_MAX, "%s", s2);
				}
				if (!strcasecmp(s1, "logtotalmatches")) {
					LogTotalMatches = atoi(s2);
				}
				if (!strcasecmp(s1, "logfooter")) {
					snprintf(LogFooter, 128, "%s", s2);
				}
				if (!strcasecmp(s1, "regex")) {
					// add this to the end of the regex
					// linked list
					if (!cregp) {
						tregp = (struct regstruct *)
							malloc(sizeof(struct regstruct));
						if (tregp == NULL) {
							fprintf(stderr, "malloc! %s\n", strerror(errno));
							exit(1);
						}
						tregp -> next = NULL;
						cregp = tregp;
						if (first_regex) { 
							startregp = cregp;
							first_regex = 0;
						}
					} else {
						// chain another
						tregp = (struct regstruct *)
							malloc(sizeof(struct regstruct));
						if (tregp == NULL) {
							fprintf(stderr, "malloc!%s\n", strerror(errno));
							exit(1);
						}
						tregp -> next = NULL;
						cregp -> next = tregp;
						cregp = tregp;
					}
					if (!strstr(s2, "(C?)")) {
						strncat(s2, "(C?)", 4);
					}
					snprintf(cregp -> regtext, 256, "%s", s2);
			 	}
				if (!strcasecmp(s1, "skiptype")) {
					// add this to the linked list of 
					// skip types
					if (!cskip) {
						tskip = (struct skiptypes *)
							malloc(sizeof(struct skiptypes));
						if (tskip == NULL) {
							fprintf(stderr, "malloc!%s\n", strerror(errno));
							exit(1);
						}
						tskip -> next = NULL;
						cskip = tskip;
						if (first_skip) {
							startskip = cskip;
							first_skip = 0;
						}
					} else {
						tskip = (struct skiptypes *)
							malloc(sizeof(struct skiptypes));
						if (tskip == NULL) {
							fprintf(stderr,"malloc! %s\n", strerror(errno));
							exit(1);
						}
						tskip -> next = NULL;
						cskip -> next = tskip;
						cskip = tskip;

					}
					snprintf(cskip -> type, 128, "%s", s2);
				}
				if (!strcasecmp(s1, "skippath")) {
					if (!cskipp) {
						tskipp = (struct skippaths *)
							malloc(sizeof(struct skippaths));
						if (tskipp == NULL) {
							fprintf(stderr, "malloc!%s\n", strerror(errno));
							exit(1);
						}
						tskipp -> next = NULL;
						cskipp = tskipp;
						if (first_skipp) {
							startskippath = cskipp;
							first_skipp = 0;
						}
					} else {
						tskipp = (struct skippaths *)
							malloc(sizeof(struct skippaths));
						if (tskipp == NULL) {
							fprintf(stderr, "malloc!%s\n", strerror(errno));
							exit(1);
						}
						tskipp -> next = NULL;
						cskipp -> next = tskipp;
						cskipp = tskipp;
					}
					snprintf(cskipp -> skippath, PATH_MAX, "%s", s2);
				}
			}
		}
	} // end while

	fclose(fp);
	// sanity check
	//
	sanity_check();

	// now that we're done with that, set a couple of globals
	set_globals();

	return;

}