Pass the socket address when setting up the daemon

This commit is contained in:
Richard Hughes 2022-05-13 20:52:39 +01:00
parent 065b2a33f4
commit 7b806dbb2a
6 changed files with 30 additions and 26 deletions

View File

@ -828,7 +828,7 @@ fwupd_client_connect_async(FwupdClient *self,
}
} else {
#ifdef _WIN32
socket_address = g_strdup("tcp:host=localhost,port=1341");
socket_address = g_strdup(FWUPD_DBUS_P2P_SOCKET_ADDRESS);
#endif
}

View File

@ -28,6 +28,12 @@ G_BEGIN_DECLS
* The dbus interface
**/
#define FWUPD_DBUS_INTERFACE "org.freedesktop.fwupd"
/**
* FWUPD_DBUS_P2P_SOCKET_ADDRESS:
*
* The D-Bus socket address when using point-to-point connections.
**/
#define FWUPD_DBUS_P2P_SOCKET_ADDRESS "tcp:host=localhost,port=1341"
/**
* FWUPD_DEVICE_ID_ANY:

View File

@ -2110,11 +2110,9 @@ fu_daemon_set_machine_kind(FuDaemon *self, FuDaemonMachineKind machine_kind)
}
gboolean
fu_daemon_setup(FuDaemon *self, GError **error)
fu_daemon_setup(FuDaemon *self, const gchar *socket_address, GError **error)
{
const gchar *machine_kind = g_getenv("FWUPD_MACHINE_KIND");
const gchar *socket_filename = g_getenv("FWUPD_DBUS_SOCKET");
g_autofree gchar *socket_address = NULL;
g_return_val_if_fail(FU_IS_DAEMON(self), FALSE);
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
@ -2183,24 +2181,6 @@ fu_daemon_setup(FuDaemon *self, GError **error)
}
#endif
/* convert from filename to address, if required */
if (socket_filename != NULL) {
if (g_strrstr(socket_filename, "=") == NULL) {
#ifndef HAVE_SYSTEMD
/* this must be owned by root */
if (g_file_test(socket_filename, G_FILE_TEST_EXISTS))
g_unlink(socket_filename);
#endif
socket_address = g_strdup_printf("unix:path=%s", socket_filename);
} else {
socket_address = g_strdup(socket_filename);
}
} else {
#ifdef _WIN32
socket_address = g_strdup("tcp:host=localhost,port=1341");
#endif
}
/* own the object */
if (socket_address != NULL) {
g_autofree gchar *guid = g_dbus_generate_guid();

View File

@ -21,7 +21,7 @@ typedef enum {
FuDaemon *
fu_daemon_new(void);
gboolean
fu_daemon_setup(FuDaemon *self, GError **error);
fu_daemon_setup(FuDaemon *self, const gchar *socket_address, GError **error);
void
fu_daemon_start(FuDaemon *self);
void

View File

@ -13,6 +13,8 @@
#include <windows.h>
#include "fwupd-common.h"
#include "fu-daemon.h"
#include "fu-debug.h"
@ -88,7 +90,7 @@ fu_main_svc_main_cb(DWORD dwArgc, LPSTR *lpszArgv)
/* set up the daemon, which includes coldplugging devices -- then run it */
fu_main_svc_report_status(SERVICE_START_PENDING, NO_ERROR, 1000);
if (!fu_daemon_setup(daemon, &error)) {
if (!fu_daemon_setup(daemon, FWUPD_DBUS_P2P_SOCKET_ADDRESS, &error)) {
g_warning("Failed to load daemon: %s", error->message);
return;
}
@ -112,7 +114,7 @@ fu_main_console(int argc, char *argv[])
}
/* set up the daemon, which includes coldplugging devices -- then run it */
if (!fu_daemon_setup(daemon, &error)) {
if (!fu_daemon_setup(daemon, FWUPD_DBUS_P2P_SOCKET_ADDRESS, &error)) {
g_printerr("Failed to load daemon: %s\n", error->message);
return EXIT_FAILURE;
}

View File

@ -97,6 +97,7 @@ main(int argc, char *argv[])
{
gboolean immediate_exit = FALSE;
gboolean timed_exit = FALSE;
const gchar *socket_filename = g_getenv("FWUPD_DBUS_SOCKET");
const GOptionEntry options[] = {
{"timed-exit",
'\0',
@ -115,6 +116,7 @@ main(int argc, char *argv[])
N_("Exit after the engine has loaded"),
NULL},
{NULL}};
g_autofree gchar *socket_address = NULL;
g_autoptr(GError) error = NULL;
g_autoptr(GFile) argv0_file = g_file_new_for_path(argv[0]);
g_autoptr(GOptionContext) context = NULL;
@ -151,8 +153,22 @@ main(int argc, char *argv[])
fu_daemon_set_machine_kind(daemon, FU_DAEMON_MACHINE_KIND_PHYSICAL);
}
/* convert from filename to address, if required */
if (socket_filename != NULL) {
if (g_strrstr(socket_filename, "=") == NULL) {
#ifndef HAVE_SYSTEMD
/* this must be owned by root */
if (g_file_test(socket_filename, G_FILE_TEST_EXISTS))
g_unlink(socket_filename);
#endif
socket_address = g_strdup_printf("unix:path=%s", socket_filename);
} else {
socket_address = g_strdup(socket_filename);
}
}
/* set up the daemon, which includes coldplugging devices */
if (!fu_daemon_setup(daemon, &error)) {
if (!fu_daemon_setup(daemon, socket_address, &error)) {
g_printerr("Failed to load daemon: %s\n", error->message);
return EXIT_FAILURE;
}