<div dir="ltr"><div>The only existing use I see for the PID is for killing the client.<br><br></div>I'd also argue that using the PID for application tracking is bound to go awry for a variety of reasons, and you should use WM_CLASS or _GTK_APPLICATION_ID for more complete tracking.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 27, 2015 at 12:29 PM, Giulio Camuffo <span dir="ltr"><<a href="mailto:giuliocamuffo@gmail.com" target="_blank">giuliocamuffo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">2015-01-27 19:23 GMT+02:00 Jasper St. Pierre <<a href="mailto:jstpierre@mecheye.net">jstpierre@mecheye.net</a>>:<br>
> Are you still not using XKillClient for some reason?<br>
<br>
</span>This patch is not about killing X clients, it's about passing the pid<br>
to the shell, so not sure what relevance it has.<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> On Tue, Jan 27, 2015 at 12:10 PM, Giulio Camuffo <<a href="mailto:giuliocamuffo@gmail.com">giuliocamuffo@gmail.com</a>><br>
> wrote:<br>
>><br>
>> All the surfaces from all the X clients share the same wl_client so<br>
>> wl_client_get_credentials can't be used to get the pid of the X<br>
>> clients.<br>
>> The shell may need to know the pid to be able to associate a surface<br>
>> with e.g. a DBus service.<br>
>> ---<br>
>><br>
>> v5: added the check on the hostname<br>
>><br>
>> desktop-shell/shell.c | 7 +++++++<br>
>> src/compositor.h | 1 +<br>
>> xwayland/window-manager.c | 30 ++++++++++++++++++++++--------<br>
>> 3 files changed, 30 insertions(+), 8 deletions(-)<br>
>><br>
>> diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c<br>
>> index a7514f7..6bb9af8 100644<br>
>> --- a/desktop-shell/shell.c<br>
>> +++ b/desktop-shell/shell.c<br>
>> @@ -2248,6 +2248,12 @@ set_title(struct shell_surface *shsurf, const char<br>
>> *title)<br>
>> }<br>
>><br>
>> static void<br>
>> +set_pid(struct shell_surface *shsurf, pid_t pid)<br>
>> +{<br>
>> + /* We have no use for it */<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> set_type(struct shell_surface *shsurf, enum shell_surface_type t)<br>
>> {<br>
>> shsurf->type = t;<br>
>> @@ -6624,6 +6630,7 @@ module_init(struct weston_compositor *ec,<br>
>> ec->shell_interface.resize = surface_resize;<br>
>> ec->shell_interface.set_title = set_title;<br>
>> ec->shell_interface.set_window_geometry = set_window_geometry;<br>
>> + ec->shell_interface.set_pid = set_pid;<br>
>><br>
>> weston_layer_init(&shell->fullscreen_layer,<br>
>> &ec->cursor_layer.link);<br>
>> weston_layer_init(&shell->panel_layer,<br>
>> &shell->fullscreen_layer.link);<br>
>> diff --git a/src/compositor.h b/src/compositor.h<br>
>> index aa87ec0..0223f41 100644<br>
>> --- a/src/compositor.h<br>
>> +++ b/src/compositor.h<br>
>> @@ -121,6 +121,7 @@ struct weston_shell_interface {<br>
>> void (*set_window_geometry)(struct shell_surface *shsurf,<br>
>> int32_t x, int32_t y,<br>
>> int32_t width, int32_t height);<br>
>> + void (*set_pid)(struct shell_surface *shsurf, pid_t pid);<br>
>> };<br>
>><br>
>> struct weston_animation {<br>
>> diff --git a/xwayland/window-manager.c b/xwayland/window-manager.c<br>
>> index 6f1996f..c966fd5 100644<br>
>> --- a/xwayland/window-manager.c<br>
>> +++ b/xwayland/window-manager.c<br>
>> @@ -401,6 +401,7 @@ weston_wm_window_read_properties(struct<br>
>> weston_wm_window *window)<br>
>> uint32_t *xid;<br>
>> xcb_atom_t *atom;<br>
>> uint32_t i;<br>
>> + char name[1024];<br>
>><br>
>> if (!window->properties_dirty)<br>
>> return;<br>
>> @@ -487,10 +488,28 @@ weston_wm_window_read_properties(struct<br>
>> weston_wm_window *window)<br>
>> free(reply);<br>
>> }<br>
>><br>
>> + if (window->pid > 0) {<br>
>> + gethostname(name, sizeof(name));<br>
>> + for (i = 0; i < sizeof(name); i++) {<br>
>> + if (name[i] == '\0')<br>
>> + break;<br>
>> + }<br>
>> + if (i == sizeof(name))<br>
>> + name[0] = '\0'; /* ignore stupid hostnames */<br>
>> +<br>
>> + /* this is only one heuristic to guess the PID of a client<br>
>> is<br>
>> + * valid, assuming it's compliant with icccm and ewmh.<br>
>> + * Non-compliants and remote applications of course fail.<br>
>> */<br>
>> + if (!window->machine || strcmp(window->machine, name))<br>
>> + window->pid = 0;<br>
>> + }<br>
>> +<br>
>> if (window->shsurf && window->name)<br>
>> shell_interface->set_title(window->shsurf, window->name);<br>
>> if (window->frame && window->name)<br>
>> frame_set_title(window->frame, window->name);<br>
>> + if (window->shsurf && window->pid > 0)<br>
>> + shell_interface->set_pid(window->shsurf, window->pid);<br>
>> }<br>
>><br>
>> static void<br>
>> @@ -651,17 +670,10 @@ weston_wm_kill_client(struct wl_listener *listener,<br>
>> void *data)<br>
>> {<br>
>> struct weston_surface *surface = data;<br>
>> struct weston_wm_window *window = get_wm_window(surface);<br>
>> - char name[1024];<br>
>> -<br>
>> if (!window)<br>
>> return;<br>
>><br>
>> - gethostname(name, 1024);<br>
>> -<br>
>> - /* this is only one heuristic to guess the PID of a client is<br>
>> valid,<br>
>> - * assuming it's compliant with icccm and ewmh. Non-compliants and<br>
>> - * remote applications of course fail. */<br>
>> - if (!strcmp(window->machine, name) && window->pid != 0)<br>
>> + if (window->pid > 0)<br>
>> kill(window->pid, SIGKILL);<br>
>> }<br>
>><br>
>> @@ -2333,6 +2345,8 @@ xserver_map_shell_surface(struct weston_wm_window<br>
>> *window,<br>
>><br>
>> if (window->name)<br>
>> shell_interface->set_title(window->shsurf, window->name);<br>
>> + if (window->pid > 0)<br>
>> + shell_interface->set_pid(window->shsurf, window->pid);<br>
>><br>
>> if (window->fullscreen) {<br>
>> window->saved_width = window->width;<br>
>> --<br>
>> 2.2.2<br>
>><br>
>> _______________________________________________<br>
>> wayland-devel mailing list<br>
>> <a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
>> <a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
><br>
><br>
><br>
><br>
> --<br>
> Jasper<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"> Jasper<br></div>
</div>