summaryrefslogtreecommitdiff
path: root/deps/vts/test-hang.c
blob: 5568b028590f367dbc06b37c3d9b15bd650a3131 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

#include <stdio.h>
#include <stdlib.h>
#include <poll.h>
#include <errno.h>

#include <vts.h>

static void
on_enter (VTSClient *client, void *user_data)
{
  printf ("VT Enter\n");
}

static void
on_leave (VTSClient *client, void *user_data)
{
  printf ("VT Leave\n");
  printf ("Hang...\n");
  while (1)
    sleep (5);
}

static void
run_client (VTSClient *client)
{
  struct pollfd pollfd;

  printf ("Run Client\n");

  vts_client_set_vt_enter_callback (client, on_enter, NULL);
  vts_client_set_vt_leave_callback (client, on_leave, NULL);

  pollfd.fd = vts_client_get_poll_fd (client);
  pollfd.events = POLLIN;

  while (1)
    {
      int n;
      VTSError *error = NULL;

      do {
        n = poll (&pollfd, 1, -1);
      } while (n < 0 && errno == EINTR);

      if (n < 0)
        fprintf (stderr, "epoll_wait failed: %m");

      printf ("client dispatch\n");
      if (n)
        {
          if (!vts_client_dispatch (client, &error))
            {
              fprintf (stderr, "Failed to dispatch vts events: %s\n",
                       error->message);
              exit (1);
            }
        }
    }
}

int
main (int argc, char **argv)
{
  VTSServer *server = vts_server_new ();
  VTSClient *client;
  VTSError *error = NULL;

  vts_server_set_pam_enabled (server, 1);
  vts_server_set_kernel_key_bindings_enabled (server, 1);

  client = vts_server_run (server, &error);

  if (error)
    {
      fprintf (stderr, "Failed to run server: %s\n", error->message);
      vts_error_free (error);
      return EXIT_FAILURE;
    }

  if (client)
    run_client (client);
}