Skip to content

Commit 3ffb404

Browse files
committed
Refactor: tools: Clarify options.cmdline_params in crm_resource.c
Signed-off-by: Reid Wahl <[email protected]>
1 parent fb241ec commit 3ffb404

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

lib/services/services.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ copy_action_arguments(svc_action_t *op, uint32_t ra_caps, const char *name,
250250
return pcmk_rc_ok;
251251
}
252252

253+
// Takes ownership of params
253254
svc_action_t *
254255
services__create_resource_action(const char *name, const char *standard,
255256
const char *provider, const char *agent,

tools/crm_resource.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,12 @@ option_cb(const gchar *option_name, const gchar *optarg, gpointer data,
771771
if (pcmk__scan_nvpair(optarg, &name, &value) != pcmk_rc_ok) {
772772
return FALSE;
773773
}
774+
775+
/* services__create_resource_action() ultimately takes ownership of
776+
* options.cmdline_params. It's not worth trying to ensure that the entire
777+
* call path uses (gchar *) strings and g_free(). So create the table for
778+
* (char *) strings, and duplicate the (gchar *) strings when inserting.
779+
*/
774780
if (options.cmdline_params == NULL) {
775781
options.cmdline_params = pcmk__strkey_table(free, free);
776782
}
@@ -1902,7 +1908,6 @@ main(int argc, char **argv)
19021908
g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
19031909
_("--option must be used with --validate and without -r"));
19041910
g_hash_table_destroy(options.cmdline_params);
1905-
options.cmdline_params = NULL;
19061911
goto done;
19071912
}
19081913

tools/crm_resource_runtime.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2237,7 +2237,9 @@ apply_overrides(GHashTable *params, GHashTable *overrides)
22372237
}
22382238
}
22392239

2240-
// Does not modify override_hash or its contents
2240+
/* Takes ownership of params.
2241+
* Does not modify override_hash or its contents.
2242+
*/
22412243
crm_exit_t
22422244
cli_resource_execute_from_params(pcmk__output_t *out, const char *rsc_name,
22432245
const char *rsc_class, const char *rsc_prov,
@@ -2259,6 +2261,7 @@ cli_resource_execute_from_params(pcmk__output_t *out, const char *rsc_name,
22592261
set_agent_environment(params, timeout_ms, check_level, resource_verbose);
22602262
apply_overrides(params, override_hash);
22612263

2264+
// services__create_resource_action() takes ownership of params on success
22622265
op = services__create_resource_action(rsc_name? rsc_name : "test",
22632266
rsc_class, rsc_prov, rsc_type, action,
22642267
0, QB_MIN(timeout_ms, INT_MAX),

0 commit comments

Comments
 (0)