diff options
| author | B. Watson <urchlay@slackware.uk> | 2026-05-23 00:22:10 -0400 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2026-05-23 00:22:10 -0400 |
| commit | 23f1b44654220fbff41b476f2a001a2797d53ba5 (patch) | |
| tree | 2bca27a8fbd26be060f4d8ca0bfaa1e74d39819e | |
| parent | 48bd5dbb1297b386f7913ac485c5ec186c41419f (diff) | |
| download | sbosrcarch-23f1b44654220fbff41b476f2a001a2797d53ba5.tar.gz | |
Exit if another instance is already running.
| -rwxr-xr-x | sbosrcarch | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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(); }; |
