Codebase list facter / 70d26da
(maint) Merge up 2f05c0b to master Generated by CI * commit '2f05c0b208c0848bc0052ac7abf772754f4b79da': (FACT-2682) disable stdout buffering while loading custom facts Jenkins CI 3 years ago
1 changed file(s) with 14 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
7676 // https://github.com/ruby/ruby/blob/v2_1_9/ruby.c#L2011-L2022 for comments.
7777 // The only piece we seem to need out of rb_w32_sysinit is WSAStartup.
7878 util::windows::wsa winsocket;
79
80 // Disable stdout buffering while loading custom facts, similar to `stderr` in `init_stdhandle`
81 // https://github.com/ruby/ruby/blob/9e41a75255d15765648279629fd3134cae076398/win32/win32.c#L2655
82 // This is needed in a specific case:
83 // - run facter from ruby with backticks
84 // - have a custom fact executing external command with backticks
85 // In this case, `\x00` character will be shown on stdout instead of fact output
86 // We suppose that somwhere between ruby(`facter my_fact`)<->c(rb_load)<->ruby(Facter.add)<->c(rb_funcall_passing_block)<->ruby(`echo test`)
87 // stdout gets the wchar end of string that will break it
88 setvbuf(stdout, NULL, _IONBF, 0);
7989 #endif
8090 api& ruby = api::instance();
8191 module mod(facts, {}, !initialize_puppet);
94104 } else {
95105 mod.resolve_facts();
96106 }
107 #ifdef _WIN32
108 // Enable stdout line buffering (disabled due custom facts loading)
109 setvbuf(stdout, NULL, _IOLBF, 0);
110 #endif
97111 }
98112
99113 void load_custom_facts(collection& facts, vector<string> const& paths)