]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - src/pakfire/pakfire
pakfire: Prevent from get launched multiple times.
[people/pmueller/ipfire-2.x.git] / src / pakfire / pakfire
index c69a8d3ad6dcf056f83518c4910463938c01f5cd..4139d106b8c0ef7ff4f4ad46839e0da64c9662cb 100644 (file)
@@ -2,7 +2,7 @@
 ###############################################################################
 #                                                                             #
 # IPFire.org - A linux based firewall                                         #
-# Copyright (C) 2007-2015   IPFire Team   <info@ipfire.org>                   #
+# Copyright (C) 2007-2021   IPFire Team   <info@ipfire.org>                   #
 #                                                                             #
 # This program is free software: you can redistribute it and/or modify        #
 # it under the terms of the GNU General Public License as published by        #
@@ -31,6 +31,7 @@
        
        my $interactive = 1;
        my $force = "noforce";
+       my $locked;
        
        &Pakfire::logger("PAKFIRE INFO: IPFire Pakfire $Conf::version started!");
 
                &Pakfire::message("PAKFIRE ERROR: You need to be online to run pakfire!");
                exit 2;
        }
+
+       # Check if a lockfile already exists.
+       if (-e "$Pakfire::lockfile") {
+               &Pakfire::message("PAKFIRE ERROR: Another instance of pakfire is already running!");
+               exit 1;
+       }
+
+       # Write lockfile.
+       open(LOCK, ">$Pakfire::lockfile");
+
+       # Pakfire has locked in this session set locket to "1".
+       $locked = "1";
+
+       # Close filehandle.
+       close(LOCK);
        
        ### Check if we are started by another name
        #
 
        &Pakfire::logger("PAKFIRE INFO: Pakfire has finished. Closing.");
 
+       END {
+               # Check if pakfire has been locked in this session.
+               if ($locked) {
+                       # Remove lockfile.
+                       unlink($Pakfire::lockfile);
+               }
+       }
+
        exit 0;