MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / io_redirect

Function io_redirect

gtk/src/application.c:267–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

265}
266
267static void
268io_redirect (GhbApplication *self, signal_user_data_t *ud)
269{
270 GIOChannel *channel;
271 gint pfd[2];
272 gchar *config, *path, *str;
273 pid_t pid;
274
275 g_return_if_fail(GHB_IS_APPLICATION(self));
276
277 if (!redirect_io)
278 return;
279
280 // I'm opening a pipe and attaching the writer end to stderr
281 // The reader end will be polled by main event loop and I'll get
282 // a callback when there is data available.
283 if (pipe( pfd ) < 0)
284 {
285 g_warning("Failed to redirect IO. Logging impaired\n");
286 return;
287 }
288 clean_old_logs();
289 // Open activity log.
290 config = ghb_get_user_config_dir(NULL);
291 pid = getpid();
292 path = g_strdup_printf("%s/Activity.log.%"PRId64, config, (int64_t)pid);
293 ud->activity_log = g_io_channel_new_file (path, "w", NULL);
294 ud->job_activity_log = NULL;
295 str = g_strdup_printf("<big><b>%s</b></big>", path);
296 ghb_ui_update("activity_location", ghb_string_value(str));
297 g_free(str);
298 g_free(path);
299 g_free(config);
300 if (ud->activity_log != NULL)
301 {
302 // Set encoding to raw.
303 g_io_channel_set_encoding(ud->activity_log, NULL, NULL);
304 }
305 // redirect stderr to the writer end of the pipe
306
307#if defined(_WIN32)
308 _dup2(pfd[1], _fileno(stderr));
309#else
310 dup2(pfd[1], STDERR_FILENO);
311#endif
312 setvbuf(stderr, NULL, _IONBF, 0);
313
314#if defined(_WIN32)
315 channel = g_io_channel_win32_new_fd(pfd[0]);
316#else
317 channel = g_io_channel_unix_new(pfd[0]);
318#endif
319
320 // I was getting an this error:
321 // "Invalid byte sequence in conversion input"
322 // Set disable encoding on the channel.
323 g_io_channel_set_encoding(channel, NULL, NULL);
324 self->stderr_src_id =

Callers 1

ghb_application_activateFunction · 0.85

Calls 4

clean_old_logsFunction · 0.85
ghb_get_user_config_dirFunction · 0.85
ghb_ui_updateFunction · 0.85
ghb_string_valueFunction · 0.85

Tested by

no test coverage detected