mirror of
https://github.com/qemu/qemu.git
synced 2025-08-07 23:16:19 +00:00
pr-helper: Rework socket path handling
When reviewing Paolo's pr-helper patches I've noticed couple of problems: 1) socket_path needs to be calculated at two different places (one for printing out help, the other if socket activation is NOT used), 2) even though the default socket_path is allocated in compute_default_paths() it is the only default path the function handles. For instance, pidfile is allocated outside of this function. And yet again, at different places than 1) Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Message-Id: <c791ba035f26ea957e8f3602e3009b621769b1ba.1530611283.git.mprivozn@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
ee8c13b814
commit
2729d79d49
@ -76,14 +76,12 @@ static int gid = -1;
|
|||||||
|
|
||||||
static void compute_default_paths(void)
|
static void compute_default_paths(void)
|
||||||
{
|
{
|
||||||
if (!socket_path) {
|
|
||||||
socket_path = qemu_get_local_state_pathname("run/qemu-pr-helper.sock");
|
socket_path = qemu_get_local_state_pathname("run/qemu-pr-helper.sock");
|
||||||
}
|
pidfile = qemu_get_local_state_pathname("run/qemu-pr-helper.pid");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usage(const char *name)
|
static void usage(const char *name)
|
||||||
{
|
{
|
||||||
compute_default_paths();
|
|
||||||
(printf) (
|
(printf) (
|
||||||
"Usage: %s [OPTIONS] FILE\n"
|
"Usage: %s [OPTIONS] FILE\n"
|
||||||
"Persistent Reservation helper program for QEMU\n"
|
"Persistent Reservation helper program for QEMU\n"
|
||||||
@ -841,19 +839,6 @@ static gboolean accept_client(QIOChannel *ioc, GIOCondition cond, gpointer opaqu
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check socket parameters compatibility when socket activation is used.
|
|
||||||
*/
|
|
||||||
static const char *socket_activation_validate_opts(void)
|
|
||||||
{
|
|
||||||
if (socket_path != NULL) {
|
|
||||||
return "Unix socket can't be set when using socket activation";
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void termsig_handler(int signum)
|
static void termsig_handler(int signum)
|
||||||
{
|
{
|
||||||
atomic_cmpxchg(&state, RUNNING, TERMINATE);
|
atomic_cmpxchg(&state, RUNNING, TERMINATE);
|
||||||
@ -927,6 +912,7 @@ int main(int argc, char **argv)
|
|||||||
char *trace_file = NULL;
|
char *trace_file = NULL;
|
||||||
bool daemonize = false;
|
bool daemonize = false;
|
||||||
bool pidfile_specified = false;
|
bool pidfile_specified = false;
|
||||||
|
bool socket_path_specified = false;
|
||||||
unsigned socket_activation;
|
unsigned socket_activation;
|
||||||
|
|
||||||
struct sigaction sa_sigterm;
|
struct sigaction sa_sigterm;
|
||||||
@ -943,12 +929,14 @@ int main(int argc, char **argv)
|
|||||||
qemu_add_opts(&qemu_trace_opts);
|
qemu_add_opts(&qemu_trace_opts);
|
||||||
qemu_init_exec_dir(argv[0]);
|
qemu_init_exec_dir(argv[0]);
|
||||||
|
|
||||||
pidfile = qemu_get_local_state_pathname("run/qemu-pr-helper.pid");
|
compute_default_paths();
|
||||||
|
|
||||||
while ((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
|
while ((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'k':
|
case 'k':
|
||||||
socket_path = optarg;
|
g_free(socket_path);
|
||||||
|
socket_path = g_strdup(optarg);
|
||||||
|
socket_path_specified = true;
|
||||||
if (socket_path[0] != '/') {
|
if (socket_path[0] != '/') {
|
||||||
error_report("socket path must be absolute");
|
error_report("socket path must be absolute");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -1039,10 +1027,9 @@ int main(int argc, char **argv)
|
|||||||
socket_activation = check_socket_activation();
|
socket_activation = check_socket_activation();
|
||||||
if (socket_activation == 0) {
|
if (socket_activation == 0) {
|
||||||
SocketAddress saddr;
|
SocketAddress saddr;
|
||||||
compute_default_paths();
|
|
||||||
saddr = (SocketAddress){
|
saddr = (SocketAddress){
|
||||||
.type = SOCKET_ADDRESS_TYPE_UNIX,
|
.type = SOCKET_ADDRESS_TYPE_UNIX,
|
||||||
.u.q_unix.path = g_strdup(socket_path)
|
.u.q_unix.path = socket_path,
|
||||||
};
|
};
|
||||||
server_ioc = qio_channel_socket_new();
|
server_ioc = qio_channel_socket_new();
|
||||||
if (qio_channel_socket_listen_sync(server_ioc, &saddr, &local_err) < 0) {
|
if (qio_channel_socket_listen_sync(server_ioc, &saddr, &local_err) < 0) {
|
||||||
@ -1050,12 +1037,10 @@ int main(int argc, char **argv)
|
|||||||
error_report_err(local_err);
|
error_report_err(local_err);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
g_free(saddr.u.q_unix.path);
|
|
||||||
} else {
|
} else {
|
||||||
/* Using socket activation - check user didn't use -p etc. */
|
/* Using socket activation - check user didn't use -p etc. */
|
||||||
const char *err_msg = socket_activation_validate_opts();
|
if (socket_path_specified) {
|
||||||
if (err_msg != NULL) {
|
error_report("Unix socket can't be set when using socket activation");
|
||||||
error_report("%s", err_msg);
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1072,7 +1057,6 @@ int main(int argc, char **argv)
|
|||||||
error_get_pretty(local_err));
|
error_get_pretty(local_err));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
socket_path = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemu_init_main_loop(&local_err)) {
|
if (qemu_init_main_loop(&local_err)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user