[PATCH weston v4] xwm: tell the shell the pid of the X clients

Daniel Stone daniel at fooishbar.org
Tue Jan 27 06:52:33 PST 2015


Hi,

On 12 January 2015 at 17:04, Giulio Camuffo <giuliocamuffo at gmail.com> wrote:
> diff --git a/xwayland/window-manager.c b/xwayland/window-manager.c
> index f362eac..748c896 100644
> --- a/xwayland/window-manager.c
> +++ b/xwayland/window-manager.c
> @@ -401,6 +401,7 @@ weston_wm_window_read_properties(struct weston_wm_window *window)
>         uint32_t *xid;
>         xcb_atom_t *atom;
>         uint32_t i;
> +       char name[1024];
>
>         if (!window->properties_dirty)
>                 return;
> @@ -487,10 +488,19 @@ weston_wm_window_read_properties(struct weston_wm_window *window)
>                 free(reply);
>         }
>
> +       gethostname(name, 1024);

The last sentence of this is important:
       gethostname() returns the null-terminated hostname in the
character array name, which has a
       length of len bytes.  If the null-terminated hostname is too
large to fit, then the name is
       truncated,  and no error is returned (but see NOTES below).
POSIX.1-2001 says that if such
       truncation occurs, then it is unspecified whether the returned
buffer includes a terminating
       null byte.

I think the best thing to do here would be:
  for (i = 0; i < sizeof(name); i++) {
      if (name[i] == '\0')
          break;
  }
  if (i == sizeof(name))
      name[0] = '\0'; /* ignore stupid hostnames */

Cheers,
Daniel


More information about the wayland-devel mailing list