<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, May 1, 2014 at 9:00 AM, Andrew Wedgbury <span dir="ltr"><<a href="mailto:andrew.wedgbury@realvnc.com" target="_blank">andrew.wedgbury@realvnc.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Currently the screen-share module uses a hard-coded command to start the<br>
fullscreen shell server. This patch causes the module to read the command from<br>
the weston config file (from the "command" key in the "screen-share" section).<br>
The default value remains the same (i.e. to run weston with the RDP backend and<br>
fullscreen shell), but is now located in the weston config file.<br>
<br>
As well as allowing the arguments to the fullscreen shell server to be changed,<br>
this also permits an alternative fullscreen shell server to be used if required,<br>
without needing to recompile. Since the command is run as the user running<br>
weston, this should not pose any additional security risk.<br>
<br>
---<br>
 src/screen-share.c | 62 ++++++++++++++++++++++++++++++++++++++++++------------<br>
 <a href="http://weston.ini.in" target="_blank">weston.ini.in</a>      |  3 +++<br>
 2 files changed, 51 insertions(+), 14 deletions(-)<br>
<br>
diff --git a/src/screen-share.c b/src/screen-share.c<br>
index 6f60b81..6e9a14f 100644<br>
--- a/src/screen-share.c<br>
+++ b/src/screen-share.c<br>
@@ -32,6 +32,7 @@<br>
 #include <signal.h><br>
 #include <linux/input.h><br>
 #include <errno.h><br>
+#include <ctype.h><br>
<br>
 #include <wayland-client.h><br>
<br>
@@ -101,6 +102,11 @@ struct ss_shm_buffer {<br>
        pixman_image_t *pm_image;<br>
 };<br>
<br>
+struct screen_share {<br>
+       struct weston_compositor *compositor;<br>
+       char *command;<br>
+};<br>
+<br>
 static void<br>
 ss_seat_handle_pointer_enter(void *data, struct wl_pointer *pointer,<br>
                             uint32_t serial, struct wl_surface *surface,<br>
@@ -982,13 +988,15 @@ shared_output_destroy(struct shared_output *so)<br>
 }<br>
<br>
 static struct shared_output *<br>
-weston_output_share(struct weston_output *output,<br>
-                   const char *path, char *const argv[])<br>
+weston_output_share(struct weston_output *output, const char* command)<br>
 {<br>
        int sv[2];<br>
        char str[32];<br>
        pid_t pid;<br>
        sigset_t allsigs;<br>
+       struct wl_array args;<br>
+       char **argv;<br>
+       char *start, *p, **ps;<br>
<br>
        if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) {<br>
                weston_log("weston_output_share: socketpair failed: %m\n");<br>
@@ -1025,7 +1033,28 @@ weston_output_share(struct weston_output *output,<br>
                snprintf(str, sizeof str, "%d", sv[1]);<br>
                setenv("WAYLAND_SERVER_SOCKET", str, 1);<br>
<br>
-               execv(path, argv);<br>
+               wl_array_init(&args);<br>
+               start = zalloc(strlen(command)+1);<br>
+               if (start == 0)<br>
+                       return NULL;<br>
+               strcpy(start, command);<br>
+               while (*start) {<br>
+                       for (p = start; *p && !isspace(*p); p++)<br>
+                               ;<br>
+<br>
+                       ps = wl_array_add(&args, sizeof *ps);<br>
+                       *ps = start;<br>
+<br>
+                       while (*p && isspace(*p))<br>
+                               *p++ = '\0';<br>
+<br>
+                       start = p;<br>
+               }<br>
+               ps = wl_array_add(&args, sizeof *ps);<br>
+               *ps = NULL;<br>
+<br>
+               argv = args.data;<br>
+               execv(argv[0], argv);<br>
                weston_log("weston_output_share: exec failed: %m\n");<br>
                abort();<br>
        } else {<br>
@@ -1056,7 +1085,7 @@ share_output_binding(struct weston_seat *seat, uint32_t time, uint32_t key,<br>
                     void *data)<br>
 {<br>
        struct weston_output *output;<br>
-       const char *path = BINDIR "/weston";<br>
+       struct screen_share *ss = data;<br>
<br>
        if (!seat->pointer) {<br>
                weston_log("Cannot pick output: Seat does not have pointer\n");<br>
@@ -1071,23 +1100,28 @@ share_output_binding(struct weston_seat *seat, uint32_t time, uint32_t key,<br>
                return;<br>
        }<br>
<br>
-       char *const argv[] = {<br>
-               "weston",<br>
-               "--backend=rdp-backend.so",<br>
-               "--shell=fullscreen-shell.so",<br>
-               "--no-clients-resize",<br>
-               NULL<br>
-       };<br>
-<br>
-       weston_output_share(output, path, argv);<br>
+       weston_output_share(output, ss->command);<br></blockquote><div><br></div><div>Why are we doing our own command parsing?  Why not just run "sh -c command" instead of doing our own command-line parsing?  Then we could just do:<br>
<br>       char *const argv[] = {<br></div><div>
               "/bin/sh",<br></div><div>
               "-c",<br>
               command,<br>
               NULL<br>
       };<br></div><div><br></div><div> It's much simpler and would allow for proper quoting etc.  Is there a good reason why we shouldn't do this?<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

 }<br>
<br>
 WL_EXPORT int<br>
 module_init(struct weston_compositor *compositor,<br>
            int *argc, char *argv[])<br>
 {<br>
+       struct screen_share *ss;<br>
+       struct weston_config_section *section;<br>
+<br>
+       ss = zalloc(sizeof *ss);<br>
+       if (ss == NULL)<br>
+               return -1;<br>
+       ss->compositor = compositor;<br>
+<br>
+       section = weston_config_get_section(compositor->config, "screen-share",<br>
+                                           NULL, NULL);<br>
+<br>
+       weston_config_section_get_string(section, "command", &ss->command, "");<br></blockquote><div><br></div><div>Do we want an actual default here rather than just putting something in the default config file?<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
        weston_compositor_add_key_binding(compositor, KEY_S,<br>
                                          MODIFIER_CTRL | MODIFIER_ALT,<br>
-                                         share_output_binding, compositor);<br>
+                                         share_output_binding, ss);<br>
        return 0;<br>
 }<br>
diff --git a/<a href="http://weston.ini.in" target="_blank">weston.ini.in</a> b/<a href="http://weston.ini.in" target="_blank">weston.ini.in</a><br>
index 2c39177..1f216a7 100644<br>
--- a/<a href="http://weston.ini.in" target="_blank">weston.ini.in</a><br>
+++ b/<a href="http://weston.ini.in" target="_blank">weston.ini.in</a><br>
@@ -65,3 +65,6 @@ path=@libexecdir@/weston-keyboard<br>
 #constant_accel_factor = 50<br>
 #min_accel_factor = 0.16<br>
 #max_accel_factor = 1.0<br>
+<br>
+[screen-share]<br>
+command=@bindir@/weston --backend=rdp-backend.so --shell=fullscreen-shell.so --no-clients-resize<br>
<span class=""><font color="#888888">--<br>
1.9.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>
</font></span></blockquote></div><br></div></div>