From 3e4cd1e0f7d8428ee2ad6f4e93d2b1ac08deef3e Mon Sep 17 00:00:00 2001 From: jstebbins Date: Sun, 4 Oct 2009 18:00:57 +0000 Subject: [PATCH] LinGui: create a queue lock file to prevent simultaneous access to the queue from 2 running instances of ghb git-svn-id: svn://localhost/HandBrake/trunk@2869 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- gtk/src/main.c | 15 +++++++++++++++ gtk/src/presets.c | 22 ++++++++++++++++++++++ gtk/src/presets.h | 1 + gtk/src/preview.c | 2 -- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/gtk/src/main.c b/gtk/src/main.c index efc2fbc9..2c732079 100644 --- a/gtk/src/main.c +++ b/gtk/src/main.c @@ -697,6 +697,21 @@ main (int argc, char *argv[]) ghb_hal_init(); #endif + if (!ghb_lock_file("queue_lock")) + { + const gchar *markup = + N_("Another instance of HandBrake is already running.\n" + "\n" + "Only one instance of HandBrake may run.\n"); + GtkWidget *dialog = gtk_message_dialog_new_with_markup(NULL, + GTK_DIALOG_MODAL, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + _(markup)); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + exit(EXIT_FAILURE); + } ud = g_malloc0(sizeof(signal_user_data_t)); ud->debug = ghb_debug; g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, debug_log_handler, ud); diff --git a/gtk/src/presets.c b/gtk/src/presets.c index 7d315190..75354b16 100644 --- a/gtk/src/presets.c +++ b/gtk/src/presets.c @@ -11,6 +11,10 @@ * any later version. * */ +#include +#include +#include +#include #include #include #include @@ -1112,6 +1116,24 @@ load_plist(const gchar *name) return plist; } +gboolean +ghb_lock_file(const gchar *name) +{ + gchar *config, *path; + int fd, lock = 0; + + config = ghb_get_user_config_dir(NULL); + path = g_strdup_printf ("%s/%s", config, name); + fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); + if (fd >= 0) + lock = lockf(fd, F_TLOCK, 0); + if (lock) + close(fd); + g_free(config); + g_free(path); + return !lock; +} + static void remove_plist(const gchar *name) { diff --git a/gtk/src/presets.h b/gtk/src/presets.h index 8c05f197..65b4e8cd 100644 --- a/gtk/src/presets.h +++ b/gtk/src/presets.h @@ -40,5 +40,6 @@ gchar* ghb_preset_path_string(const GValue *path); gboolean ghb_preset_is_custom(void); void ghb_prefs_store(void); void ghb_pref_set(GValue *settings, const gchar *key); +gboolean ghb_lock_file(const gchar *name); #endif // _GHB_PRESETS_H_ diff --git a/gtk/src/preview.c b/gtk/src/preview.c index 577cbd55..9fd92bf5 100644 --- a/gtk/src/preview.c +++ b/gtk/src/preview.c @@ -946,8 +946,6 @@ picture_settings_alt2_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) { GtkWidget *toggle; gboolean active; - gint signal_id; - gint handler_id = 0; GtkWidget *window; g_debug("picture_settings_alt2_clicked_cb()"); -- 2.11.0