1 /* libsecret - GLib wrapper for Secret Service
3 * Copyright 2011 Red Hat Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation; either version 2 of the licence or (at
8 * your option) any later version.
10 * See the included COPYING file for more information.
12 * Author: Stef Walter <stefw@gnome.org>
18 #include "mock-service.h"
20 #include "secret-private.h"
28 mock_service_start (const gchar *mock_script,
31 gchar ready[8] = { 0, };
39 "python", (gchar *)mock_script,
40 "--name", MOCK_SERVICE_NAME,
45 g_return_val_if_fail (mock_script != NULL, FALSE);
46 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
48 g_setenv ("SECRET_SERVICE_BUS_NAME", MOCK_SERVICE_NAME, TRUE);
50 if (pipe (wait_pipe) < 0) {
51 g_set_error_literal (error, G_IO_ERROR, g_io_error_from_errno (errno),
52 "Couldn't create pipe for mock service");
56 snprintf (ready, sizeof (ready), "%d", wait_pipe[1]);
58 flags = G_SPAWN_SEARCH_PATH | G_SPAWN_LEAVE_DESCRIPTORS_OPEN;
59 ret = g_spawn_async (SRCDIR, argv, NULL, flags, NULL, NULL, &pid, error);
64 poll_fd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
65 poll_fd.fd = wait_pipe[0];
68 polled = g_poll (&poll_fd, 1, 2000);
70 g_warning ("couldn't poll file descirptor: %s", g_strerror (errno));
72 g_warning ("couldn't wait for mock service");
80 mock_service_stop (void)
85 if (kill (pid, SIGTERM) < 0) {
87 g_warning ("kill() failed: %s", g_strerror (errno));
90 g_spawn_close_pid (pid);