Exemplo n.º 1
0
int main(int argc, char **argv) {
	get_command_args(argc, argv);

	char line[10];
	FILE *cmd = popen("pidof -s catcher", "r");

	fgets(line, 10, cmd);
	pid_t pid = strtoul(line, NULL, 10);

	pclose(cmd);

	signal(SIGRTMIN + 1, signal_received);
	signal(SIGRTMIN + 2, finish_receiving);

	int i;
	for(i = 0; i < NUM_OF_SIGNALS; i++) {
		kill(pid, SIGRTMIN + 1);
	}

	kill(pid, SIGRTMIN + 2);

	while(1) {

	}

	return 0;
}
Exemplo n.º 2
0
int		gere_instruction(char **words, char *s, t_asmline *line)
{
  char		*lbl;

  if (words[0] && is_label(words[0]))
    {
      line->code = -1;
      lbl = my_strdup(words[0]);
      get_command_args(words, line->argv);
      line->argv[0] = lbl;
    }
  else if (words[0] && words[1])
    {
      line->code = get_command_id(words[0]);
      get_command_arg_type(words + 1, line->type);
      get_command_args(words + 1, line->argv);
    }
  else
    return (0);
  if (line->code > 0)
    verif_args(line, s);
  return (1);
}
Exemplo n.º 3
0
bool	is_command(char **words, char *s, t_cmd *line, char **label_index)
{
  char	*lbl;

  if (words[0] && is_label(words[0]))
    {
      line->cmd_code = T_LABEL;
      lbl = my_strdup(words[0]);
      get_command_args(words, line->arg.argv);
      line->arg.argv[0] = lbl;
      (void)label_index;
    }
  else if (words[0] && words[1])
    {
      line->cmd_code = get_command_id(words[0]);
      get_command_arg_type(words + 1, line->arg.type);
      get_command_args(words + 1, line->arg.argv);
    }
  else
    return (FALSE);
  if (line->cmd_code > T_NONE)
    check_args(line, s);
  return (TRUE);
}
bool CmdexSync::execute()
{
	set_error_msg("");  // clear old error if present

	bool slot_connected = !(signal_execute_tick.slots().begin() == signal_execute_tick.slots().end());

	if (slot_connected && !signal_execute_tick.emit(status_starting))
		return false;

	if (!cmdex_.execute()) {  // try to execute
		debug_out_error("app", DBG_FUNC_MSG << "cmdex_.execute() failed.\n");
		import_error();  // get error from cmdex and display warnings if needed

		// emit this for execution loggers
		cmdex_sync_signal_execute_finish()->emit(CmdexSyncCommandInfo(get_command_name(),
				get_command_args(), get_stdout_str(), get_stderr_str(), get_error_msg()));

		if (slot_connected)
			signal_execute_tick.emit(status_failed);
		return false;
	}

	bool stop_requested = false;  // stop requested from tick function
	bool signals_sent = false;  // stop signals sent

	while(!cmdex_.stopped_cleanup_needed()) {

		if (!stop_requested) {  // running and no stop requested yet
			// call the tick function with "running" periodically.
			// if it returns false, try to stop.
			if (slot_connected && !signal_execute_tick.emit(status_running)) {
				debug_out_info("app", DBG_FUNC_MSG << "execute_tick slot returned false, trying to stop the program.\n");
				stop_requested = true;
			}
		}


		if (stop_requested && !signals_sent) {  // stop request received
			// send the stop request to the command
			if (!cmdex_.try_stop()) {  // try sigterm. this returns false if it can't be done (no permissions, zombie)
				debug_out_warn("app", DBG_FUNC_MSG << "cmdex_.try_stop() returned false.\n");
			}

			// set sigkill timeout to 3 sec (in case sigterm fails); won't do anything if already exited.
			cmdex_.set_stop_timeouts(0, forced_kill_timeout_msec);
			// import_error();  // don't need errors here - they will be available later anyway.

			signals_sent = true;
		}


		// alert the tick function
		if (stop_requested && slot_connected) {
			signal_execute_tick.emit(status_stopping);  // ignore returned value here
		}


		// without this, no event sources will be processed and the program will
		// hang waiting for the child to exit (the watch handler won't be called).
		while(g_main_context_pending(NULL)) {
			g_main_context_iteration(NULL, false);
		}

		Glib::usleep(50*1000);  // 50 msec. avoids 100% CPU usage.
	}

	// command exited, do a cleanup.
	cmdex_.stopped_cleanup();
	import_error();  // get error from cmdex and display warnings if needed

	// emit this for execution loggers
	cmdex_sync_signal_execute_finish()->emit(CmdexSyncCommandInfo(get_command_name(),
			get_command_args(), get_stdout_str(), get_stderr_str(), get_error_msg()));

	if (slot_connected)
		signal_execute_tick.emit(status_stopped);  // last call

	return true;
}