From 23f1b44654220fbff41b476f2a001a2797d53ba5 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sat, 23 May 2026 00:22:10 -0400 Subject: Exit if another instance is already running. --- sbosrcarch | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sbosrcarch b/sbosrcarch index 183a88e..b706cf5 100755 --- a/sbosrcarch +++ b/sbosrcarch @@ -390,6 +390,7 @@ use Net::FTP; use POSIX 'getcwd'; use File::Path qw/mkpath rmtree/; use File::Copy qw/copy move/; +use Fcntl ':flock'; # check_single_instance() needs this # 20151016 bkw: migrating to curl our $use_curl = 1; @@ -420,6 +421,20 @@ our $filebytes = 0; our $actualfilecount = 0; our $totalfiles = 0; +# 20260523 bkw: needs to be a global so it won't auto-close when +# check_single_instance() returns. +our $self_fh; + +# 20260523 bkw: This may not be portable to non-Linux (or even to +# Perl built on non-Slackware), but it doesn't have to be. +sub check_single_instance { + open our $self_fh, "<", $0 or die "Can't open myself for reading: $!\n"; + + if(!flock($self_fh, LOCK_EX | LOCK_NB)) { + die "Another instance of $0 is running.\n"; + } +} + sub read_config { my $conf_used; @@ -1977,6 +1992,7 @@ EOF $|++; usage() unless (defined $ARGV[0] && $ARGV[0] !~ /^-+h(?:elp)?/); +check_single_instance(); read_config(); for ($ARGV[0]) { /create/ && do { create_mode(); }; -- cgit v1.2.3