Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/167'
Browse files Browse the repository at this point in the history
* origin/pr/167:
  Remove redundant log line
  Make stderr line-buffered for logging
  daemon: attempt starting target vm only if not running yet
  • Loading branch information
marmarek committed Jun 27, 2024
2 parents 7a2155d + c87b9e7 commit 3b7ab0c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
17 changes: 13 additions & 4 deletions daemon/qrexec-daemon-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ bool qrexec_execute_vm(const char *target, bool autostart, int remote_domain_id,
return false;
}
}
if (autostart) {
int s = disposable ? -2 : connect_unix_socket(target);
if (s == -2 && autostart) {
buf = qubesd_call(target, "admin.vm.Start", "", &resp_len);
if (buf == NULL) // error already printed by qubesd_call
return false;
Expand All @@ -150,9 +151,9 @@ bool qrexec_execute_vm(const char *target, bool autostart, int remote_domain_id,
return false;
}
free(buf);
s = connect_unix_socket(target);
}
int s = connect_unix_socket(target);
if (s == -1)
if (s < 0)
goto kill;
int data_domain;
int data_port;
Expand Down Expand Up @@ -199,6 +200,11 @@ int connect_unix_socket_by_id(unsigned int domid)
return connect_unix_socket(id_str);
}

/* Returns:
* - FD on success,
* - -2 target qrexec daemon is not running,
* - -1 on other errors
*/
int connect_unix_socket(const char *domname)
{
int s, len, res;
Expand All @@ -217,12 +223,15 @@ int connect_unix_socket(const char *domname)
if (res >= (int)sizeof(remote.sun_path)) {
LOG(ERROR, "%s/qrexec.%s is too long for AF_UNIX socket path",
socket_dir, domname);
close(s);
return -1;
}
len = (size_t)res + 1 + offsetof(struct sockaddr_un, sun_path);
if (connect(s, (struct sockaddr *) &remote, len) == -1) {
int saved_errno = errno;
LOG(ERROR, "connect %s", remote.sun_path);
return -1;
close(s);
return (saved_errno == ENOENT || saved_errno == ECONNREFUSED) ? -2 : -1;
}
if (handle_daemon_handshake(s) < 0)
return -1;
Expand Down
1 change: 0 additions & 1 deletion libqrexec/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,6 @@ static int qubes_tcp_connect(const char *host, const char *port)
close(sockfd);
} else {
rc = sockfd;
LOG(DEBUG, "Connection succeeded");
}
freeaddrs:
freeaddrinfo(addrs);
Expand Down
5 changes: 5 additions & 0 deletions libqrexec/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,10 @@ void setup_logging(const char *program_name) {
errx(125, "File descriptor %d is closed, cannot continue", i);
}

/* qrexec_logv() uses several separate fprintf calls, print them at once */
errno = 0;
if (setvbuf(stderr, NULL, _IOLBF, 0))
warn("Failed to enable line buffering on stderr");

qrexec_program_name = program_name;
}

0 comments on commit 3b7ab0c

Please sign in to comment.