Skip to content

Commit 6975b5d

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

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
@@ -772,6 +772,12 @@ option_cb(const gchar *option_name, const gchar *optarg, gpointer data,
772772
if (pcmk__scan_nvpair(optarg, &name, &value) != pcmk_rc_ok) {
773773
return FALSE;
774774
}
775+
776+
/* services__create_resource_action() ultimately takes ownership of
777+
* options.cmdline_params. It's not worth trying to ensure that the entire
778+
* call path uses (gchar *) strings and g_free(). So create the table for
779+
* (char *) strings, and duplicate the (gchar *) strings when inserting.
780+
*/
775781
if (options.cmdline_params == NULL) {
776782
options.cmdline_params = pcmk__strkey_table(free, free);
777783
}
@@ -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
@@ -2238,7 +2238,9 @@ apply_overrides(GHashTable *params, GHashTable *overrides)
22382238
}
22392239
}
22402240

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

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

0 commit comments

Comments
 (0)