[PATCH NOTFINISHED 1/4] compositor: take argument for opening xserver display connection

Tiago Vignatti tiago.vignatti at intel.com
Wed Aug 3 02:12:30 PDT 2011


Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>
---

Oh boy... I tried for about half-hour to make getopt_long work properly for my
desires. I wanted to set 'x' as an optional argument for the compositor, so
whenever it is called it takes another argument (the X server display
connection) as optional. For example, calling "wayland-compositor",
"wayland-compositor -x" or "wayland-compositor -x 2" should all work. For that,
man pagetells me that I have to insert two colons (::) after 'x' in the
optstring (opts). I tried for awhile but I failed. I guess I'm missing a
very basic understanding here of getopt_long usage that my tiredness/dumbness
is not helping :/

I hope someone could give a help. Thanks!


 compositor/compositor.c       |   14 ++++++++++----
 compositor/compositor.h       |    2 +-
 compositor/xserver-launcher.c |    4 ++--
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/compositor/compositor.c b/compositor/compositor.c
index 177de54..a92e806 100644
--- a/compositor/compositor.c
+++ b/compositor/compositor.c
@@ -2008,7 +2008,7 @@ int main(int argc, char *argv[])
 	char *shell = NULL;
 	char *p;
 
-	static const char opts[] = "B:b:o:S:i:s:x";
+	static const char opts[] = "B:b:o:S:i:s:x:";
 	static const struct option longopts[ ] = {
 		{ "backend", 1, NULL, 'B' },
 		{ "backend-options", 1, NULL, 'o' },
@@ -2016,7 +2016,7 @@ int main(int argc, char *argv[])
 		{ "socket", 1, NULL, 'S' },
 		{ "idle-time", 1, NULL, 'i' },
 		{ "shell", 1, NULL, 's' },
-		{ "xserver", 0, NULL, 'x' },
+		{ "xserver", 2, 0, 'w' },
 		{ NULL, }
 	};
 
@@ -2047,7 +2047,13 @@ int main(int argc, char *argv[])
 			shell = optarg;
 			break;
 		case 'x':
-			xserver = 1;
+			xserver = strtol(optarg, &p, 0);
+			if (*p != '\0') {
+				fprintf(stderr,
+					"invalid xserver connection: %s\n",
+					optarg);
+				exit(EXIT_FAILURE);
+			}
 			break;
 		}
 	}
@@ -2088,7 +2094,7 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 
 	if (xserver)
-		wlsc_xserver_init(ec);
+		wlsc_xserver_init(ec, xserver);
 
 	if (wl_display_add_socket(display, option_socket_name)) {
 		fprintf(stderr, "failed to add socket: %m\n");
diff --git a/compositor/compositor.h b/compositor/compositor.h
index ea6e9e7..fce3693 100644
--- a/compositor/compositor.h
+++ b/compositor/compositor.h
@@ -399,7 +399,7 @@ void
 wlsc_watch_process(struct wlsc_process *process);
 
 int
-wlsc_xserver_init(struct wlsc_compositor *compositor);
+wlsc_xserver_init(struct wlsc_compositor *compositor, int server_display);
 void
 wlsc_xserver_destroy(struct wlsc_compositor *compositor);
 
diff --git a/compositor/xserver-launcher.c b/compositor/xserver-launcher.c
index f39c38d..b01619b 100644
--- a/compositor/xserver-launcher.c
+++ b/compositor/xserver-launcher.c
@@ -575,7 +575,7 @@ static const struct xserver_interface xserver_implementation = {
 };
 
 int
-wlsc_xserver_init(struct wlsc_compositor *compositor)
+wlsc_xserver_init(struct wlsc_compositor *compositor, int server_display)
 {
 	struct wl_display *display = compositor->wl_display;
 	struct wlsc_xserver *mxs;
@@ -596,7 +596,7 @@ wlsc_xserver_init(struct wlsc_compositor *compositor)
 		return -1;
 	}
 
-	mxs->display = 0;
+	mxs->display = server_display;
 	do {
 		snprintf(lockfile, sizeof lockfile,
 			 "/tmp/.X%d-lock", mxs->display);
-- 
1.7.2.2



More information about the wayland-devel mailing list