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