]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
pakfire: Prevent from get launched multiple times.
authorStefan Schantl <stefan.schantl@ipfire.org>
Mon, 24 May 2021 17:38:20 +0000 (19:38 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 May 2021 09:51:56 +0000 (09:51 +0000)
When pakfire gets launched a check if a so called lockfile exists and
the process will be aborted, otherwise the file will be created which
prevents any other pakfire instance to perform any operations until the
first process gets finished and the lock will be released again.

Because the release of the lock is located in an END block, the lock
also will be released in case the pakfire process gets interuped or
gains an error.

This prevents from an lock loop and an unuseable pakfire.

Reference: #12621.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/lib/functions.pl
src/pakfire/pakfire

index 4d5c6219ab2c30bf24a28cb50b3b1b710b9881c2..f9a19b60d8206bf0433ab3104262a1acae4893f3 100644 (file)
@@ -73,6 +73,9 @@ my %pakfiresettings = ();
 # Make version
 $Conf::version = &make_version();
 
+# Pakfire lock file.
+our $lockfile = "/tmp/pakfire_lock";
+
 sub message {
        my $message = shift;
                
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;