summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2013-09-02 21:41:48 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2013-09-02 21:42:50 +0100
commitd2f7f85cd20fb3a2bb3dba8c9be7ff21d2a8c049 (patch)
tree29220306cdab7a1830734b67904d52411c99422c /tools
parent5fed6e24996eb0fcfeec19341ce4103e7e7eb2d8 (diff)
intel-virtual-overlay: Fix the bumblebee query parsing
It supplies both a trailing newline, NUL byte and length. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'tools')
-rw-r--r--tools/virtual.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/tools/virtual.c b/tools/virtual.c
index 27d80e85..64b869c8 100644
--- a/tools/virtual.c
+++ b/tools/virtual.c
@@ -1658,33 +1658,45 @@ static int bumblebee_open(struct context *ctx)
struct sockaddr_un addr;
int fd, len;
- fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
- if (fd < 0)
+ fd = socket(PF_UNIX, SOCK_STREAM, 0);
+ if (fd < 0) {
+ DBG(("%s unable to create a socket: %d\n", __func__, errno));
return -ECONNREFUSED;
+ }
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, optarg && *optarg ? optarg : "/var/run/bumblebee.socket");
- if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
+ if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ DBG(("%s unable to create a socket: %d\n", __func__, errno));
goto err;
+ }
/* Ask bumblebee to start the second server */
buf[0] = 'C';
- if (send(fd, &buf, 1, 0) != 1 || (len = recv(fd, &buf, 255, 0)) <= 0)
+ if (send(fd, &buf, 1, 0) != 1 || (len = recv(fd, &buf, 255, 0)) <= 0) {
+ DBG(("%s startup send/recv failed: %d\n", __func__, errno));
goto err;
+ }
buf[len] = '\0';
/* Query the display name */
strcpy(buf, "Q VirtualDisplay");
- if (send(fd, buf, 17, 0) != 17 || (len = recv(fd, buf, 255, 0)) <= 0)
+ if (send(fd, buf, 17, 0) != 17 || (len = recv(fd, buf, 255, 0)) <= 0) {
+ DBG(("%s query send/recv failed: %d\n", __func__, errno));
goto err;
+ }
buf[len] = '\0';
close(fd);
+ DBG(("%s query result '%s'\n", __func__, buf));
+
if (strncmp(buf, "Value: ", 7))
return -ECONNREFUSED;
- while (isspace(buf[--len]))
- buf[len] = '\0';
+ len = 7;
+ while (buf[len] != '\n' && buf[len] != '\0')
+ len++;
+ buf[len] = '\0';
return display_open(ctx, buf+7);