Ejemplo n.º 1
0
void
ply_terminal_close (ply_terminal_t *terminal)
{
    if (!terminal->is_open) {
        ply_trace ("terminal %s is already closed", terminal->name);
        return;
    }

    terminal->is_open = false;

    ply_terminal_stop_watching_for_vt_changes (terminal);

    ply_trace ("restoring color palette");
    ply_terminal_restore_color_palette (terminal);

    if (terminal->fd_watch != NULL) {
        ply_trace ("stop watching tty fd");
        ply_event_loop_stop_watching_fd (terminal->loop, terminal->fd_watch);
        terminal->fd_watch = NULL;
    }

    if (terminal->loop != NULL) {
        ply_trace ("stop watching SIGWINCH signal");
        ply_event_loop_stop_watching_signal (terminal->loop, SIGWINCH);
    }

    ply_trace ("setting buffered input");
    ply_terminal_set_buffered_input (terminal);

    close (terminal->fd);
    terminal->fd = -1;
}
Ejemplo n.º 2
0
static void
ply_boot_client_cancel_unsent_requests (ply_boot_client_t *client)
{
  ply_list_node_t *node;

  if (ply_list_get_length (client->requests_to_send) == 0)
      return;

  node = ply_list_get_first_node (client->requests_to_send);
  while (node != NULL)
    {
      ply_list_node_t *next_node;
      ply_boot_client_request_t *request;

      request = (ply_boot_client_request_t *) ply_list_node_get_data (node);
      next_node = ply_list_get_next_node (client->requests_to_send, node);

      ply_boot_client_cancel_request (client, request);
      ply_list_remove_node (client->requests_to_send, node);

      node = next_node;
    }

  if (client->daemon_can_take_request_watch != NULL)
    {
      assert (client->loop != NULL);

      ply_event_loop_stop_watching_fd (client->loop, 
                                       client->daemon_can_take_request_watch);
      client->daemon_can_take_request_watch = NULL;
    }
}
Ejemplo n.º 3
0
static void
ply_boot_client_process_pending_requests (ply_boot_client_t *client)
{
  ply_list_node_t *request_node;
  ply_boot_client_request_t *request;

  assert (ply_list_get_length (client->requests_to_send) != 0);
  assert (client->daemon_can_take_request_watch != NULL);

  request_node = ply_list_get_first_node (client->requests_to_send);
  assert (request_node != NULL);

  request = (ply_boot_client_request_t *) ply_list_node_get_data (request_node);
  assert (request != NULL);

  ply_list_remove_node (client->requests_to_send, request_node);

  if (ply_boot_client_send_request (client, request))
    ply_list_append_data (client->requests_waiting_for_replies, request);

  if (ply_list_get_length (client->requests_to_send) == 0)
    {
      if (client->daemon_has_reply_watch != NULL)
        {
          assert (client->loop != NULL);

          ply_event_loop_stop_watching_fd (client->loop,
                                           client->daemon_can_take_request_watch);
          client->daemon_can_take_request_watch = NULL;
        }
    }
}
Ejemplo n.º 4
0
static void
close_input_source (ply_renderer_backend_t      *backend,
                    ply_renderer_input_source_t *input_source)
{
  assert (backend != NULL);
  assert (has_input_source (backend, input_source));

  ply_event_loop_stop_watching_fd (backend->loop, input_source->terminal_input_watch);
  input_source->terminal_input_watch = NULL;
  input_source->backend = NULL;
}
Ejemplo n.º 5
0
static void
ply_boot_client_process_incoming_replies (ply_boot_client_t *client)
{
  ply_list_node_t *request_node;
  ply_boot_client_request_t *request;
  bool processed_reply;
  uint8_t byte[2] = "";
  uint32_t size;

  assert (client != NULL);

  processed_reply = false;
  if (ply_list_get_length (client->requests_waiting_for_replies) == 0)
    {
      ply_error ("received unexpected response from boot status daemon");
      return;
    }

  if (!ply_read (client->socket_fd, byte, sizeof (uint8_t)))
    goto out;

  for (request_node = ply_list_get_first_node (client->requests_waiting_for_replies);
       request_node; request_node = ply_list_get_next_node (client->requests_waiting_for_replies, request_node))
    {
      assert (request_node != NULL);
      request = (ply_boot_client_request_t *) ply_list_node_get_data (request_node);
      assert (request != NULL);

      if (! strcmp (request->command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_PASSWORD)
          || ! strcmp (request->command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_QUESTION)
          || ! strcmp (request->command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_KEYSTROKE))
        {
          if (! memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER, sizeof (uint8_t))
              || ! memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER, sizeof (uint8_t)))
            break;
        }
      else
        {
          if (memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER, sizeof (uint8_t))
              && memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER, sizeof (uint8_t)))
            break;
        }
    }

  if (memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ACK, sizeof (uint8_t)) == 0)
      request->handler (request->user_data, client);
  else if (memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER, sizeof (uint8_t)) == 0)
    {
      char *answer;

      if (!ply_read_uint32 (client->socket_fd, &size))
        goto out;
      
      answer = malloc ((size+1) * sizeof(char));
      if (size > 0)
        {
          if (!ply_read (client->socket_fd, answer, size))
            goto out;
        }

      answer[size] = '\0';
      ((ply_boot_client_answer_handler_t) request->handler) (request->user_data, answer, client);
      free(answer);
    }
  else if (memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_MULTIPLE_ANSWERS, sizeof (uint8_t)) == 0)
    {
      ply_array_t *array;
      char **answers;
      char *answer;
      char *p;
      char *q;
      uint8_t i;

      array = NULL;
      answers = NULL;

      if (!ply_read_uint32 (client->socket_fd, &size))
        goto out;

      assert (size > 0);

      answer = malloc (size);

      if (!ply_read (client->socket_fd, answer, size))
        {
          free (answer);
          goto out;
        }

      array = ply_array_new ();

      p = answer;
      q = p;
      for (i = 0; i < size; i++, q++)
        {
          if (*q == '\0')
            {
              ply_array_add_element (array, strdup (p));
              p = q + 1;
            }
        }
      free (answer);

      answers = (char **) ply_array_steal_elements (array);
      ply_array_free (array);

      ((ply_boot_client_multiple_answers_handler_t) request->handler) (request->user_data, (const char * const *) answers, client);

      ply_free_string_array (answers);
    }
  else if (memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER, sizeof (uint8_t)) == 0)
    {
      ((ply_boot_client_answer_handler_t) request->handler) (request->user_data, NULL, client);
    }
  else
    goto out;

  processed_reply = true;

out:
  if (!processed_reply)
    {
      if (request->failed_handler != NULL)
        request->failed_handler (request->user_data, client);
    }

  ply_list_remove_node (client->requests_waiting_for_replies, request_node);

  if (ply_list_get_length (client->requests_waiting_for_replies) == 0)
    {
      if (client->daemon_has_reply_watch != NULL)
        {
          assert (client->loop != NULL);
          ply_event_loop_stop_watching_fd (client->loop,
                                           client->daemon_has_reply_watch);
          client->daemon_has_reply_watch = NULL;
        }
    }
}