client: Don't register agent without a need

Register agent iff no '--dontask' command-line option has been provided
or there are some other command line options besides '--dontask'
This commit is contained in:
Tim Kourt 2019-09-19 10:16:31 -07:00 committed by Denis Kenzior
parent 411834e089
commit 19529a4d3a
3 changed files with 13 additions and 1 deletions

View File

@ -76,6 +76,12 @@ bool command_option_get(const char *name, const char **value_out)
return false;
}
bool command_needs_no_agent(void)
{
return command_option_get(COMMAND_OPTION_DONTASK, NULL) &&
(l_queue_length(command_options) == 1);
}
static enum cmd_status cmd_version(const char *entity,
char **argv, int argc)
{

View File

@ -58,6 +58,7 @@ struct command_family {
};
bool command_option_get(const char *name, const char **value_out);
bool command_needs_no_agent(void);
bool command_line_find_token(const char *token, uint8_t num_to_inspect);
char **command_completion(const char *text, int start, int end);

View File

@ -704,6 +704,9 @@ static void get_managed_objects_callback(struct l_dbus_message *message,
while (l_dbus_message_iter_next_entry(&objects, &path, &object))
proxy_interface_create(path, &object);
if (command_needs_no_agent())
goto no_agent;
if (!agent_manager_register_agent()) {
display_error("Failed to register Agent.\n");
@ -715,6 +718,7 @@ static void get_managed_objects_callback(struct l_dbus_message *message,
return;
}
no_agent:
if (!command_is_interactive_mode()) {
command_noninteractive_trigger();
@ -829,7 +833,8 @@ bool dbus_proxy_exit(void)
{
struct interface_type_desc *desc;
agent_manager_unregister_agent();
if (!command_needs_no_agent())
agent_manager_unregister_agent();
for (desc = __start___interface; desc < __stop___interface; desc++) {
if (!desc->exit)