summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2018-03-01 15:17:49 -0800
committerKeith Packard <keithp@keithp.com>2018-03-01 15:17:49 -0800
commitb70915413d86d7ce37a9f90af942c86e269d7872 (patch)
tree8db1084ea3c788c5bf26706c0635002d08ad3e64
parentd08a95cbbeb909db3637fe0cfaa70d54fa8ed218 (diff)
Switch to using command line to pass master fd. Add manual.
The X server now accepts '-masterfd' as the way to pass the master file descriptor to the X server. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--Makefile.am3
-rw-r--r--xlease.183
-rw-r--r--xlease.c38
3 files changed, 111 insertions, 13 deletions
diff --git a/Makefile.am b/Makefile.am
index 697f89c..062a916 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -22,6 +22,9 @@
bin_PROGRAMS = xlease
+appmandir=$(APP_MAN_DIR)
+appman_DATA=xlease.1
+
AM_CFLAGS = $(XLEASE_CFLAGS)
xlease_LDADD = $(XLEASE_LIBS)
diff --git a/xlease.1 b/xlease.1
new file mode 100644
index 0000000..724a9a4
--- /dev/null
+++ b/xlease.1
@@ -0,0 +1,83 @@
+.\"
+.\" Copyright © 2018 Keith Packard
+.\"
+.\" Permission to use, copy, modify, distribute, and sell this software and its
+.\" documentation for any purpose is hereby granted without fee, provided that
+.\" the above copyright notice appear in all copies and that both that copyright
+.\" notice and this permission notice appear in supporting documentation, and
+.\" that the name of the copyright holders not be used in advertising or
+.\" publicity pertaining to distribution of the software without specific,
+.\" written prior permission. The copyright holders make no representations
+.\" about the suitability of this software for any purpose. It is provided "as
+.\" is" without express or implied warranty.
+.\"
+.\" THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+.\" INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+.\" EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+.\" CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+.\" DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+.\" TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+.\" OF THIS SOFTWARE.
+.\"
+.TH XLEASE 1 "xlease 0.1" "X Version 11"
+.SH NAME
+xlease \- lease an X output for another DRM application
+.SH SYNOPSIS
+.B "xlease"
+.RI [\-\-help] [\-\-verbose]
+.RI [\-\-output \fIoutput\fP]
+.RI [\-\-display \fIdisplay\fP]
+.RI [\-\-fd_arg \fIname\fP]
+.IR <command> <arg> ...
+.SH DESCRIPTION
+.I Xlease
+is used to borrow a set of DRM resources from the X server and hand
+them to another application (potentially another X server) for
+independent use. The resources are leased from the X server DRM master
+and attached to a new DRM master associated with a file
+descriptor. That file descriptor is passed on the command line to the
+application which can then perform KMS operations on the descriptor to
+configure it for display.
+.IP \-\-help
+Print out a usage summary and exit.
+.IP \-\-verbose
+Increase the verbosity of the application, printing out various
+progress messages and other information.
+.IP "\-\-output \fIoutput\fP"
+Borrow the specified output for use. This option is required.
+.IP "\-\-display \fIdisplay\fP"
+Connect to the specified X server.
+.IP "\-\-fd-arg \fIargument-name\fP"
+.I Xlease
+passes the DRM master file descriptor on the command line to the
+application. This option allows the configuration of the flag for that
+value, by default it is “-masterfd”.
+.IP "<command> <arg> ..."
+This specifies the program to be run. By default, this is “X -seat
+seat1 :1”. The fd-arg parameter is added to this, and then the file
+descriptor in decimal, so if no parameters are provided to
+.I xlease
+then the command that will be run is
+.RS
+X -seat seat1 :1 -masterfd 4
+.RE
+.PP
+For this to be able to open suitable input devices, they must first be
+assigned to the specified seat, perhaps by using loginctl, and the
+devices must be accessible by the user running the application.
+.SH EXAMPLES
+Starts another X server on connection :1 for seat 1 using output HDMI-2
+.RS
+xlease --output HDMI-2
+.RE
+.PP
+More verbose example that does exactly the same, just with all
+parameters specified on the command line:
+.RS
+xlease --display :0 --output HDMI-2 -fd-arg -master-fd -- X -seat
+seat1 :1
+.SH "SEE ALSO"
+Xrandr(1), X(1)
+.SH AUTHORS
+Keith Packard,
+keithp@keithp.com
diff --git a/xlease.c b/xlease.c
index 79c48ec..ddaf349 100644
--- a/xlease.c
+++ b/xlease.c
@@ -34,10 +34,13 @@
char *default_x_server[] = {
"X",
+ "-seat",
+ "seat1",
+ ":1",
NULL
};
-#define DEFAULT_ENV "XF86_VIDEO_MODESETTING_FD"
+#define DEFAULT_FD_ARG "-masterfd"
/* Lease an output from X and start an X server running on it */
@@ -58,7 +61,7 @@ typedef struct {
char *display;
char *output_name;
char **xserver;
- char *env;
+ char *fd_arg;
char *shell;
int verbose;
xcb_connection_t *conn;
@@ -312,17 +315,17 @@ app_fini(app_t *app)
}
static const struct option options[] = {
- { .name = "output", .has_arg = 1, .val = 'o' },
{ .name = "display", .has_arg = 1, .val = 'd' },
+ { .name = "output", .has_arg = 1, .val = 'o' },
+ { .name = "fd-arg", .has_arg = 1, .val = 'f' },
{ .name = "help", .has_arg = 0, .val = '?' },
{ .name = "verbose", .has_arg = 0, .val = 'v' },
- { .name = "env", .has_arg = 1, .val = 'e' },
{ 0 },
};
static void usage(char *program, int code)
{
- fprintf(stderr, "usage: %s [--display=<display>] [--output=<output>] [--env=<name>] [--verbose] [--help] {X server ...}\n", program);
+ fprintf(stderr, "usage: %s [--display=<display>] [--output=<output>] [--fd-arg=<--name>] [--verbose] [--help] {command args ...}\n", program);
exit(code);
}
@@ -334,9 +337,9 @@ int main (int argc, char **argv)
init_app(&app);
app.xserver = default_x_server;
- app.env = DEFAULT_ENV;
+ app.fd_arg = DEFAULT_FD_ARG;
- while ((c = getopt_long(argc, argv, "?vo:d:x:s:", options, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "?vo:d:f:", options, NULL)) != -1) {
switch (c) {
case 'v':
app.verbose++;
@@ -347,8 +350,8 @@ int main (int argc, char **argv)
case 'o':
app.output_name = optarg;
break;
- case 'e':
- app.env = optarg;
+ case 'f':
+ app.fd_arg = optarg;
break;
case '?':
usage(argv[0], 0);
@@ -420,13 +423,22 @@ int main (int argc, char **argv)
exit(1);
}
- if (setenv(app.env, fd_string, 1) < 0) {
- perror("setenv");
+ int xserver_argc = 0;
+ for (xserver_argc = 0; app.xserver[xserver_argc]; xserver_argc++);
+
+ char **xserver = calloc((xserver_argc + 5), sizeof (char *));
+ if (!xserver) {
+ perror("calloc");
exit(1);
}
- if (execvp(app.xserver[0], app.xserver)) {
- perror(app.xserver[0]);
+ memcpy(xserver, app.xserver, xserver_argc * sizeof (char *));
+ xserver[xserver_argc++] = app.fd_arg;
+ xserver[xserver_argc++] = fd_string;
+ xserver[xserver_argc++] = NULL;
+
+ if (execvp(xserver[0], xserver)) {
+ perror(xserver[0]);
exit(1);
}