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>
This commit is contained in:
Chris Wilson 2013-09-02 21:41:48 +01:00
parent 5fed6e2499
commit d2f7f85cd2
1 changed files with 19 additions and 7 deletions

View File

@ -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);