changeset 2738:c6e5a43c87e5

Fix #162: Cannot symlink file if two geeqie instances are running https://github.com/BestImageViewer/geeqie/issues/162 Do not permit a second instance of Geeqie to be started. There is only one geeqierc.xml file - it is not sensible to allow more than one instance to be run. File/New Window can be used instead.
author Colin Clark <colin.clark@cclark.uk>
date Thu, 29 Mar 2018 17:10:58 +0100
parents 065402476db8
children a03b5446e68f
files src/main.c src/remote.c src/remote.h
diffstat 3 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.c	Sat Mar 24 10:37:17 2018 +0000
+++ b/src/main.c	Thu Mar 29 17:10:58 2018 +0100
@@ -782,6 +782,7 @@
 	CollectionData *first_collection = NULL;
 	gchar *buf;
 	CollectionData *cd = NULL;
+	gchar *app_lock;
 
 #ifdef HAVE_GTHREAD
 #if !GLIB_CHECK_VERSION(2,32,0)
@@ -857,6 +858,16 @@
 	DEBUG_1("%s main: parse_command_line", get_exec_time());
 	parse_command_line(argc, argv);
 
+	/* If Geeqie is already running, prevent a second instance
+	 * from being started
+	 */
+	app_lock = g_build_filename(get_rc_dir(), ".command", NULL);
+	if (remote_server_exists(app_lock))
+		{
+		_exit(0);
+		}
+	g_free(app_lock);
+
 	DEBUG_1("%s main: mkdir_if_not_exists", get_exec_time());
 	/* these functions don't depend on config file */
 	mkdir_if_not_exists(get_rc_dir());
--- a/src/remote.c	Sat Mar 24 10:37:17 2018 +0000
+++ b/src/remote.c	Thu Mar 29 17:10:58 2018 +0100
@@ -181,7 +181,7 @@
 	return TRUE;
 }
 
-static gboolean remote_server_exists(const gchar *path)
+gboolean remote_server_exists(const gchar *path)
 {
 	RemoteConnection *rc;
 
--- a/src/remote.h	Sat Mar 24 10:37:17 2018 +0000
+++ b/src/remote.h	Thu Mar 29 17:10:58 2018 +0100
@@ -47,6 +47,7 @@
 		    GList *cmd_list, GList *collection_list);
 
 RemoteConnection *remote_server_init(gchar *path, CollectionData *command_collection);
+gboolean remote_server_exists(const gchar *path);
 
 
 #endif