cli_scope_install with the activation's stdout captured into out. */
| 2204 | |
| 2205 | /* cli_scope_install with the activation's stdout captured into out. */ |
| 2206 | static int cli_scope_install_captured(cli_scope_fixture_t *fixture, const char *home, |
| 2207 | const char *cache, const char *bin_dir, bool skip_binary, |
| 2208 | char *out, size_t out_size) { |
| 2209 | out[0] = '\0'; |
| 2210 | FILE *capture = tmpfile(); |
| 2211 | int saved_stdout = capture ? dup(STDOUT_FILENO) : -1; |
| 2212 | bool redirected = false; |
| 2213 | if (capture && saved_stdout >= 0) { |
| 2214 | fflush(stdout); |
| 2215 | redirected = dup2(fileno(capture), STDOUT_FILENO) >= 0; |
| 2216 | } |
| 2217 | int rc = redirected ? cli_scope_install(fixture, home, cache, bin_dir, skip_binary) : -1; |
| 2218 | if (redirected) { |
| 2219 | fflush(stdout); |
| 2220 | (void)dup2(saved_stdout, STDOUT_FILENO); |
| 2221 | } |
| 2222 | if (saved_stdout >= 0) { |
| 2223 | close(saved_stdout); |
| 2224 | } |
| 2225 | if (capture) { |
| 2226 | rewind(capture); |
| 2227 | size_t count = fread(out, 1, out_size - 1U, capture); |
| 2228 | out[count] = '\0'; |
| 2229 | fclose(capture); |
| 2230 | } |
| 2231 | return rc; |
| 2232 | } |
| 2233 | |
| 2234 | /* The notice an activation prints when it leaves a daemon it could not |
| 2235 | * confirm as its own: names the daemon by pid and tells the user how to stop |
no test coverage detected