1/*
2 * Mock version of dbus-launch, for gdbus-address-get-session test
3 *
4 * Copyright © 2015 Collabora Ltd.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <glib.h>
21
22#ifndef G_OS_UNIX
23#error This is a Unix-specific test helper
24#endif
25
26#include <errno.h>
27#include <string.h>
28#include <sys/types.h>
29#include <unistd.h>
30
31#define ME "GDBus mock version of dbus-launch"
32
33static void
34write_all (const void *ptr,
35 size_t len)
36{
37 const char *p = ptr;
38
39 while (len > 0)
40 {
41 gssize done = write (STDOUT_FILENO, buf: p, n: len);
42 int errsv = errno;
43
44 if (done == 0)
45 {
46 g_error ("%s: write: EOF", ME);
47 }
48 else if (done < 0)
49 {
50 if (errsv == EINTR)
51 continue;
52
53 g_error ("%s: write: %s", ME, g_strerror (errsv));
54 }
55 else
56 {
57 if (len < (size_t) done)
58 g_error ("%s: wrote too many bytes?", ME);
59
60 len -= done;
61 p += done;
62 }
63 }
64}
65
66int
67main (int argc,
68 char *argv[])
69{
70 pid_t pid = 0x2323;
71 long window_id = 0x42424242;
72 const char *addr = "hello:this=address-is-from-the,mock=dbus-launch";
73
74 write_all (ptr: addr, len: strlen (s: addr) + 1);
75 write_all (ptr: &pid, len: sizeof (pid));
76 write_all (ptr: &window_id, len: sizeof (window_id));
77 return 0;
78}
79

source code of gtk/subprojects/glib/gio/tests/dbus-launch.c