X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tools%2Fdbus-launch-x11.c;h=c7e33309bac742b8656d79b5175ea5f2ab8a02b7;hb=afe93187e46fc062dc05b08a56975e8dc7884919;hp=b7d1c20855ee9e0d2a1ef4d20792c6837d2153a2;hpb=01b91ba121034f94c1e4d4511b9e61f622dde48c;p=platform%2Fupstream%2Fdbus.git diff --git a/tools/dbus-launch-x11.c b/tools/dbus-launch-x11.c index b7d1c20..c7e3330 100644 --- a/tools/dbus-launch-x11.c +++ b/tools/dbus-launch-x11.c @@ -1,4 +1,4 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ /* dbus-launch.h dbus-launch utility * * Copyright (C) 2006 Thiago Macieira @@ -17,9 +17,11 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ + +#include #include "dbus-launch.h" #ifdef DBUS_BUILD_X11 @@ -246,7 +248,7 @@ init_x_atoms (Display *display) user = getpwuid (getuid ()); if (user == NULL) { - verbose ("Could not determine the user informations; aborting X11 integration.\n"); + verbose ("Could not determine user information; aborting X11 integration.\n"); return FALSE; } user_name = xstrdup(user->pw_name); @@ -291,6 +293,7 @@ init_x_atoms (Display *display) int x11_get_address (char **paddress, pid_t *pid, long *wid) { + int result; Atom type; Window owner; int format; @@ -308,10 +311,10 @@ x11_get_address (char **paddress, pid_t *pid, long *wid) *wid = (long) owner; /* get the bus address */ - XGetWindowProperty (xdisplay, owner, address_atom, 0, 1024, False, - XA_STRING, &type, &format, &items, &after, - (unsigned char **) &data); - if (type == None || after != 0 || data == NULL || format != 8) + 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) return FALSE; /* error */ *paddress = xstrdup (data); @@ -321,10 +324,10 @@ x11_get_address (char **paddress, pid_t *pid, long *wid) if (pid != NULL) { *pid = 0; - XGetWindowProperty (xdisplay, owner, pid_atom, 0, sizeof pid, False, - XA_CARDINAL, &type, &format, &items, &after, - (unsigned char **) &data); - if (type != None && after == 0 && data != NULL && format == 32) + 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) *pid = (pid_t) *(long*) data; XFree (data); } @@ -341,8 +344,8 @@ static Window set_address_in_x11(char *address, pid_t pid) { char *current_address; - Window wid; - int pid32; + Window wid = None; + unsigned long pid32; /* Xlib property functions want _long_ not 32-bit for format "32" */ /* lock the X11 display to make sure we're doing this atomically */ XGrabServer (xdisplay); @@ -350,42 +353,37 @@ set_address_in_x11(char *address, pid_t pid) if (!x11_get_address (¤t_address, NULL, NULL)) { /* error! */ - XUngrabServer (xdisplay); - return None; + goto out; } if (current_address != NULL) { /* someone saved the address in the meantime */ - XUngrabServer (xdisplay); free (current_address); - return None; + goto out; } /* Create our window */ - wid = XCreateSimpleWindow (xdisplay, RootWindow (xdisplay, 0), -20, -20, 10, 10, - 0, WhitePixel (xdisplay, 0), - BlackPixel (xdisplay, 0)); + wid = XCreateWindow (xdisplay, RootWindow (xdisplay, 0), -20, -20, 10, 10, + 0, CopyFromParent, InputOnly, CopyFromParent, + 0, NULL); verbose ("Created window %d\n", wid); /* Save the property in the window */ XChangeProperty (xdisplay, wid, address_atom, XA_STRING, 8, PropModeReplace, (unsigned char *)address, strlen (address)); pid32 = pid; - if (sizeof(pid32) != 4) - { - fprintf (stderr, "int is not 32 bits!\n"); - exit (1); - } XChangeProperty (xdisplay, wid, pid_atom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&pid32, 1); /* Now grab the selection */ XSetSelectionOwner (xdisplay, selection_atom, wid, CurrentTime); + out: /* Ungrab the server to let other people use it too */ XUngrabServer (xdisplay); + /* And make sure that the ungrab gets sent to X11 */ XFlush (xdisplay); return wid; @@ -407,6 +405,7 @@ set_address_in_file (char *address, pid_t pid, Window wid) return FALSE; f = fopen (session_file, "w"); + free (session_file); if (f == NULL) return FALSE; /* some kind of error */ fprintf (f, @@ -423,7 +422,6 @@ set_address_in_file (char *address, pid_t pid, Window wid) address, (long)pid, (long)wid); fclose (f); - free (session_file); return TRUE; } @@ -464,5 +462,7 @@ x11_handle_event (void) } #else +void dummy_dbus_launch_x11 (void); + void dummy_dbus_launch_x11 (void) { } #endif