Exemplo n.º 1
0
//Read the string and execute instructions
void process_string(char instruction[], int size)
{
	//the character / means delete block... used for comments and stuff.
	if (instruction[0] != '/')	
	{
		fp.x = 0.0;
		fp.y = 0.0;
		fp.z = 0.0;
		fp.a = 0.0;
		fp.b = 0.0;
		fp.f = 0.0;
	
		//get all our parameters!
		parse_string(instruction, size);
	  
	  
		bool handleStandardCommands = (!sharedMachineModel.emergencyStop && sharedMachineModel.receiving);
    	if(handleStandardCommands || isPriorityCommand())
    	{
			execute_commands(instruction);
		}
		else
		{
			if(SendDebug & DEBUG_ERRORS)
                sprintf(talkToHost.string(), "Error: Machine is not armed (%s)", instruction);
            talkToHost.setResend(gc.LastLineNrRecieved+1);
        }
	}
}
Exemplo n.º 2
0
int cmd_receive_pack(int argc, const char **argv, const char *prefix)
{
	int i;
	char *dir = NULL;

	argv++;
	for (i = 1; i < argc; i++) {
		const char *arg = *argv++;

		if (*arg == '-') {
			/* Do flag handling here */
			usage(receive_pack_usage);
		}
		if (dir)
			usage(receive_pack_usage);
		dir = xstrdup(arg);
	}
	if (!dir)
		usage(receive_pack_usage);

	setup_path();

	if (!enter_repo(dir, 0))
		die("'%s': unable to chdir or not a git archive", dir);

	if (is_repository_shallow())
		die("attempt to push into a shallow repository");

	git_config(receive_pack_config, NULL);

	if (0 <= transfer_unpack_limit)
		unpack_limit = transfer_unpack_limit;
	else if (0 <= receive_unpack_limit)
		unpack_limit = receive_unpack_limit;

	add_alternate_refs();
	write_head_info();
	clear_extra_refs();

	/* EOF */
	packet_flush(1);

	read_head_info();
	if (commands) {
		const char *unpack_status = NULL;

		if (!delete_only(commands))
			unpack_status = unpack();
		execute_commands(unpack_status);
		if (pack_lockfile)
			unlink(pack_lockfile);
		if (report_status)
			report(unpack_status);
		run_receive_hook(post_receive_hook);
		run_update_post_hook(commands);
	}
	return 0;
}
Exemplo n.º 3
0
Arquivo: vcs.c Projeto: a1ip/ejudge
static int
cvs_add(const unsigned char *dir, const unsigned char *file,
        unsigned char **p_log_txt)
{
  path_t cmd1;
  const unsigned char *cmds[] = { cmd1, 0 };

  snprintf(cmd1, sizeof(cmd1), "cvs add \"%s\"", file);
  return execute_commands(dir, cmds, p_log_txt);
}
Exemplo n.º 4
0
Arquivo: vcs.c Projeto: a1ip/ejudge
static int
svn_add(const unsigned char *dir, const unsigned char *file,
        unsigned char **p_log_txt)
{
  path_t cmd1, cmd2, cmd3;
  const unsigned char *cmds[] = { cmd1, cmd2, cmd3, 0 };

  snprintf(cmd1, sizeof(cmd1), "svn add \"%s\"", file);
  snprintf(cmd2, sizeof(cmd2), "svn ps svn:eol-style native \"%s\"", file);
  snprintf(cmd3, sizeof(cmd3), "svn ps svn:keywords Id \"%s\"", file);
  return execute_commands(dir, cmds, p_log_txt);
}
Exemplo n.º 5
0
Arquivo: vcs.c Projeto: a1ip/ejudge
static int
svn_add_dir(const unsigned char *path, const unsigned char *dir,
            unsigned char **p_log_txt)
{
  path_t cmd1;
  path_t cmd2;
  const unsigned char *cmds[] = { cmd1, cmd2, 0 };

  snprintf(cmd1, sizeof(cmd1), "svn add -N \"%s\"", dir);
  snprintf(cmd2, sizeof(cmd2), "svn ci -m \"\" \"%s\"", dir);
  return execute_commands(path, cmds, p_log_txt);
}
Exemplo n.º 6
0
void *client_handler(void *socket_desc) {
	//Get the socket descriptor
	int sock = *(int*) socket_desc;
	int read_size, finish = 0;
	char client_message[MAX_BUFFER_SIZE];
	char message[LOGSZ];

	sprintf(message, "Started cli connection.\n");
	logger(LOG_INFO, message);

	cli_prompt(sock);

	//Receive a message from client
	while (!(finish) && ((read_size = recv(sock, client_message,
			MAX_BUFFER_SIZE, 0)) > 0)) {

		client_message[read_size - 1] = '\0';

		if (read_size) {

			finish = execute_commands(sock, client_message, read_size);
			//finish = cli_process_message(sock, client_message, read_size);
		}

		if (finish) {
			shutdown(sock, SHUT_RDWR);
		}

		if (read_size == 0) {
			puts("Client disconnected");
			fflush(stdout);
		} else if (read_size == -1) {
			perror("recv failed");
		}
	}
	//Free the socket pointer
	free(socket_desc);

	sprintf(message, "Closing cli connection.\n");
	logger(LOG_INFO, message);

	return NULL;
}
Exemplo n.º 7
0
void *client_handler(void *socket_desc) {
	//Get the socket descriptor
	int sock = *(int*) socket_desc;
	int read_size, finish = 0;
	char client_message[MAX_BUFFER_SIZE];
	char message[LOGSZ];

	sprintf(message, "Started cli connection.\n");
	logger(LOG_INFO, message);

        num_sock++;
        num_tot_sock++;
        sprintf(message, "Established. Number of established sockets: %d. Total: %d.\n", num_sock, num_tot_sock);
        logger(LOG_INFO, message);

	//cli_prompt(sock);

	//Receive a message from client
	while ((finish != CLI_SHUTDOWN) && ((read_size = recv(sock, client_message,
			MAX_BUFFER_SIZE, 0)) > 0)) {

		client_message[read_size] = '\0';

		if (read_size)
			finish = execute_commands(sock, client_message, read_size);

		switch (finish) {
			case    CLI_SHUTDOWN:
				shutdown(sock, SHUT_RDWR);
				break;
	                case    CLI_SUCCESS:
				break;
			case    CLI_ERR_CMD:
                                sprintf(message,"%s","Command arguments are incorrect or command not executed properly\n");
                                logger(LOG_INFO, message);
                                cli_send_feedback(sock, message);
                                break;
	                case    CLI_INV_CMD:
                                sprintf(message,"%s","Command Not Found\n");
                                logger(LOG_INFO, message);
                                cli_send_feedback(sock, message);
                                break;
			default:
                                break;
		}
		sprintf(message, "%s\n", END_OF_COMMAND);
		cli_send_feedback(sock, message);

		if (read_size == 0) {
			puts("Client disconnected");
			fflush(stdout);
		} else if (read_size == -1) {
			perror("recv failed");
		}
	}
        num_sock--;
        sprintf(message, "Disconnected.Number of established sockets: %d.\n", num_sock);
        logger(LOG_INFO, message);

	close(sock);
	//Free the socket pointer
	free(socket_desc);

	sprintf(message, "Closing cli connection.\n");
	logger(LOG_INFO, message);

        pthread_exit(NULL);
}
Exemplo n.º 8
0
static void	execute_operations(DB_ESCALATION *escalation, DB_EVENT *event, DB_ACTION *action)
{
	const char	*__function_name = "execute_operations";
	DB_RESULT	result;
	DB_ROW		row;
	DB_OPERATION	operation;
	int		esc_period = 0, operations = 0;
	ZBX_USER_MSG	*user_msg = NULL, *p;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

	if (0 == action->esc_period)
	{
		result = DBselect(
				"select o.operationid,o.operationtype,o.esc_period,o.evaltype,"
					"m.operationid,m.default_msg,subject,message,mediatypeid"
				" from operations o"
					" left join opmessage m"
						" on m.operationid=o.operationid"
				" where o.actionid=" ZBX_FS_UI64
					" and o.operationtype in (%d,%d)",
				action->actionid,
				OPERATION_TYPE_MESSAGE, OPERATION_TYPE_COMMAND);
	}
	else
	{
		escalation->esc_step++;

		result = DBselect(
				"select o.operationid,o.operationtype,o.esc_period,o.evaltype,"
					"m.operationid,m.default_msg,subject,message,mediatypeid"
				" from operations o"
					" left join opmessage m"
						" on m.operationid=o.operationid"
				" where o.actionid=" ZBX_FS_UI64
					" and o.operationtype in (%d,%d)"
					" and o.esc_step_from<=%d"
					" and (o.esc_step_to=0 or o.esc_step_to>=%d)",
				action->actionid,
				OPERATION_TYPE_MESSAGE, OPERATION_TYPE_COMMAND,
				escalation->esc_step,
				escalation->esc_step);
	}

	while (NULL != (row = DBfetch(result)))
	{
		memset(&operation, 0, sizeof(operation));

		ZBX_STR2UINT64(operation.operationid, row[0]);
		operation.actionid = action->actionid;
		operation.operationtype = atoi(row[1]);
		operation.esc_period = atoi(row[2]);
		operation.evaltype = (unsigned char)atoi(row[3]);

		if (SUCCEED == check_operation_conditions(event, operation.operationid, operation.evaltype))
		{
			unsigned char	default_msg;
			char		*subject, *message;
			zbx_uint64_t	mediatypeid;

			zabbix_log(LOG_LEVEL_DEBUG, "Conditions match our event. Execute operation.");

			if (0 == esc_period || esc_period > operation.esc_period)
				esc_period = operation.esc_period;

			switch (operation.operationtype)
			{
				case OPERATION_TYPE_MESSAGE:
					if (SUCCEED == DBis_null(row[4]))
						break;

					default_msg = (unsigned char)atoi(row[5]);
					ZBX_DBROW2UINT64(mediatypeid, row[8]);

					if (0 == default_msg)
					{
						subject = row[6];
						message = row[7];
					}
					else
					{
						subject = action->shortdata;
						message = action->longdata;
					}

					add_object_msg(operation.operationid, mediatypeid, &user_msg, subject, message,
							event->source, event->objectid);
					break;
				case OPERATION_TYPE_COMMAND:
					execute_commands(event, action->actionid, operation.operationid, escalation->esc_step);
					break;
			}
		}
		else
			zabbix_log(LOG_LEVEL_DEBUG, "Conditions do not match our event. Do not execute operation.");

		operations = 1;
	}
	DBfree_result(result);

	while (NULL != user_msg)
	{
		p = user_msg;
		user_msg = user_msg->next;

		add_message_alert(escalation, event, action, p->userid, p->mediatypeid, p->subject, p->message);

		zbx_free(p->subject);
		zbx_free(p->message);
		zbx_free(p);
	}

	if (0 == action->esc_period)
	{
		escalation->status = (action->recovery_msg == 1) ? ESCALATION_STATUS_SLEEP : ESCALATION_STATUS_COMPLETED;
	}
	else
	{
		if (0 == operations)
		{
			result = DBselect("select operationid from operations where actionid=" ZBX_FS_UI64 " and esc_step_from>%d",
					action->actionid,
					escalation->esc_step);

			if (NULL != (row = DBfetch(result)) && SUCCEED != DBis_null(row[0]))
				operations = 1;

			DBfree_result(result);
		}

		if (1 == operations)
		{
			esc_period = (0 != esc_period) ? esc_period : action->esc_period;
			escalation->nextcheck = time(NULL) + esc_period;
		}
		else
			escalation->status = (action->recovery_msg == 1) ? ESCALATION_STATUS_SLEEP : ESCALATION_STATUS_COMPLETED;
	}

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
}
Exemplo n.º 9
0
int cli_execute(int argc, char **argv, const options_entry *osd_options)
{
	core_options *options;
	astring *gamename = astring_alloc();
	astring *exename = astring_alloc();
	const char *gamename_option;
	const game_driver *driver;
	int result;

	/* initialize the options manager and add the CLI-specific options */
	options = mame_options_init(osd_options);
	options_add_entries(options, cli_options);

	/* parse the command line first; if we fail here, we're screwed */
	if (options_parse_command_line(options, argc, argv, OPTION_PRIORITY_CMDLINE))
	{
		result = MAMERR_INVALID_CONFIG;
		goto error;
	}

	/* parse the simple commmands before we go any further */
	core_filename_extract_base(exename, argv[0], TRUE);

	result = execute_simple_commands(options, astring_c(exename));
	if (result != -1) {
		goto error;
	}

	/* find out what game we might be referring to */
	gamename_option = options_get_string(options, OPTION_GAMENAME);

	core_filename_extract_base(gamename, gamename_option, TRUE);

	driver = driver_get_name(astring_c(gamename));

	/* execute any commands specified */
	result = execute_commands(options, astring_c(exename), driver);
	if (result != -1) {
		goto error;
	}

	/* if we don't have a valid driver selected, offer some suggestions */
	if (strlen(gamename_option) > 0 && driver == NULL)
	{
		const game_driver *matches[10];
		int drvnum;

		/* get the top 10 approximate matches */
		driver_list_get_approx_matches(drivers, gamename_option, ARRAY_LENGTH(matches), matches);

		/* print them out */
		fprintf(stderr, "\n\"%s\" approximately matches the following\n"
				"supported " GAMESNOUN " (best match first):\n\n", gamename_option);
		for (drvnum = 0; drvnum < ARRAY_LENGTH(matches); drvnum++)
			if (matches[drvnum] != NULL)
				fprintf(stderr, "%-10s%s\n", matches[drvnum]->name, matches[drvnum]->description);

		/* exit with an error */
		result = MAMERR_NO_SUCH_GAME;
		goto error;
	}
	/* run the game */
	result = mame_execute(options);

error:
	/* free our options and exit */
	options_free(options);
	astring_free(gamename);
	astring_free(exename);
	return result;
}
Exemplo n.º 10
0
int cmd_receive_pack(int argc, const char **argv, const char *prefix)
{
	int advertise_refs = 0;
	int stateless_rpc = 0;
	int i;
	char *dir = NULL;
	struct command *commands;

	packet_trace_identity("receive-pack");

	argv++;
	for (i = 1; i < argc; i++) {
		const char *arg = *argv++;

		if (*arg == '-') {
			if (!strcmp(arg, "--advertise-refs")) {
				advertise_refs = 1;
				continue;
			}
			if (!strcmp(arg, "--stateless-rpc")) {
				stateless_rpc = 1;
				continue;
			}

			usage(receive_pack_usage);
		}
		if (dir)
			usage(receive_pack_usage);
		dir = xstrdup(arg);
	}
	if (!dir)
		usage(receive_pack_usage);

	setup_path();

	if (!enter_repo(dir, 0))
		die("'%s' does not appear to be a git repository", dir);

	if (is_repository_shallow())
		die("attempt to push into a shallow repository");

	git_config(receive_pack_config, NULL);

	if (0 <= transfer_unpack_limit)
		unpack_limit = transfer_unpack_limit;
	else if (0 <= receive_unpack_limit)
		unpack_limit = receive_unpack_limit;

	if (advertise_refs || !stateless_rpc) {
		write_head_info();
	}
	if (advertise_refs)
		return 0;

	if ((commands = read_head_info()) != NULL) {
		const char *unpack_status = NULL;

		if (!delete_only(commands))
			unpack_status = unpack();
		execute_commands(commands, unpack_status);
		if (pack_lockfile)
			unlink_or_warn(pack_lockfile);
		if (report_status)
			report(commands, unpack_status);
		run_receive_hook(commands, post_receive_hook, 1);
		run_update_post_hook(commands);
		if (auto_gc) {
			const char *argv_gc_auto[] = {
				"gc", "--auto", "--quiet", NULL,
			};
			run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
		}
		if (auto_update_server_info)
			update_server_info(0);
	}
	if (use_sideband)
		packet_flush(1);
	return 0;
}
Exemplo n.º 11
0
int cmd_receive_pack(int argc, const char **argv, const char *prefix)
{
	int advertise_refs = 0;
	struct command *commands;
	struct sha1_array shallow = SHA1_ARRAY_INIT;
	struct sha1_array ref = SHA1_ARRAY_INIT;
	struct shallow_info si;

	struct option options[] = {
		OPT__QUIET(&quiet, N_("quiet")),
		OPT_HIDDEN_BOOL(0, "stateless-rpc", &stateless_rpc, NULL),
		OPT_HIDDEN_BOOL(0, "advertise-refs", &advertise_refs, NULL),
		OPT_HIDDEN_BOOL(0, "reject-thin-pack-for-testing", &reject_thin, NULL),
		OPT_END()
	};

	packet_trace_identity("receive-pack");

	argc = parse_options(argc, argv, prefix, options, receive_pack_usage, 0);

	if (argc > 1)
		usage_msg_opt(_("Too many arguments."), receive_pack_usage, options);
	if (argc == 0)
		usage_msg_opt(_("You must specify a directory."), receive_pack_usage, options);

	service_dir = argv[0];

	setup_path();

	if (!enter_repo(service_dir, 0))
		die("'%s' does not appear to be a git repository", service_dir);

	git_config(receive_pack_config, NULL);
	if (cert_nonce_seed)
		push_cert_nonce = prepare_push_cert_nonce(service_dir, time(NULL));

	if (0 <= transfer_unpack_limit)
		unpack_limit = transfer_unpack_limit;
	else if (0 <= receive_unpack_limit)
		unpack_limit = receive_unpack_limit;

	if (advertise_refs || !stateless_rpc) {
		write_head_info();
	}
	if (advertise_refs)
		return 0;

	if ((commands = read_head_info(&shallow)) != NULL) {
		const char *unpack_status = NULL;
		struct string_list push_options = STRING_LIST_INIT_DUP;

		if (use_push_options)
			read_push_options(&push_options);

		prepare_shallow_info(&si, &shallow);
		if (!si.nr_ours && !si.nr_theirs)
			shallow_update = 0;
		if (!delete_only(commands)) {
			unpack_status = unpack_with_sideband(&si);
			update_shallow_info(commands, &si, &ref);
		}
		use_keepalive = KEEPALIVE_ALWAYS;
		execute_commands(commands, unpack_status, &si,
				 &push_options);
		if (pack_lockfile)
			unlink_or_warn(pack_lockfile);
		if (report_status)
			report(commands, unpack_status);
		run_receive_hook(commands, "post-receive", 1,
				 &push_options);
		run_update_post_hook(commands);
		if (push_options.nr)
			string_list_clear(&push_options, 0);
		if (auto_gc) {
			const char *argv_gc_auto[] = {
				"gc", "--auto", "--quiet", NULL,
			};
			struct child_process proc = CHILD_PROCESS_INIT;

			proc.no_stdin = 1;
			proc.stdout_to_stderr = 1;
			proc.err = use_sideband ? -1 : 0;
			proc.git_cmd = 1;
			proc.argv = argv_gc_auto;

			close_all_packs();
			if (!start_command(&proc)) {
				if (use_sideband)
					copy_to_sideband(proc.err, -1, NULL);
				finish_command(&proc);
			}
		}
		if (auto_update_server_info)
			update_server_info(0);
		clear_shallow_info(&si);
	}
	if (use_sideband)
		packet_flush(1);
	sha1_array_clear(&shallow);
	sha1_array_clear(&ref);
	free((void *)push_cert_nonce);
	return 0;
}
Exemplo n.º 12
0
int
main(int argc, char **argv)
{
	const char *host = NULL;

	char *homedir;
	char hist_file[1024] = "";

	sdb_input_t input = SDB_INPUT_INIT;
	sdb_llist_t *commands = NULL;

	while (42) {
		int opt = getopt(argc, argv, "H:U:c:C:K:A:hV");

		if (-1 == opt)
			break;

		switch (opt) {
			case 'H':
				host = optarg;
				break;
			case 'U':
				input.user = optarg;
				break;

			case 'c':
				{
					sdb_object_t *obj;

					if (! commands)
						commands = sdb_llist_create();
					if (! commands) {
						sdb_log(SDB_LOG_ERR, "Failed to create list object");
						exit(1);
					}

					if (! (obj = sdb_object_create_T(optarg, sdb_object_t))) {
						sdb_log(SDB_LOG_ERR, "Failed to create object");
						exit(1);
					}
					if (sdb_llist_append(commands, obj)) {
						sdb_log(SDB_LOG_ERR, "Failed to append command to list");
						sdb_object_deref(obj);
						exit(1);
					}
					sdb_object_deref(obj);
				}
				break;

			case 'C':
				ssl_options.cert_file = optarg;
				break;
			case 'K':
				ssl_options.key_file = optarg;
				break;
			case 'A':
				ssl_options.ca_file = optarg;
				break;

			case 'h':
				exit_usage(argv[0], 0);
				break;
			case 'V':
				exit_version();
				break;
			default:
				exit_usage(argv[0], 1);
		}
	}

	if (optind < argc)
		exit_usage(argv[0], 1);

	if (! host)
		host = DEFAULT_SOCKET;
	if (! input.user)
		input.user = sdb_get_current_user();
	else
		input.user = strdup(input.user);
	if (! input.user)
		exit(1);

	if (sdb_ssl_init())
		exit(1);

	input.client = sdb_client_create(host);
	if (! input.client) {
		sdb_log(SDB_LOG_ERR, "Failed to create client object");
		sdb_input_reset(&input);
		exit(1);
	}
	canonicalize_ssl_options();
	if (sdb_client_set_ssl_options(input.client, &ssl_options)) {
		sdb_log(SDB_LOG_ERR, "Failed to apply SSL options");
		sdb_input_reset(&input);
		sdb_ssl_free_options(&ssl_options);
		exit(1);
	}
	sdb_ssl_free_options(&ssl_options);
	if (sdb_client_connect(input.client, input.user)) {
		sdb_log(SDB_LOG_ERR, "Failed to connect to SysDBd");
		sdb_input_reset(&input);
		exit(1);
	}

	if (commands) {
		int status = execute_commands(input.client, commands);
		sdb_llist_destroy(commands);
		sdb_input_reset(&input);
		if ((status != SDB_CONNECTION_OK) && (status != SDB_CONNECTION_DATA))
			exit(1);
		exit(0);
	}

	sdb_log(SDB_LOG_INFO, "SysDB client "SDB_CLIENT_VERSION_STRING
			SDB_CLIENT_VERSION_EXTRA" (libsysdbclient %s%s)",
			sdb_client_version_string(), sdb_client_version_extra());
	sdb_command_print_server_version(&input);
	printf("\n");

	using_history();

	if ((homedir = sdb_get_homedir())) {
		snprintf(hist_file, sizeof(hist_file) - 1,
				"%s/.sysdb_history", homedir);
		hist_file[sizeof(hist_file) - 1] = '\0';
		free(homedir);
		homedir = NULL;

		errno = 0;
		if (read_history(hist_file) && (errno != ENOENT)) {
			char errbuf[1024];
			sdb_log(SDB_LOG_WARNING, "Failed to load history (%s): %s",
					hist_file, sdb_strerror(errno, errbuf, sizeof(errbuf)));
		}
	}

	input.input = sdb_strbuf_create(2048);
	sdb_input_init(&input);
	sdb_input_mainloop();

	sdb_client_shutdown(input.client, SHUT_WR);
	while (! sdb_client_eof(input.client)) {
		/* wait for remaining data to arrive */
		sdb_command_print_reply(input.client);
	}

	if (hist_file[0] != '\0') {
		errno = 0;
		if (write_history(hist_file)) {
			char errbuf[1024];
			sdb_log(SDB_LOG_WARNING, "Failed to store history (%s): %s",
					hist_file, sdb_strerror(errno, errbuf, sizeof(errbuf)));
		}
	}

	sdb_input_reset(&input);
	sdb_ssl_shutdown();
	return 0;
} /* main */
Exemplo n.º 13
0
int cmd_receive_pack(int argc, const char **argv, const char *prefix)
{
	int advertise_refs = 0;
	int i;
	struct command *commands;
	struct sha1_array shallow = SHA1_ARRAY_INIT;
	struct sha1_array ref = SHA1_ARRAY_INIT;
	struct shallow_info si;

	packet_trace_identity("receive-pack");

	argv++;
	for (i = 1; i < argc; i++) {
		const char *arg = *argv++;

		if (*arg == '-') {
			if (!strcmp(arg, "--quiet")) {
				quiet = 1;
				continue;
			}

			if (!strcmp(arg, "--advertise-refs")) {
				advertise_refs = 1;
				continue;
			}
			if (!strcmp(arg, "--stateless-rpc")) {
				stateless_rpc = 1;
				continue;
			}
			if (!strcmp(arg, "--reject-thin-pack-for-testing")) {
				fix_thin = 0;
				continue;
			}

			usage(receive_pack_usage);
		}
		if (service_dir)
			usage(receive_pack_usage);
		service_dir = arg;
	}
	if (!service_dir)
		usage(receive_pack_usage);

	setup_path();

	if (!enter_repo(service_dir, 0))
		die("'%s' does not appear to be a git repository", service_dir);

	git_config(receive_pack_config, NULL);
	if (cert_nonce_seed)
		push_cert_nonce = prepare_push_cert_nonce(service_dir, time(NULL));

	if (0 <= transfer_unpack_limit)
		unpack_limit = transfer_unpack_limit;
	else if (0 <= receive_unpack_limit)
		unpack_limit = receive_unpack_limit;

	if (advertise_refs || !stateless_rpc) {
		write_head_info();
	}
	if (advertise_refs)
		return 0;

	if ((commands = read_head_info(&shallow)) != NULL) {
		const char *unpack_status = NULL;

		prepare_shallow_info(&si, &shallow);
		if (!si.nr_ours && !si.nr_theirs)
			shallow_update = 0;
		if (!delete_only(commands)) {
			unpack_status = unpack_with_sideband(&si);
			update_shallow_info(commands, &si, &ref);
		}
		execute_commands(commands, unpack_status, &si);
		if (pack_lockfile)
			unlink_or_warn(pack_lockfile);
		if (report_status)
			report(commands, unpack_status);
		run_receive_hook(commands, "post-receive", 1);
		run_update_post_hook(commands);
		if (auto_gc) {
			const char *argv_gc_auto[] = {
				"gc", "--auto", "--quiet", NULL,
			};
			int opt = RUN_GIT_CMD | RUN_COMMAND_STDOUT_TO_STDERR;
			run_command_v_opt(argv_gc_auto, opt);
		}
		if (auto_update_server_info)
			update_server_info(0);
		clear_shallow_info(&si);
	}
	if (use_sideband)
		packet_flush(1);
	sha1_array_clear(&shallow);
	sha1_array_clear(&ref);
	free((void *)push_cert_nonce);
	return 0;
}
Exemplo n.º 14
0
/**
 * Fonction principale
 * @param argc nombre d'arguments
 * @param argv tableau d'arguments
 * @return program exit code
 */
