Blame gio/tests/dbus-launch.c

Packit ae235b
/*
Packit ae235b
 * Mock version of dbus-launch, for gdbus-unix-addresses test
Packit ae235b
 *
Packit ae235b
 * Copyright © 2015 Collabora Ltd.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include <glib.h>
Packit ae235b
Packit ae235b
#ifndef G_OS_UNIX
Packit ae235b
#error This is a Unix-specific test helper
Packit ae235b
#endif
Packit ae235b
Packit ae235b
#include <errno.h>
Packit ae235b
#include <string.h>
Packit ae235b
#include <sys/types.h>
Packit ae235b
#include <unistd.h>
Packit ae235b
Packit ae235b
#define ME "GDBus mock version of dbus-launch"
Packit ae235b
Packit ae235b
static void
Packit ae235b
write_all (const void *ptr,
Packit ae235b
           size_t      len)
Packit ae235b
{
Packit ae235b
  const char *p = ptr;
Packit ae235b
Packit ae235b
  while (len > 0)
Packit ae235b
    {
Packit ae235b
      gssize done = write (STDOUT_FILENO, p, len);
Packit ae235b
      int errsv = errno;
Packit ae235b
Packit ae235b
      if (done == 0)
Packit ae235b
        {
Packit ae235b
          g_error ("%s: write: EOF", ME);
Packit ae235b
        }
Packit ae235b
      else if (done < 0)
Packit ae235b
        {
Packit ae235b
          if (errsv == EINTR)
Packit ae235b
            continue;
Packit ae235b
Packit ae235b
          g_error ("%s: write: %s", ME, g_strerror (errsv));
Packit ae235b
        }
Packit ae235b
      else
Packit ae235b
        {
Packit ae235b
          if (len < (size_t) done)
Packit ae235b
            g_error ("%s: wrote too many bytes?", ME);
Packit ae235b
Packit ae235b
          len -= done;
Packit ae235b
          p += done;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
int
Packit ae235b
main (int   argc,
Packit ae235b
      char *argv[])
Packit ae235b
{
Packit ae235b
  pid_t pid = 0x2323;
Packit ae235b
  long window_id = 0x42424242;
Packit ae235b
  const char *addr = "hello:this=address-is-from-the,mock=dbus-launch";
Packit ae235b
Packit ae235b
  write_all (addr, strlen (addr) + 1);
Packit ae235b
  write_all (&pid, sizeof (pid));
Packit ae235b
  write_all (&window_id, sizeof (window_id));
Packit ae235b
  return 0;
Packit ae235b
}