aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2023-08-04 19:23:51 -0400
committerB. Watson <urchlay@slackware.uk>2023-08-04 19:23:51 -0400
commit00898478dd5c67a5a8ec040f72bbffc76275082e (patch)
treed041dfbae3e470a6f343bb2a688878274139269d
parentb6fdc5b205a81952f29a1911bab710219530649a (diff)
downloadmisc-scripts-00898478dd5c67a5a8ec040f72bbffc76275082e.tar.gz
slacktopic.pl: avoid race condition with multiple instances.
-rw-r--r--slacktopic.pl21
1 files changed, 15 insertions, 6 deletions
diff --git a/slacktopic.pl b/slacktopic.pl
index 78a7b5c..5091e3e 100644
--- a/slacktopic.pl
+++ b/slacktopic.pl
@@ -80,7 +80,7 @@ our %IRSSI = (
# TODO: make some or all of these config variables into irssi
# settings? Probably overkill, this script is niche-market (probably
-# nobody but the author will ever run it...)
+# nobody but the author and one other person will ever run it...)
# Print verbose debugging messages in local irssi window?
our $DEBUG = 0;
@@ -94,11 +94,11 @@ our $FAKE = 0;
# the plain http URL, not https (which doesn't even exist). Actually,
# ftp would also work, but then you got the whole passive vs. active
# firewall mess.
-# 20190920 bkw: old URL quit working:
-#our $changelog_url =
- #"http://ftp.slackware.com/pub/slackware/slackware64-14.2/ChangeLog.txt";
+# Note: ftp.osuosl.org really is the primary Slackware site, but it
+# resolves to 3 different IPs (currently), which seem not to always
+# be in sync with each other.
our $changelog_url =
- "ftp://ftp.osuosl.org/pub/slackware/slackware-15.0/ChangeLog.txt";
+ "http://ftp.osuosl.org/pub/slackware/slackware-15.0/ChangeLog.txt";
# Max time curl will spend trying to do its thing. It'll give up after
# this many seconds, if it can't download the ChangeLog.
@@ -314,11 +314,20 @@ sub set_topic_date {
# Get old topic, replace the date with the new one.
debugmsg("set_topic_date() called, \$new_date is: $new_date");
my $t = $chan->{topic};
- unless($t =~ s,\[\d\d\d\d-\d\d-\d\d\],[$new_date],) {
+ unless($t =~ s,\[(\d\d\d\d-\d\d-\d\d)\],[$new_date],) {
errmsg("topic doesn't contain [yyyy-mm-dd] date, fix it manually");
return;
}
+ # 20230804 bkw: to avoid 2 instances of this script fighting each other when
+ # they're using different mirrors (where one mirror hasn't yet updated but
+ # the other one has), make sure $new_date actually is new.
+ my $topic_date = $1;
+ if($new_date lt $topic_date) {
+ debugmsg("new_date $new_date is older than topic_date $topic_date, ignoring");
+ return;
+ }
+
# Don't do anything if the topic's already correct.
if($t eq $chan->{topic}) {
debugmsg("topic already correct, not doing anything");