diff options
-rw-r--r-- | packaging/murphy.spec | 2 | ||||
-rw-r--r-- | src/console-client/client.c | 9 | ||||
-rw-r--r-- | src/plugins/console/plugin-console.c | 8 | ||||
-rw-r--r-- | src/plugins/domain-control/client.h | 1 | ||||
-rw-r--r-- | src/plugins/domain-control/plugin-domain-control.c | 11 | ||||
-rw-r--r-- | src/plugins/domain-control/test-client.c | 9 | ||||
-rw-r--r-- | src/resource/protocol.h | 17 |
7 files changed, 48 insertions, 9 deletions
diff --git a/packaging/murphy.spec b/packaging/murphy.spec index 26acaa2..7f8d9e3 100644 --- a/packaging/murphy.spec +++ b/packaging/murphy.spec @@ -29,7 +29,7 @@ Summary: Resource policy framework Name: murphy Version: 0.0.75 -Release: 21 +Release: 22 License: BSD-3-Clause Group: System/Service URL: http://01.org/murphy/ diff --git a/src/console-client/client.c b/src/console-client/client.c index 1346691..9495fc1 100644 --- a/src/console-client/client.c +++ b/src/console-client/client.c @@ -48,6 +48,7 @@ #define DEFAULT_PROMPT "murphy" #define DEFAULT_ADDRESS "unxs:@murphy-console" +#define DEFAULT_CONTAINER_ADDRESS DEFAULT_ADDRESS"-container" /* @@ -318,11 +319,17 @@ static void signal_handler(mrp_sighandler_t *h, int signum, void *user_data) } +static bool is_in_container(void) +{ + return access("/run/systemd/container", F_OK) == 0; +} + + static void client_set_defaults(client_t *c) { mrp_clear(c); c->seqno = 1; - c->server = DEFAULT_ADDRESS; + c->server = is_in_container() ? DEFAULT_CONTAINER_ADDRESS : DEFAULT_ADDRESS; c->log_mask = MRP_LOG_UPTO(MRP_LOG_INFO); c->log_target = MRP_LOG_TO_STDERR; } diff --git a/src/plugins/console/plugin-console.c b/src/plugins/console/plugin-console.c index 13fa207..fee47af 100644 --- a/src/plugins/console/plugin-console.c +++ b/src/plugins/console/plugin-console.c @@ -49,6 +49,7 @@ #include <murphy/plugins/console-protocol.h> #define DEFAULT_ADDRESS "unxs:@murphy-console" /* default console address */ +#define DEFAULT_CONTAINER_ADDRESS DEFAULT_ADDRESS"-container" /* default container console address */ #ifdef MURPHY_DATADIR /* default content dir */ # define DEFAULT_HTTPDIR MURPHY_DATADIR"/webconsole" @@ -729,6 +730,11 @@ enum { }; +static bool is_in_container(void) +{ + return access("/run/systemd/container", F_OK) == 0; +} + static int console_init(mrp_plugin_t *plugin) { @@ -739,7 +745,7 @@ static int console_init(mrp_plugin_t *plugin) mrp_list_init(&data->clients); data->ctx = plugin->ctx; - data->address = plugin->args[ARG_ADDRESS].str; + data->address = is_in_container() ? DEFAULT_CONTAINER_ADDRESS : plugin->args[ARG_ADDRESS].str; data->httpdir = plugin->args[ARG_HTTPDIR].str; data->sslcert = plugin->args[ARG_SSLCERT].str; data->sslpkey = plugin->args[ARG_SSLPKEY].str; diff --git a/src/plugins/domain-control/client.h b/src/plugins/domain-control/client.h index 5a90b6d..30a3158 100644 --- a/src/plugins/domain-control/client.h +++ b/src/plugins/domain-control/client.h @@ -38,6 +38,7 @@ MRP_CDECL_BEGIN #define MRP_DEFAULT_DOMCTL_ADDRESS "unxs:@murphy-domctrl" +#define MRP_DEFAULT_CONTAINER_DOMCTL_ADDRESS MRP_DEFAULT_DOMCTL_ADDRESS"-container" /* diff --git a/src/plugins/domain-control/plugin-domain-control.c b/src/plugins/domain-control/plugin-domain-control.c index 287844e..309cdb2 100644 --- a/src/plugins/domain-control/plugin-domain-control.c +++ b/src/plugins/domain-control/plugin-domain-control.c @@ -37,6 +37,8 @@ #include "client.h" #define DEFAULT_EXTADDR MRP_DEFAULT_DOMCTL_ADDRESS +#define DEFAULT_CONTAINER_EXTADDR MRP_DEFAULT_CONTAINER_DOMCTL_ADDRESS + #define NO_ADDR NULL #ifdef MURPHY_DATADIR @@ -53,9 +55,16 @@ enum { }; +static bool is_in_container(void) +{ + return access("/run/systemd/container", F_OK) == 0; +} + + static int plugin_init(mrp_plugin_t *plugin) { - const char *extaddr = plugin->args[ARG_EXTADDR].str; + const char *extaddr = is_in_container() ? + DEFAULT_CONTAINER_EXTADDR : plugin->args[ARG_EXTADDR].str; const char *intaddr = plugin->args[ARG_INTADDR].str; const char *wrtaddr = plugin->args[ARG_WRTADDR].str; const char *httpdir = plugin->args[ARG_HTTPDIR].str; diff --git a/src/plugins/domain-control/test-client.c b/src/plugins/domain-control/test-client.c index f801470..885557c 100644 --- a/src/plugins/domain-control/test-client.c +++ b/src/plugins/domain-control/test-client.c @@ -1302,10 +1302,17 @@ static void print_usage(const char *argv0, int exit_code, const char *fmt, ...) } +static bool is_in_container(void) +{ + return access("/run/systemd/container", F_OK) == 0; +} + + static void client_set_defaults(client_t *c) { mrp_clear(c); - c->addrstr = MRP_DEFAULT_DOMCTL_ADDRESS; + c->addrstr = is_in_container() ? + MRP_DEFAULT_CONTAINER_DOMCTL_ADDRESS : MRP_DEFAULT_DOMCTL_ADDRESS; c->zone = FALSE; c->verbose = FALSE; c->audio = FALSE; diff --git a/src/resource/protocol.h b/src/resource/protocol.h index 44075e8..30c7691 100644 --- a/src/resource/protocol.h +++ b/src/resource/protocol.h @@ -33,10 +33,12 @@ #include <stdint.h> #include <stdbool.h> #include <stdlib.h> +#include <fcntl.h> #include <murphy/common/msg.h> #define RESPROTO_DEFAULT_ADDRESS "unxs:@murphy-resource-native" +#define RESPROTO_DEFAULT_CONTAINER_ADDRESS RESPROTO_DEFAULT_ADDRESS"-container" #define RESPROTO_DEFAULT_ADDRVAR "MURPHY_RESOURCE_ADDRESS" @@ -93,14 +95,21 @@ typedef enum { } mrp_resproto_state_t; +static bool is_in_container(void) +{ + return access("/run/systemd/container", F_OK) == 0; +} + + static inline const char *mrp_resource_get_default_address(void) { - const char *addr; + const char *addr = getenv(RESPROTO_DEFAULT_ADDRVAR); - if ((addr = getenv(RESPROTO_DEFAULT_ADDRVAR)) == NULL) - return RESPROTO_DEFAULT_ADDRESS; - else + if (addr) return addr; + + return is_in_container() ? + RESPROTO_DEFAULT_CONTAINER_ADDRESS : RESPROTO_DEFAULT_ADDRESS; } #endif /* __MURPHY_RESOURCE_PROTOCOL_H__ */ |