static void on_session_finished (GSubprocess *subprocess, GAsyncResult *result, State *state) { gboolean cancelled; cancelled = !g_subprocess_wait_finish (subprocess, result, NULL); if (cancelled) { goto out; } if (g_subprocess_get_if_exited (subprocess)) { int exit_status; exit_status = g_subprocess_get_exit_status (subprocess); g_debug ("session exited with status %d", exit_status); state->session_exit_status = exit_status; } else { int signal_number; signal_number = g_subprocess_get_term_sig (subprocess); g_debug ("session was killed with status %d", signal_number); } g_clear_object (&state->session_subprocess); out: g_main_loop_quit (state->main_loop); }
static void subprocess_wait_cb (GObject *object, GAsyncResult *res, gpointer user_data) { GSubprocess *subprocess = (GSubprocess *)object; g_autofree gchar *input_prefix = NULL; g_autoptr(IdeDiagnostics) local_diags = NULL; g_autoptr(GTask) task = user_data; g_autoptr(GPtrArray) array = NULL; g_autoptr(GDataInputStream) stderr_data_input = NULL; GInputStream *stderr_input = NULL; g_autoptr(IdeGettextDiagnostics) diags = NULL; TranslationUnit *unit; GError *error = NULL; g_assert (G_IS_SUBPROCESS (subprocess)); g_assert (G_IS_TASK (task)); unit = g_task_get_task_data (task); g_assert (unit != NULL); if (!g_subprocess_wait_finish (subprocess, res, &error)) { g_task_return_error (task, error); return; } array = g_ptr_array_new_with_free_func ((GDestroyNotify)ide_diagnostic_unref); if (g_subprocess_get_exit_status (subprocess) == 0) goto out; stderr_input = g_subprocess_get_stderr_pipe (subprocess); stderr_data_input = g_data_input_stream_new (stderr_input); input_prefix = g_strdup_printf ("%s:", ide_unsaved_file_get_temp_path (unit->unsaved_file)); for (;;) { g_autofree gchar *line = NULL; gsize length; line = g_data_input_stream_read_line (stderr_data_input, &length, g_task_get_cancellable (task), &error); if (line == NULL) break; if (g_str_has_prefix (line, input_prefix)) { gchar *p = line + strlen (input_prefix); if (g_ascii_isdigit (*p)) { gulong line_number = strtoul (p, &p, 10); IdeSourceLocation *loc; IdeDiagnostic *diag; loc = ide_source_location_new (unit->file, line_number - 1, 0, 0); diag = ide_diagnostic_new (IDE_DIAGNOSTIC_WARNING, g_strstrip (p + 1), loc); g_ptr_array_add (array, diag); } } } out: local_diags = ide_diagnostics_new (g_steal_pointer (&array)); diags = g_object_new (IDE_TYPE_GETTEXT_DIAGNOSTICS, "diagnostics", local_diags, "sequence", ide_unsaved_file_get_sequence (unit->unsaved_file), NULL); g_task_return_pointer (task, g_steal_pointer (&diags), g_object_unref); }