summaryrefslogtreecommitdiff
path: root/gio/tests/dbus-launch.c
blob: 90d8d069e73d893ef7982c46a6a9992769da70f2 (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
/*
 * Mock version of dbus-launch, for gdbus-unix-addresses test
 *
 * Copyright © 2015 Collabora Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>

#ifndef G_OS_UNIX
#error This is a Unix-specific test helper
#endif

#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

#define ME "GDBus mock version of dbus-launch"

static void
write_all (const void *ptr,
           size_t      len)
{
  const char *p = ptr;

  while (len > 0)
    {
      gssize done = write (STDOUT_FILENO, p, len);
      int errsv = errno;

      if (done == 0)
        {
          g_error ("%s: write: EOF", ME);
        }
      else if (done < 0)
        {
          if (errsv == EINTR)
            continue;

          g_error ("%s: write: %s", ME, g_strerror (errsv));
        }
      else
        {
          if (len < (size_t) done)
            g_error ("%s: wrote too many bytes?", ME);

          len -= done;
          p += done;
        }
    }
}

int
main (int   argc,
      char *argv[])
{
  pid_t pid = 0x2323;
  long window_id = 0x42424242;
  const char *addr = "hello:this=address-is-from-the,mock=dbus-launch";

  write_all (addr, strlen (addr) + 1);
  write_all (&pid, sizeof (pid));
  write_all (&window_id, sizeof (window_id));
  return 0;
}