Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #9021: Patch the agent to output needed data for jinja2 templating #1081

Conversation

amousset
Copy link
Member

@amousset
Copy link
Member Author

Still testing, please wait before merging.

FNCALL_OPTION_NONE, FNCALL_CATEGORY_IO, SYNTAX_STATUS_NORMAL),
FnCallTypeNew("datastate", CF_DATA_TYPE_CONTAINER, DATASTATE_ARGS, &FnCallDatastate, "Construct a container of the variable and class state",
FNCALL_OPTION_NONE, FNCALL_CATEGORY_UTILS, SYNTAX_STATUS_NORMAL),
+ FnCallTypeNew("dumpdatastate", CF_DATA_TYPE_CONTEXT, FILESTAT_ARGS, &FnCallDumpDatastate, "Dump the current datatstae() into the given file",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo here: datastate()*

+ FILE *fout;
+ if ((fout = fopen(path, "w")) == NULL)
+ {
+ Log(LOG_LEVEL_ERR, "Cannot open the destination file '%s'. (fopen: %s)",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's useful in error messages to know where this error is coming from. Could you prefix it with "dumpdatastate(): " maybe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

+ ARG_UNUSED const FnCall *fp,
+ ARG_UNUSED const Rlist *args)
+{
+ char *path = RlistScalarValue(args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need free-ing at the end of the function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the data is in args, which is freed by FnCallDestroy in a parent function.

+ JsonElement *state = DefaultTemplateData(ctx, NULL);
+ JsonWrite(writer, state, 0);
+
+ WriterClose(writer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also fclose() the FILE handle above? If not we should close it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

@amousset
Copy link
Member Author

Commit modified

@amousset amousset force-pushed the bug_9021/patch_the_agent_to_output_needed_data_for_jinja2_templating branch from 3ef5527 to 49fb019 Compare September 22, 2016 15:14
@peckpeck
Copy link
Member

Looks good to me

@Normation-Quality-Assistant
Copy link
Contributor

OK, merging this PR

@Normation-Quality-Assistant Normation-Quality-Assistant merged commit 49fb019 into Normation:branches/rudder/3.2 Sep 27, 2016
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants