(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
76 | 76 | // https://github.com/ruby/ruby/blob/v2_1_9/ruby.c#L2011-L2022 for comments. |
77 | 77 | // The only piece we seem to need out of rb_w32_sysinit is WSAStartup. |
78 | 78 | 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); | |
79 | 89 | #endif |
80 | 90 | api& ruby = api::instance(); |
81 | 91 | module mod(facts, {}, !initialize_puppet); |
94 | 104 | } else { |
95 | 105 | mod.resolve_facts(); |
96 | 106 | } |
107 | #ifdef _WIN32 | |
108 | // Enable stdout line buffering (disabled due custom facts loading) | |
109 | setvbuf(stdout, NULL, _IOLBF, 0); | |
110 | #endif | |
97 | 111 | } |
98 | 112 | |
99 | 113 | void load_custom_facts(collection& facts, vector<string> const& paths) |