diff main.c @ 9:0e50d3652326

use libunique to ensure that only a single instance of pk-update-icon can be run
author Guido Berhoerster <guido@berhoerster.name>
date Tue, 11 Oct 2011 17:07:49 +0200
parents 58a3312a1c59
children 64f05992d8ec
line wrap: on
line diff
--- a/main.c	Tue Oct 11 17:07:49 2011 +0200
+++ b/main.c	Tue Oct 11 17:07:49 2011 +0200
@@ -25,6 +25,7 @@
 #include <locale.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
+#include <unique/unique.h>
 
 struct UpdatesInfo info;
 
@@ -86,6 +87,8 @@
 int main(int argc, char **argv)
 {
 	GtkStatusIcon *tray_icon;
+	UniqueApp *app;
+	int exitval = 0;
 
 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);
@@ -93,6 +96,12 @@
 	textdomain(PACKAGE);
 
 	gtk_init(&argc, &argv);
+	app = unique_app_new(APP_NAME, NULL);
+	if (unique_app_is_running(app)) {
+		g_printerr("Another instance of pk-update-icon is already running. Exiting.\n");
+		exitval = 1;
+		goto out;
+	}
 	tray_icon = create_tray_icon();
 	init_notify();
 
@@ -103,5 +112,10 @@
 
 	gtk_main();
 
-	return 0;
+	g_object_unref(tray_icon);
+
+out:
+	g_object_unref(app);
+
+	return exitval;
 }