Commit d7ded23e authored by Victor Ananjevsky's avatar Victor Ananjevsky

improve run_command_sync for avoiding possible race conditions

parent 1d402f7d
...@@ -644,29 +644,30 @@ print_bool_val (gboolean val) ...@@ -644,29 +644,30 @@ print_bool_val (gboolean val)
typedef struct { typedef struct {
gchar *cmd; gchar *cmd;
gchar **out; gchar **out;
gint ret;
gboolean lock;
} RunData; } RunData;
static gboolean run_lock = FALSE;
static gint ret = 0;
static void static void
run_thread (RunData *d) run_thread (RunData *d)
{ {
GError *err = NULL; GError *err = NULL;
if (!g_spawn_command_line_sync (d->cmd, d->out, NULL, &ret, &err)) if (!g_spawn_command_line_sync (d->cmd, d->out, NULL, NULL, &err))
{ {
if (options.debug) if (options.debug)
g_printerr (_("WARNING: Run command failed: %s\n"), err->message); g_printerr (_("WARNING: Run command failed: %s\n"), err->message);
g_error_free (err); g_error_free (err);
d->ret = -1;
} }
run_lock = FALSE; d->lock = FALSE;
} }
gint gint
run_command_sync (gchar *cmd, gchar **out) run_command_sync (gchar *cmd, gchar **out)
{ {
RunData *d; RunData *d;
gint ret;
d = g_new0 (RunData, 1); d = g_new0 (RunData, 1);
...@@ -681,16 +682,16 @@ run_command_sync (gchar *cmd, gchar **out) ...@@ -681,16 +682,16 @@ run_command_sync (gchar *cmd, gchar **out)
d->cmd = g_strdup (cmd); d->cmd = g_strdup (cmd);
d->out = out; d->out = out;
run_lock = TRUE; d->lock = TRUE;
ret = 0;
g_thread_new ("run_sync", (GThreadFunc) run_thread, d); g_thread_new ("run_sync", (GThreadFunc) run_thread, d);
while (run_lock != FALSE) while (d->lock != FALSE)
{ {
gtk_main_iteration_do (FALSE); gtk_main_iteration_do (FALSE);
usleep (10000); usleep (10000);
} }
ret = d->ret;
g_free (d->cmd); g_free (d->cmd);
g_free (d); g_free (d);
...@@ -905,6 +906,7 @@ yad_confirm_dlg (GtkWindow *parent, gchar *txt) ...@@ -905,6 +906,7 @@ yad_confirm_dlg (GtkWindow *parent, gchar *txt)
{ {
GtkWidget *d; GtkWidget *d;
gchar *buf; gchar *buf;
gint ret;
buf = g_strcompress (options.text_data.confirm_text); buf = g_strcompress (options.text_data.confirm_text);
d = gtk_message_dialog_new (parent, GTK_DIALOG_DESTROY_WITH_PARENT, d = gtk_message_dialog_new (parent, GTK_DIALOG_DESTROY_WITH_PARENT,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment