2007-07-14 02:44:01 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
2006-09-30 19:38:34 +00:00
|
|
|
/* dbus-launch.h dbus-launch utility
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2006 Thiago Macieira <thiago@kde.org>
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Academic Free License version 2.1
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2009-07-10 19:32:38 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-09-30 19:38:34 +00:00
|
|
|
*
|
|
|
|
|
*/
|
2010-03-19 12:36:49 +01:00
|
|
|
|
|
|
|
|
#include <config.h>
|
2006-09-30 19:38:34 +00:00
|
|
|
#include "dbus-launch.h"
|
|
|
|
|
|
|
|
|
|
#ifdef DBUS_BUILD_X11
|
|
|
|
|
#include <stdlib.h>
|
2006-10-01 20:05:39 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
2006-09-30 19:38:34 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <pwd.h>
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
|
|
2006-09-30 Havoc Pennington <hp@redhat.com>
* configure.in (LT_CURRENT, LT_AGE): increment current and age to
reflect addition of interfaces.
* doc/dbus-specification.xml: describe a new
org.freedesktop.DBus.Peer.GetMachineId method
* dbus/dbus-string.c (_dbus_string_skip_white_reverse): new function
(_dbus_string_skip_white, _dbus_string_skip_blank): use new
DBUS_IS_ASCII_BLANK, DBUS_IS_ASCII_WHITE macros and fix assertion
at end of skip_white
(_dbus_string_chop_white): new function
* bus/connection.c (bus_connections_setup_connection): call
dbus_connection_set_route_peer_messages.
* dbus/dbus-connection.c
(_dbus_connection_peer_filter_unlocked_no_update): modify to
support a GetMachineId method.
Also, support a new flag to let the bus pass peer methods through
to apps on the bus, which can be set with
dbus_connection_set_route_peer_messages.
Finally, handle and return an error for anything unknown on the
Peer interface, which will allow us to extend the Peer interface
in the future without fear that we're now intercepting something
apps were wanting to see.
* tools/dbus-uuidgen.c: a thin wrapper around the functions in
dbus/dbus-uuidgen.c
* dbus/dbus-uuidgen.c: implement the bulk of the dbus-uuidgen
binary here, since most of the code is already in libdbus
* dbus/dbus-sysdeps.c (_dbus_read_local_machine_uuid): read the
uuid from the system config file
* dbus/dbus-internals.c (_dbus_generate_uuid, _dbus_uuid_encode)
(_dbus_read_uuid_file_without_creating)
(_dbus_create_uuid_file_exclusively, _dbus_read_uuid_file): new
uuid-related functions, partly factored out from dbus-server.c
* dbus/dbus-sysdeps.c (_dbus_error_from_errno): convert EEXIST to
DBUS_ERROR_FILE_EXISTS instead of EEXIST
* dbus/dbus-protocol.h (DBUS_ERROR_FILE_EXISTS): add file exists error
* tools/dbus-cleanup-sockets.1: explain what the point of this
thing is a bit more
* autogen.sh (run_configure): add --config-cache to default
configure args
* dbus/dbus-internals.h (_DBUS_ASSERT_ERROR_IS_SET): disable the
error set/clear assertions when DBUS_DISABLE_CHECKS is defined
* tools/dbus-launch.c (main): if xdisplay hasn't been opened,
don't try to save address, fixes crash in make check
2006-10-01 03:18:47 +00:00
|
|
|
Display *xdisplay = NULL;
|
2006-09-30 19:38:34 +00:00
|
|
|
static Atom selection_atom;
|
|
|
|
|
static Atom address_atom;
|
|
|
|
|
static Atom pid_atom;
|
|
|
|
|
|
|
|
|
|
static int
|
2016-08-21 21:30:49 +02:00
|
|
|
x_io_error_handler (Display *local_xdisplay)
|
2006-09-30 19:38:34 +00:00
|
|
|
{
|
|
|
|
|
verbose ("X IO error\n");
|
|
|
|
|
kill_bus_and_exit (0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-01 20:05:39 +00:00
|
|
|
static void
|
|
|
|
|
remove_prefix (char *s,
|
Be more const-correct
As a general design principle, strings that we aren't going to modify
should usually be const. When compiling with -Wwrite-strings, quoted
string constants are of type "const char *", causing compiler warnings
when they are assigned to char * variables.
Unfortunately, we need to add casts in a few places:
* _dbus_list_append(), _dbus_test_oom_handling() and similar generic
"user-data" APIs take a void *, not a const void *, so we have
to cast
* For historical reasons the execve() family of functions take a
(char * const *), i.e. a constant pointer to an array of mutable
strings, so again we have to cast
* _dbus_spawn_async_with_babysitter similarly takes a char **,
although we can make it a little more const-correct by making it
take (char * const *) like execve() does
This also incorporates a subsequent patch by Thomas Zimmermann to
put various string constants in static storage, which is a little
more efficient.
Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97357
2016-10-07 17:41:01 +01:00
|
|
|
const char *prefix)
|
2006-09-30 19:38:34 +00:00
|
|
|
{
|
2006-10-01 20:05:39 +00:00
|
|
|
int plen;
|
|
|
|
|
|
|
|
|
|
plen = strlen (prefix);
|
2006-09-30 19:38:34 +00:00
|
|
|
|
2006-10-01 20:05:39 +00:00
|
|
|
if (strncmp (s, prefix, plen) == 0)
|
2006-09-30 19:38:34 +00:00
|
|
|
{
|
2006-10-01 20:05:39 +00:00
|
|
|
memmove (s, s + plen, strlen (s) - plen + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-09-30 19:38:34 +00:00
|
|
|
|
2006-10-01 20:05:39 +00:00
|
|
|
static const char*
|
|
|
|
|
get_homedir (void)
|
|
|
|
|
{
|
|
|
|
|
const char *home;
|
|
|
|
|
|
|
|
|
|
home = getenv ("HOME");
|
|
|
|
|
if (home == NULL)
|
|
|
|
|
{
|
|
|
|
|
/* try from the user database */
|
|
|
|
|
struct passwd *user = getpwuid (getuid());
|
|
|
|
|
if (user != NULL)
|
|
|
|
|
home = user->pw_dir;
|
|
|
|
|
}
|
2006-09-30 19:38:34 +00:00
|
|
|
|
2006-10-01 20:05:39 +00:00
|
|
|
if (home == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Can't get user home directory\n");
|
|
|
|
|
exit (1);
|
2006-09-30 19:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
2006-10-01 20:05:39 +00:00
|
|
|
return home;
|
2006-09-30 19:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
2006-10-01 20:05:39 +00:00
|
|
|
#define DBUS_DIR ".dbus"
|
|
|
|
|
#define DBUS_SESSION_BUS_DIR "session-bus"
|
|
|
|
|
|
2006-09-30 19:38:34 +00:00
|
|
|
static char *
|
|
|
|
|
get_session_file (void)
|
|
|
|
|
{
|
2006-10-01 20:05:39 +00:00
|
|
|
static const char prefix[] = "/" DBUS_DIR "/" DBUS_SESSION_BUS_DIR "/";
|
|
|
|
|
const char *machine;
|
|
|
|
|
const char *home;
|
2006-09-30 19:38:34 +00:00
|
|
|
char *display;
|
|
|
|
|
char *result;
|
|
|
|
|
char *p;
|
|
|
|
|
|
2006-10-26 17:34:49 +00:00
|
|
|
machine = get_machine_uuid ();
|
|
|
|
|
if (machine == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2006-09-30 19:38:34 +00:00
|
|
|
display = xstrdup (getenv ("DISPLAY"));
|
|
|
|
|
if (display == NULL)
|
|
|
|
|
{
|
|
|
|
|
verbose ("X11 integration disabled because X11 is not running\n");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* remove the screen part of the display name */
|
|
|
|
|
p = strrchr (display, ':');
|
|
|
|
|
if (p != NULL)
|
2006-10-01 20:05:39 +00:00
|
|
|
{
|
|
|
|
|
for ( ; *p; ++p)
|
2006-09-30 19:38:34 +00:00
|
|
|
{
|
2006-10-01 20:05:39 +00:00
|
|
|
if (*p == '.')
|
|
|
|
|
{
|
|
|
|
|
*p = '\0';
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-09-30 19:38:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-01 20:05:39 +00:00
|
|
|
/* Note that we leave the hostname in the display most of the
|
|
|
|
|
* time. The idea is that we want to be per-(machine,display,user)
|
|
|
|
|
* triplet to be extra-sure we get a bus we can connect to. Ideally
|
|
|
|
|
* we'd recognize when the hostname matches the machine we're on in
|
|
|
|
|
* all cases; we do try to drop localhost and localhost.localdomain
|
|
|
|
|
* as a special common case so that alternate spellings of DISPLAY
|
|
|
|
|
* don't result in extra bus instances.
|
|
|
|
|
*
|
|
|
|
|
* We also kill the ":" if there's nothing in front of it. This
|
|
|
|
|
* avoids an ugly double underscore in the filename.
|
|
|
|
|
*/
|
|
|
|
|
remove_prefix (display, "localhost.localdomain:");
|
|
|
|
|
remove_prefix (display, "localhost:");
|
|
|
|
|
remove_prefix (display, ":");
|
|
|
|
|
|
|
|
|
|
/* replace the : in the display with _ if the : is still there.
|
|
|
|
|
* use _ instead of - since it can't be in hostnames.
|
|
|
|
|
*/
|
|
|
|
|
for (p = display; *p; ++p)
|
2006-09-30 19:38:34 +00:00
|
|
|
{
|
2006-10-01 20:05:39 +00:00
|
|
|
if (*p == ':')
|
|
|
|
|
*p = '_';
|
2006-09-30 19:38:34 +00:00
|
|
|
}
|
2006-10-01 20:05:39 +00:00
|
|
|
|
|
|
|
|
home = get_homedir ();
|
|
|
|
|
|
|
|
|
|
result = malloc (strlen (home) + strlen (prefix) + strlen (machine) +
|
2006-09-30 19:38:34 +00:00
|
|
|
strlen (display) + 2);
|
|
|
|
|
if (result == NULL)
|
|
|
|
|
{
|
|
|
|
|
/* out of memory */
|
|
|
|
|
free (display);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strcpy (result, home);
|
|
|
|
|
strcat (result, prefix);
|
2006-10-01 20:05:39 +00:00
|
|
|
strcat (result, machine);
|
|
|
|
|
strcat (result, "-");
|
2006-09-30 19:38:34 +00:00
|
|
|
strcat (result, display);
|
|
|
|
|
free (display);
|
|
|
|
|
|
|
|
|
|
verbose ("session file: %s\n", result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-01 20:05:39 +00:00
|
|
|
static void
|
|
|
|
|
ensure_session_directory (void)
|
|
|
|
|
{
|
|
|
|
|
const char *home;
|
|
|
|
|
char *dir;
|
|
|
|
|
|
|
|
|
|
home = get_homedir ();
|
|
|
|
|
|
|
|
|
|
/* be sure we have space for / and nul */
|
|
|
|
|
dir = malloc (strlen (home) + strlen (DBUS_DIR) + strlen (DBUS_SESSION_BUS_DIR) + 3);
|
|
|
|
|
if (dir == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "no memory\n");
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strcpy (dir, home);
|
|
|
|
|
strcat (dir, "/");
|
|
|
|
|
strcat (dir, DBUS_DIR);
|
|
|
|
|
|
|
|
|
|
if (mkdir (dir, 0700) < 0)
|
|
|
|
|
{
|
|
|
|
|
/* only print a warning here, writing the session file itself will fail later */
|
|
|
|
|
if (errno != EEXIST)
|
|
|
|
|
fprintf (stderr, "Unable to create %s\n", dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strcat (dir, "/");
|
|
|
|
|
strcat (dir, DBUS_SESSION_BUS_DIR);
|
|
|
|
|
|
|
|
|
|
if (mkdir (dir, 0700) < 0)
|
|
|
|
|
{
|
|
|
|
|
/* only print a warning here, writing the session file itself will fail later */
|
|
|
|
|
if (errno != EEXIST)
|
|
|
|
|
fprintf (stderr, "Unable to create %s\n", dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free (dir);
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-30 19:38:34 +00:00
|
|
|
static Display *
|
|
|
|
|
open_x11 (void)
|
|
|
|
|
{
|
|
|
|
|
if (xdisplay != NULL)
|
|
|
|
|
return xdisplay;
|
|
|
|
|
|
|
|
|
|
xdisplay = XOpenDisplay (NULL);
|
|
|
|
|
if (xdisplay != NULL)
|
|
|
|
|
{
|
|
|
|
|
verbose ("Connected to X11 display '%s'\n", DisplayString (xdisplay));
|
|
|
|
|
XSetIOErrorHandler (x_io_error_handler);
|
|
|
|
|
}
|
|
|
|
|
return xdisplay;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
init_x_atoms (Display *display)
|
|
|
|
|
{
|
2006-10-01 20:05:39 +00:00
|
|
|
static const char selection_prefix[] = "_DBUS_SESSION_BUS_SELECTION_";
|
|
|
|
|
static const char address_prefix[] = "_DBUS_SESSION_BUS_ADDRESS";
|
|
|
|
|
static const char pid_prefix[] = "_DBUS_SESSION_BUS_PID";
|
2006-09-30 19:38:34 +00:00
|
|
|
static int init = FALSE;
|
|
|
|
|
char *atom_name;
|
2006-10-01 20:05:39 +00:00
|
|
|
const char *machine;
|
2006-09-30 19:38:34 +00:00
|
|
|
char *user_name;
|
|
|
|
|
struct passwd *user;
|
|
|
|
|
|
|
|
|
|
if (init)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
2006-10-26 17:34:49 +00:00
|
|
|
machine = get_machine_uuid ();
|
|
|
|
|
if (machine == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2006-09-30 19:38:34 +00:00
|
|
|
user = getpwuid (getuid ());
|
|
|
|
|
if (user == NULL)
|
|
|
|
|
{
|
2011-06-10 16:45:34 +01:00
|
|
|
verbose ("Could not determine user information; aborting X11 integration.\n");
|
2006-09-30 19:38:34 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
user_name = xstrdup(user->pw_name);
|
|
|
|
|
|
2006-10-01 20:05:39 +00:00
|
|
|
atom_name = malloc (strlen (machine) + strlen (user_name) + 2 +
|
2006-09-30 19:38:34 +00:00
|
|
|
MAX (strlen (selection_prefix),
|
|
|
|
|
MAX (strlen (address_prefix),
|
|
|
|
|
strlen (pid_prefix))));
|
|
|
|
|
if (atom_name == NULL)
|
|
|
|
|
{
|
|
|
|
|
verbose ("Could not create X11 atoms; aborting X11 integration.\n");
|
|
|
|
|
free (user_name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create the selection atom */
|
|
|
|
|
strcpy (atom_name, selection_prefix);
|
|
|
|
|
strcat (atom_name, user_name);
|
|
|
|
|
strcat (atom_name, "_");
|
2006-10-01 20:05:39 +00:00
|
|
|
strcat (atom_name, machine);
|
2006-09-30 19:38:34 +00:00
|
|
|
selection_atom = XInternAtom (display, atom_name, FALSE);
|
|
|
|
|
|
|
|
|
|
/* create the address property atom */
|
|
|
|
|
strcpy (atom_name, address_prefix);
|
|
|
|
|
address_atom = XInternAtom (display, atom_name, FALSE);
|
|
|
|
|
|
|
|
|
|
/* create the PID property atom */
|
|
|
|
|
strcpy (atom_name, pid_prefix);
|
|
|
|
|
pid_atom = XInternAtom (display, atom_name, FALSE);
|
|
|
|
|
|
|
|
|
|
free (atom_name);
|
|
|
|
|
free (user_name);
|
|
|
|
|
init = TRUE;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Gets the daemon address from the X11 display.
|
|
|
|
|
* Returns FALSE if there was an error. Returning
|
|
|
|
|
* TRUE does not mean the address exists.
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
x11_get_address (char **paddress, pid_t *pid, long *wid)
|
|
|
|
|
{
|
2010-07-19 11:48:06 +02:00
|
|
|
int result;
|
2006-09-30 19:38:34 +00:00
|
|
|
Atom type;
|
|
|
|
|
Window owner;
|
|
|
|
|
int format;
|
|
|
|
|
unsigned long items;
|
|
|
|
|
unsigned long after;
|
|
|
|
|
char *data;
|
|
|
|
|
|
|
|
|
|
*paddress = NULL;
|
|
|
|
|
|
|
|
|
|
/* locate the selection owner */
|
|
|
|
|
owner = XGetSelectionOwner (xdisplay, selection_atom);
|
|
|
|
|
if (owner == None)
|
|
|
|
|
return TRUE; /* no owner */
|
|
|
|
|
if (wid != NULL)
|
|
|
|
|
*wid = (long) owner;
|
|
|
|
|
|
|
|
|
|
/* get the bus address */
|
2010-07-19 11:48:06 +02:00
|
|
|
result = XGetWindowProperty (xdisplay, owner, address_atom, 0, 1024, False,
|
|
|
|
|
XA_STRING, &type, &format, &items, &after,
|
|
|
|
|
(unsigned char **) &data);
|
|
|
|
|
if (result != Success || type == None || after != 0 || data == NULL || format != 8)
|
2006-09-30 19:38:34 +00:00
|
|
|
return FALSE; /* error */
|
|
|
|
|
|
|
|
|
|
*paddress = xstrdup (data);
|
|
|
|
|
XFree (data);
|
|
|
|
|
|
|
|
|
|
/* get the PID */
|
|
|
|
|
if (pid != NULL)
|
|
|
|
|
{
|
|
|
|
|
*pid = 0;
|
2010-07-19 11:48:06 +02:00
|
|
|
result = XGetWindowProperty (xdisplay, owner, pid_atom, 0, sizeof pid, False,
|
|
|
|
|
XA_CARDINAL, &type, &format, &items, &after,
|
|
|
|
|
(unsigned char **) &data);
|
|
|
|
|
if (result == Success && type != None && after == 0 && data != NULL && format == 32)
|
2006-09-30 19:38:34 +00:00
|
|
|
*pid = (pid_t) *(long*) data;
|
|
|
|
|
XFree (data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE; /* success */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Saves the address in the X11 display. Returns 0 on success.
|
|
|
|
|
* If an error occurs, returns -1. If the selection already exists,
|
|
|
|
|
* returns 1. (i.e. another daemon is already running)
|
|
|
|
|
*/
|
|
|
|
|
static Window
|
|
|
|
|
set_address_in_x11(char *address, pid_t pid)
|
|
|
|
|
{
|
|
|
|
|
char *current_address;
|
2008-03-31 18:16:00 -04:00
|
|
|
Window wid = None;
|
2007-08-17 16:43:57 +00:00
|
|
|
unsigned long pid32; /* Xlib property functions want _long_ not 32-bit for format "32" */
|
2006-10-01 20:05:39 +00:00
|
|
|
|
2006-09-30 19:38:34 +00:00
|
|
|
/* lock the X11 display to make sure we're doing this atomically */
|
|
|
|
|
XGrabServer (xdisplay);
|
|
|
|
|
|
|
|
|
|
if (!x11_get_address (¤t_address, NULL, NULL))
|
|
|
|
|
{
|
|
|
|
|
/* error! */
|
2008-03-31 18:16:00 -04:00
|
|
|
goto out;
|
2006-09-30 19:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (current_address != NULL)
|
|
|
|
|
{
|
|
|
|
|
/* someone saved the address in the meantime */
|
|
|
|
|
free (current_address);
|
2008-03-31 18:16:00 -04:00
|
|
|
goto out;
|
2006-09-30 19:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Create our window */
|
2009-03-20 00:26:42 -04:00
|
|
|
wid = XCreateWindow (xdisplay, RootWindow (xdisplay, 0), -20, -20, 10, 10,
|
|
|
|
|
0, CopyFromParent, InputOnly, CopyFromParent,
|
|
|
|
|
0, NULL);
|
2016-10-07 19:44:11 +01:00
|
|
|
/* The type of a Window varies, so cast it to something reasonable */
|
|
|
|
|
verbose ("Created window %lu\n", (unsigned long) wid);
|
2006-09-30 19:38:34 +00:00
|
|
|
|
|
|
|
|
/* Save the property in the window */
|
|
|
|
|
XChangeProperty (xdisplay, wid, address_atom, XA_STRING, 8, PropModeReplace,
|
|
|
|
|
(unsigned char *)address, strlen (address));
|
2006-10-01 20:05:39 +00:00
|
|
|
pid32 = pid;
|
2006-09-30 19:38:34 +00:00
|
|
|
XChangeProperty (xdisplay, wid, pid_atom, XA_CARDINAL, 32, PropModeReplace,
|
2006-10-01 20:05:39 +00:00
|
|
|
(unsigned char *)&pid32, 1);
|
2006-09-30 19:38:34 +00:00
|
|
|
|
|
|
|
|
/* Now grab the selection */
|
|
|
|
|
XSetSelectionOwner (xdisplay, selection_atom, wid, CurrentTime);
|
|
|
|
|
|
2008-03-31 18:16:00 -04:00
|
|
|
out:
|
2006-09-30 19:38:34 +00:00
|
|
|
/* Ungrab the server to let other people use it too */
|
|
|
|
|
XUngrabServer (xdisplay);
|
|
|
|
|
|
2008-03-31 18:16:00 -04:00
|
|
|
/* And make sure that the ungrab gets sent to X11 */
|
2006-09-30 19:38:34 +00:00
|
|
|
XFlush (xdisplay);
|
|
|
|
|
|
|
|
|
|
return wid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Saves the session address in session file. Returns TRUE on
|
|
|
|
|
* success, FALSE if an error occurs.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
set_address_in_file (char *address, pid_t pid, Window wid)
|
|
|
|
|
{
|
|
|
|
|
char *session_file;
|
|
|
|
|
FILE *f;
|
|
|
|
|
|
2006-10-01 20:05:39 +00:00
|
|
|
ensure_session_directory ();
|
2006-09-30 19:38:34 +00:00
|
|
|
session_file = get_session_file();
|
|
|
|
|
if (session_file == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
f = fopen (session_file, "w");
|
2010-09-23 09:21:25 -07:00
|
|
|
free (session_file);
|
2006-09-30 19:38:34 +00:00
|
|
|
if (f == NULL)
|
|
|
|
|
return FALSE; /* some kind of error */
|
2006-10-01 20:05:39 +00:00
|
|
|
fprintf (f,
|
|
|
|
|
"# This file allows processes on the machine with id %s using \n"
|
|
|
|
|
"# display %s to find the D-Bus session bus with the below address.\n"
|
|
|
|
|
"# If the DBUS_SESSION_BUS_ADDRESS environment variable is set, it will\n"
|
|
|
|
|
"# be used rather than this file.\n"
|
|
|
|
|
"# See \"man dbus-launch\" for more details.\n"
|
2016-03-29 12:15:15 -07:00
|
|
|
"DBUS_SESSION_BUS_ADDRESS='%s'\n"
|
2006-10-01 20:05:39 +00:00
|
|
|
"DBUS_SESSION_BUS_PID=%ld\n"
|
|
|
|
|
"DBUS_SESSION_BUS_WINDOWID=%ld\n",
|
|
|
|
|
get_machine_uuid (),
|
|
|
|
|
getenv ("DISPLAY"),
|
|
|
|
|
address, (long)pid, (long)wid);
|
2006-09-30 19:38:34 +00:00
|
|
|
|
|
|
|
|
fclose (f);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
x11_save_address (char *address, pid_t pid, long *wid)
|
|
|
|
|
{
|
|
|
|
|
Window id = set_address_in_x11 (address, pid);
|
|
|
|
|
if (id != None)
|
|
|
|
|
{
|
|
|
|
|
if (!set_address_in_file (address, pid, id))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (wid != NULL)
|
|
|
|
|
*wid = (long) id;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
x11_init (void)
|
|
|
|
|
{
|
|
|
|
|
return open_x11 () != NULL && init_x_atoms (xdisplay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
x11_handle_event (void)
|
|
|
|
|
{
|
|
|
|
|
if (xdisplay != NULL)
|
|
|
|
|
{
|
|
|
|
|
while (XPending (xdisplay))
|
|
|
|
|
{
|
|
|
|
|
XEvent ignored;
|
|
|
|
|
XNextEvent (xdisplay, &ignored);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
2010-02-26 08:37:53 +01:00
|
|
|
void dummy_dbus_launch_x11 (void);
|
|
|
|
|
|
2006-09-30 19:38:34 +00:00
|
|
|
void dummy_dbus_launch_x11 (void) { }
|
|
|
|
|
#endif
|