Exemple #1
0
/* Load and run a script.
 */
void
run_script(const char *filename, bool allow_missing)
{
    FILE *file;
    char *line = NULL;
    size_t line_len = 0;

    file = fopen(filename, "r");
    if (file == NULL) {
        if (!allow_missing || errno != ENOENT)
            warn(_("%s: Cannot open file - %s\n"), quotearg(filename), errstr);
        return;
    }
    while (getline(&line, &line_len, file) > 0) {
        int c;
        for (c = strlen(line)-1; c > 0 && (line[c] == '\n' || line[c] == '\r'); c--)
            line[c] = '\0';
        command_execute(line);
    }
    free(line);
    if (ferror(file)) {
        warn(_("%s: Cannot read from file - %s\n"), quotearg(filename), errstr);
        if (fclose(file) < 0)
            warn(_("%s: Cannot close file - %s\n"), quotearg(filename), errstr);
        return;
    }
    if (fclose(file) < 0)
        warn(_("%s: Cannot close file - %s\n"), quotearg(filename), errstr);
}
Exemple #2
0
static void
settings_apply (GtkDialog *dialog, gint response_id, SwitchApplet *switch_applet)
{
  if (switch_applet->dirty[switch_applet->current])
    command_execute (switch_applet, switch_applet->current);
  gtk_widget_destroy(GTK_WIDGET (dialog));
}
void going_inactive(int block) {
  // debug(1, "activity_monitor: state transitioning to \"inactive\" with%s blocking", block ? "" :
  // "out");
  if (config.cmd_active_stop)
    command_execute(config.cmd_active_stop, "", block);
#ifdef CONFIG_METADATA
  debug(2, "aend");                       // active mode end
  send_ssnc_metadata('pend', NULL, 0, 1); // contains cancellation points
#endif

#ifdef CONFIG_DBUS_INTERFACE
  if (dbus_service_is_running())
    shairport_sync_set_active(SHAIRPORT_SYNC(shairportSyncSkeleton), FALSE);
#endif

  if (config.disable_standby_mode == disable_standby_auto) {
#ifdef CONFIG_DBUS_INTERFACE
  if (dbus_service_is_running())
    shairport_sync_set_disable_standby(SHAIRPORT_SYNC(shairportSyncSkeleton), FALSE);
  else
    config.keep_dac_busy = 0;  
#else
  config.keep_dac_busy = 0;  
#endif
  }
}
Exemple #4
0
static void task_console_process(void *ptr_task_struct) {
	static char stdin_buffer[STDINBUFFERSIZE];
	static defuint_t bytes_in;

	console_read_uart_available_bytes(stdin_buffer, &bytes_in);

	if (bytes_in > STDINDEFAULTCOMMANDSIZE)
		command_execute(stdin_buffer);
}
Exemple #5
0
int selector()
{
	//backup file descriptor set
	fd_set working_set; 
	int i = 0;

	//timeout values	
	struct timeval tv;
	tv.tv_sec = 2;
	tv.tv_usec = 500000;

	FD_ZERO(&master_set);
	FD_ZERO(&working_set);

	fdmax = serverSocket;
	
	updateSelect(ADD, serverSocket, &master_set, &fdmax);
	updateSelect(ADD, STDIN_FILENO, &master_set, &fdmax);

	while(true){
		//copy master to working set

		printf("\r%s:%s >> ", localInfo.hostname, localInfo.port); 
		fflush(stdout);
		
		working_set = master_set;
		//memcpy(&working_set, &master_set, sizeof(master_set));

		if(select(fdmax+1, &working_set, NULL, NULL, NULL) < 0){
			perror("select: ");
			return -1;
		}

		for(i = 0; i <= fdmax; i++){
			if(FD_ISSET(i, &working_set)){
				if(i == serverSocket){
					acceptConnection();
				}else if(i == STDIN_FILENO){
					char* command = NULL;
					size_t nbytes;
					int result;
					getline(&command, &nbytes, stdin);
					result = command_execute(command);
					if(result){
						printf("Menu command failed: %s\n", strerror(result));
					}
				}else{
					//pass socket requiring attention
					printf("Incoming Message..\n");
					handle_command(i);
				}
			}
		}
	}
	return -1;
}
Exemple #6
0
static void
settings_width_changed (GSettings *settings, gchar *key, CommandApplet *command_applet)
{
    gint width;

    width = g_settings_get_int (command_applet->settings, WIDTH_KEY);

    command_applet->width = width;

    /* execute command to start new timer */
    command_execute (command_applet);
}
Exemple #7
0
/*
 * Execute a series of external utility programs.
 * Returns 1 if everything executed OK, 0 if one of the
 * critical commands failed or if the user cancelled.
 */