int
main(int argc, char *argv[])
{
    /* debug trace start */
    Edbg(("main(argc=%d, argv=%s)", argc, argv[0]));
    Initdbg((&argc, argv));

    int c;
    char display_opengl = FALSE;
    int ret;
	static struct sigaction act;

    /* on récupère les options */
    while ( (c = getopt(argc, argv, "hga:z:")) >= 0) 
    {
        switch (c) 
        {
            case 'h':
                /* print help */
                print_usage();
                Rdbg(("main return EXIT_SUCCESS"));
                return EXIT_SUCCESS;
            case 'g':
                /* display in OpenGL */
                display_opengl = TRUE;
                break;
            case 'z':
                /* display in OpenGL */
                g_zoomim = strtod(optarg, (char **)NULL);
                break;
            case 'a':
                /* nombre de keyframes dans l'animation OpenGL */
                g_anim_nb_keyframes = strtol(optarg, (char **)NULL, 10);;
                break;
        }
    }

    /* il faut le nom du fichier de commandes dans les arguments */
    if ((argc-optind) != 1)
    {
        print_usage();
        Rdbg(("main return EXIT_FAILURE"));
        return EXIT_FAILURE;
    }

	/* on catche le Ctrl-C */
	act.sa_handler = terminate_program_catch;
	sigfillset(&(act.sa_mask));
	sigaction(SIGINT, &act, NULL);

    /* on charge les commandes */
    ret = execute_commands(argv[optind]);
    if (ret != RETURN_SUCCESS)
    {
        destroy_cameras();
        return EXIT_FAILURE;
    }

    /* on vérifie qu'il y a bien au moins 2 caméras chargées */
    if (g_cameras.nb < 2)
    {
        fprintf(stderr, "Il faut charger au moins 2 caméras!\n");
        destroy_cameras();
        return EXIT_FAILURE;
    }

    /* affichage */
    if (TRUE == display_opengl)
    {
        /* on utilise atexit car glut ne dit pas quand il quitte le programme
         * (ce gros malin...) 
         * cf 3.070 http://users.frii.com/martz/oglfaq/glut.htm
         * update: depuis j'utilise SDL mais je garde quand même atexit... */
        atexit(terminate_program);

        init_display();
        start_display();
        destroy_display();
    }

    /* nettoyage */
    destroy_cameras();

    /* debug trace end */
    Rdbg(("main EXIT_SUCCESS"));
    return EXIT_SUCCESS;
}
Exemplo n.º 15
0
int cli_execute(int argc, char **argv, const options_entry *osd_options)
{
	core_options *options = NULL;
	const char *gamename_option;
	const game_driver *driver;
	int result = MAMERR_FATALERROR;
	astring gamename;
	astring exename;

	try
	{
		/* initialize the options manager and add the CLI-specific options */
		options = mame_options_init(osd_options);
		options_add_entries(options, cli_options);

		/* parse the command line first; if we fail here, we're screwed */
		if (options_parse_command_line(options, argc, argv, OPTION_PRIORITY_CMDLINE))
		{
			result = MAMERR_INVALID_CONFIG;
			goto error;
		}

		/* parse the simple commmands before we go any further */
		core_filename_extract_base(&exename, argv[0], TRUE);
		result = execute_simple_commands(options, exename);
		if (result != -1)
			goto error;

		/* find out what game we might be referring to */
		gamename_option = options_get_string(options, OPTION_GAMENAME);
		core_filename_extract_base(&gamename, gamename_option, TRUE);
		driver = driver_get_name(gamename);

		/* execute any commands specified */
		result = execute_commands(options, exename, driver);
		if (result != -1)
			goto error;

		/* if we don't have a valid driver selected, offer some suggestions */
		if (strlen(gamename_option) > 0 && driver == NULL)
		{
			const game_driver *matches[10];
			int drvnum;

			/* get the top 10 approximate matches */
			driver_list_get_approx_matches(drivers, gamename_option, ARRAY_LENGTH(matches), matches);

			/* print them out */
			fprintf(stderr, "\n\"%s\" approximately matches the following\n"
					"supported " GAMESNOUN " (best match first):\n\n", gamename_option);
			for (drvnum = 0; drvnum < ARRAY_LENGTH(matches); drvnum++)
				if (matches[drvnum] != NULL)
					fprintf(stderr, "%-18s%s\n", matches[drvnum]->name, matches[drvnum]->description);

			/* exit with an error */
			result = MAMERR_NO_SUCH_GAME;
			goto error;
		}

		/* run the game */
		result = mame_execute(options);
	}
	catch (emu_fatalerror &fatal)
	{
		fprintf(stderr, "%s\n", fatal.string());
		if (fatal.exitcode() != 0)
			result = fatal.exitcode();
	}
	catch (emu_exception &)
	{
		fprintf(stderr, "Caught unhandled emulator exception\n");
	}
	catch (std::bad_alloc &)
	{
		fprintf(stderr, "Out of memory!\n");
	}
	catch (...)
	{
		fprintf(stderr, "Caught unhandled exception\n");
	}

error:
	/* free our options and exit */
	if (options != NULL)
		options_free(options);

	/* report any unfreed memory */
	dump_unfreed_mem();
	return result;
}
Exemplo n.º 16
0
/* 
 * main function
 * 
 */
int main ( int argc, char *argv[] ) {
  printf( WELCOME_MSG );
  execute_commands();
  printf( QUIT_MSG );
  return 0;
}