diff options
| -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(); }; |