int
commands_execute(struct i_fn_args *a, struct commands *cmds)
{
	struct dfui_progress *pr;
	struct command *cmd;
	int i;
	int n = 0;
	int result = 0;
	int return_val = 1;

	cmd = cmds->head;
	while (cmd != NULL) {
		n++;
		cmd = cmd->next;
	}

	pr = dfui_progress_new(dfui_info_new(
	    "Executing Commands",
	    "Executing Commands",
	    ""),
	    0);

	if (!dfui_be_progress_begin(a->c, pr))
		abort_backend();

	i = 1;
	for (cmd = cmds->head; cmd != NULL; cmd = cmd->next, i++) {
		result = command_execute(a, pr, cmd);
		if (result == COMMAND_RESULT_CANCELLED) {
			return_val = 0;
			break;
		}
		if (result > 0 && result < 256) {
			return_val = 0;
			if (cmd->failure_mode == COMMAND_FAILURE_ABORT) {
				break;
			}
		}
		dfui_progress_set_amount(pr, (i * 100) / n);
	}

	if (!dfui_be_progress_end(a->c))
		abort_backend();

	dfui_progress_free(pr);

	return(return_val);
}
Exemple #8
0
static void execute(char *buf)
{
    struct command *cmd = command_new();
    char *arg;
    char *rest;

    if (!cmd)
    {
        fprintf(stderr, "Memory exhausted\n");

        return;
    }

    while (*buf && *buf == ' ')
        buf++;

    if (!*buf)
    {
        command_free(cmd);

        return;
    }

    arg = strtok_r(buf, " ", &rest);

    while (arg)
    {
        if (command_append(cmd, arg) < 0)
        {
            command_free(cmd);

            fprintf(stderr, "Memory exhausted\n");

            return;
        }

        while (*rest && *rest == ' ')
            rest++;

        arg = strtok_r(NULL, " ", &rest);
    }

    command_append(cmd, NULL);

    command_execute(cmd);

    command_free(cmd);
}
Exemple #9
0
static gboolean
switch_applet_next (GtkWidget *widget, GdkEventButton *event, SwitchApplet *switch_applet)
{
  /* Left click press */
  if (event->type == GDK_BUTTON_PRESS && event->button == 1) {
    switch_applet->current = (switch_applet->current + 1) % MAX_TOGGLE;
    if (switch_applet->pixbuf[switch_applet->current]) {
      gtk_image_set_from_pixbuf(GTK_IMAGE(switch_applet->image),
          switch_applet->pixbuf[switch_applet->current]);
    }

    command_execute (switch_applet, switch_applet->current);
    return TRUE;
  }
  return FALSE;
}
Exemple #10
0
static void
changed_cb(GtkTreeSelection *selection, gpointer param)
{
  Selection_t *data = (Selection_t*) param;

  if (data->select_lock)
    {
      data->select_lock = FALSE;
    } else
      {
        Command_t *command, *sub_command;
        GtkTreeModel *model;
        GList *list, *selected_rows;

        selected_rows = gtk_tree_selection_get_selected_rows (selection,
                                                              &model);

        command = subcommand_start (NULL);
        sub_command = unselect_all_command_new (data->object_list, NULL);
        command_add_subcommand (command, sub_command);

        for (list = selected_rows; list; list = list->next)
          {
            Object_t *obj;
            GtkTreeIter iter;
            GtkTreePath *path = (GtkTreePath*) list->data;

            gtk_tree_model_get_iter (model, &iter, path);
            gtk_tree_model_get (model, &iter, 0, &obj, -1);

            sub_command = select_command_new (obj);
            command_add_subcommand (command, sub_command);
          }

        command_set_name (command, sub_command->name);
        subcommand_end ();

        command_execute (command);

        g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
        g_list_free (selected_rows);

        set_buttons (data);
  }
}
Exemple #11
0
static error_t myexecute(const char *line) {
	char workline[128];
	char *argv[8];
	int32_t argc = 0;
	char *p;
	const char separators[] = " ";
	size_t len;

	strncpy(workline, line, sizeof(workline));
	p = argv[0] = workline;
	len = strlen(line);

	for (argc=1; argc<8; ) {
		argv[argc++] = p = text_separate(p, len - (p - workline), separators);
		if (!p) {
			break;
		}
	}

	return command_execute(cmd_hdl, argc, (const char**)argv);
}
Exemple #12
0
static void
settings_interval_changed (GSettings *settings, gchar *key, CommandApplet *command_applet)
{
    gint interval;

    interval = g_settings_get_int (command_applet->settings, INTERVAL_KEY);

    /* minimum interval */
    if (interval < 1)
        interval = 1;

    command_applet->interval = interval;

    /* stop current timer */
    if (command_applet->timeout_id != 0)
    {
        g_source_remove (command_applet->timeout_id);
        command_applet->timeout_id = 0;
    }

    /* execute command to start new timer */
    command_execute (command_applet);
}
Exemple #13
0
int process_chat_command(int unum)
{
  register int i;
  int sd, rc, ibufsize;
  CHATLINE recbuf;
  
  sd = users[unum].sockfd;
#ifdef DEBUG
  printf("Incoming on fd %d: ", sd);
#endif
  if ((rc = recv(sd, recbuf, sizeof recbuf, 0)) <= 0) {
    /* disconnected */
    exit_room(unum, EXIT_LOSTCONN, (char *)NULL);
    return -1;
  }
  ibufsize = users[unum].ibufsize;
  for (i=0; i<rc; i++) {
    /* if newline is two characters, throw out the first */
    if (recbuf[i] == '\r') continue;

    /* carriage return signals end of line */
    else if (recbuf[i] == '\n') {
      users[unum].ibuf[ibufsize] = '\0';
      if (command_execute(unum) == -1) return -1;
      ibufsize = 0;
    }

    /* add other chars to input buffer unless size limit exceeded */
    else {
      if (ibufsize < CHATLINE_TEXT_MAX)
        users[unum].ibuf[ibufsize++] = recbuf[i];
    }
  }
  users[unum].ibufsize = ibufsize;
  return 0;
}
Exemple #14
0
static gboolean
command_applet_fill (MatePanelApplet* applet)
{
    CommandApplet *command_applet;

    g_set_application_name (_("Command Applet"));
    gtk_window_set_default_icon_name (APPLET_ICON);

    mate_panel_applet_set_flags (applet, MATE_PANEL_APPLET_EXPAND_MINOR);
    mate_panel_applet_set_background_widget (applet, GTK_WIDGET (applet));

    command_applet = g_malloc0(sizeof(CommandApplet));
    command_applet->applet = applet;
    command_applet->settings = mate_panel_applet_settings_new (applet, COMMAND_SCHEMA);

    command_applet->interval = g_settings_get_int (command_applet->settings, INTERVAL_KEY);
    command_applet->command = g_settings_get_string (command_applet->settings, COMMAND_KEY);
    command_applet->width = g_settings_get_int (command_applet->settings, WIDTH_KEY);

    command_applet->box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0));
    command_applet->image = GTK_IMAGE (gtk_image_new_from_icon_name (APPLET_ICON, 24));
    command_applet->label = GTK_LABEL (gtk_label_new (ERROR_OUTPUT));
    command_applet->timeout_id = 0;

    /* we add the Gtk label into the applet */
    gtk_box_pack_start (command_applet->box,
                        GTK_WIDGET (command_applet->image),
                        TRUE, TRUE, 0);
    gtk_box_pack_start (command_applet->box,
                        GTK_WIDGET (command_applet->label),
                        TRUE, TRUE, 0);

    gtk_container_add (GTK_CONTAINER (applet),
                       GTK_WIDGET (command_applet->box));

    gtk_widget_show_all (GTK_WIDGET (command_applet->applet));

    g_signal_connect(G_OBJECT (command_applet->applet), "destroy",
                     G_CALLBACK (command_applet_destroy),
                     command_applet);

    /* GSettings signals */
    g_signal_connect(command_applet->settings,
                     "changed::" COMMAND_KEY,
                     G_CALLBACK (settings_command_changed),
                     command_applet);
    g_signal_connect(command_applet->settings,
                     "changed::" INTERVAL_KEY,
                     G_CALLBACK (settings_interval_changed),
                     command_applet);
    g_signal_connect(command_applet->settings,
                     "changed::" WIDTH_KEY,
                     G_CALLBACK (settings_width_changed),
                     command_applet);
    g_settings_bind (command_applet->settings,
                     SHOW_ICON_KEY,
                     command_applet->image,
                     "visible",
                     G_SETTINGS_BIND_DEFAULT);

    /* set up context menu */
    GtkActionGroup *action_group = gtk_action_group_new ("Command Applet Actions");
    gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
    gtk_action_group_add_actions (action_group, applet_menu_actions,
                                  G_N_ELEMENTS (applet_menu_actions), command_applet);
    mate_panel_applet_setup_menu (command_applet->applet, ui, action_group);

    /* first command execution */
    command_execute (command_applet);

    return TRUE;
}
Exemple #15
0
void test_execute_command_with_parse_error(test_t *t) {
    command_t c = command_new(CMD_PARSE_ERROR, NIL);
    cr_t res = command_execute(c, NULL);

    assert_eq_int(t, CMD_RES_PARSE_ERR, res.code);
}
Exemple #16
0
void test_execute_command_without_user(test_t *t) {
    command_t c = command_new(CMD_TALK, NIL);
    cr_t res = command_execute(c, NULL);

    assert_eq_int(t, CMD_RES_NO_USR, res.code);
}
Exemple #17
0
int script_run(char exec[], char args[])
{

kol_struct70	k70;
kol_struct_BDVK	bdvk;
unsigned	result, filesize, pos, i;
char		*buf; //буфер, куда копируется скрипт

k70.p00 = 5;
k70.p04 = k70.p08 = k70.p12 = 0;
k70.p16 = (unsigned) &bdvk;
k70.p20 = 0;
k70.p21 = exec;

result = kol_file_70(&k70); // получаем информацию о файле
if ( 0 != result ) 
	return FALSE;

filesize = bdvk.p32[0]; // получаем размер файла

buf = malloc(filesize+256);
if (NULL == buf)
	return FALSE;

buf[filesize]=0;

k70.p00 = 0;
k70.p04 = k70.p08 = 0;
k70.p12 = filesize;
k70.p16 = (unsigned) buf;
k70.p20 = 0;
k70.p21 = exec;

result = kol_file_70(&k70); // считываем файл в буфер
if ( 0 != result ) 
	{
	free(buf);
	return FALSE;
	}

pos = 0;

for (;;) // обработка скрипта
	{

	if (pos > filesize)
		break;

	for (i=0;;i++) // считывание строки
		{
		if ((0x0A == buf[pos])||(0x0D == buf[pos])||(0 == buf[pos]))
			{
			pos++;
			CMD[i] = '\0';
			break;
			}
		CMD[i] = buf[pos];
		pos++;
		}

	if ( 0 == strlen(CMD) ) // пустая строка
		continue;

	if ('#' == CMD[0]) // комментарий
		continue;

	command_execute();

	}

free(buf);
return TRUE;
}