Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If lock fails, details should be included in the error message #1824

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/lib/Sympa/Aliases/Template.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright 2017, 2018 The Sympa Community. See the AUTHORS.md file at the
# top-level directory of this distribution and at
# Copyright 2017, 2018, 2024 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
#
# This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -101,7 +101,8 @@ sub add {
# Create a lock
my $lock_fh;
unless ($lock_fh = Sympa::LockedFile->new($alias_file, 20, '+>>')) {
$log->syslog('err', 'Can\'t lock %s', $alias_file);
$log->syslog('err', 'Can\'t lock %s: %s',
$alias_file, Sympa::LockedFile->last_error);
return undef;
}

Expand Down Expand Up @@ -168,7 +169,8 @@ sub del {
# Create a lock
my $lock_fh;
unless ($lock_fh = Sympa::LockedFile->new($alias_file, 20, '+<')) {
$log->syslog('err', 'Can\'t lock %s', $alias_file);
$log->syslog('err', 'Can\'t lock %s: %s',
$alias_file, Sympa::LockedFile->last_error);
return undef;
}

Expand Down
35 changes: 27 additions & 8 deletions src/lib/Sympa/List.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
# Copyright 2017, 2018, 2019, 2020, 2021, 2022 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
# Copyright 2017, 2018, 2019, 2020, 2021, 2022, 2024 The Sympa Community.
# See the AUTHORS.md file at the top-level directory of this distribution
# and at <https://github.com/sympa-community/sympa.git>.
#
# 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
Expand Down Expand Up @@ -364,7 +364,11 @@ sub update_stats {

my $lock_fh = Sympa::LockedFile->new($self->{'dir'} . '/stats', 2, '+>>');
unless ($lock_fh) {
$log->syslog('err', 'Could not create new lock');
$log->syslog(
'err',
'Could not create new lock: %s',
Sympa::LockedFile->last_error
);
return;
}

Expand Down Expand Up @@ -552,7 +556,11 @@ sub save_config {
## Lock file
my $lock_fh = Sympa::LockedFile->new($config_file_name, 5, '+<');
unless ($lock_fh) {
$log->syslog('err', 'Could not create new lock');
$log->syslog(
'err',
'Could not create new lock: %s',
Sympa::LockedFile->last_error
);
return undef;
}

Expand Down Expand Up @@ -675,7 +683,11 @@ sub load {
my $lock_fh =
Sympa::LockedFile->new($self->{'dir'} . '/config', 5, '<');
unless ($lock_fh) {
$log->syslog('err', 'Could not create new lock');
$log->syslog(
'err',
'Could not create new lock: %s',
Sympa::LockedFile->last_error
);
return undef;
}

Expand Down Expand Up @@ -704,7 +716,11 @@ sub load {
my $lock_fh =
Sympa::LockedFile->new($self->{'dir'} . '/config', 5, '+<');
unless ($lock_fh) {
$log->syslog('err', 'Could not create new lock');
$log->syslog(
'err',
'Could not create new lock: %s',
Sympa::LockedFile->last_error
);
return undef;
}

Expand Down Expand Up @@ -5033,7 +5049,10 @@ sub _load_list_config_file {
## Lock file
my $lock_fh = Sympa::LockedFile->new($config_file, 5, '<');
unless ($lock_fh) {
$log->syslog('err', 'Could not create new lock on %s', $config_file);
$log->syslog(
'err', 'Could not create new lock on %s: %s',
$config_file, Sympa::LockedFile->last_error
);
return undef;
}

Expand Down
29 changes: 18 additions & 11 deletions src/lib/Sympa/Process.pm
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4
# $Id$

# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright (c) 1997, 1998, 1999 Institut Pasteur & Christophe Wolfhugel
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
# Copyright 2024 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
#
# 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
Expand Down Expand Up @@ -237,8 +239,8 @@ sub remove_pid {
# Lock pid file
my $lock_fh = Sympa::LockedFile->new($pidfile, 5, '+<');
unless ($lock_fh) {
$log->syslog('err', 'Could not open %s to remove PID %s',
$pidfile, $pid);
$log->syslog('err', 'Could not open %s to remove PID %s: %s',
$pidfile, $pid, Sympa::LockedFile->last_error);
return undef;
}

Expand Down Expand Up @@ -306,7 +308,7 @@ sub write_pid {
group => Sympa::Constants::GROUP,
)
) {
die sprintf 'Unable to set rights on %s. Exiting.', $piddir;
die sprintf 'Unable to set rights on %s: %s', $piddir, $ERRNO;
## No return
}

Expand All @@ -315,8 +317,8 @@ sub write_pid {
# Lock pid file
my $lock_fh = Sympa::LockedFile->new($pidfile, 5, '+>>');
unless ($lock_fh) {
die sprintf 'Unable to lock %s file in write mode. Exiting.',
$pidfile;
die sprintf 'Unable to lock %s file in write mode: %s',
$pidfile, Sympa::LockedFile->last_error;
}
## If pidfile exists, read the PIDs
if (-s $pidfile) {
Expand Down Expand Up @@ -348,9 +350,10 @@ sub write_pid {

seek $lock_fh, 0, 0;
unless (truncate $lock_fh, 0) {
## Unlock pid file
my $errno = $ERRNO;
# Unlock pid file
$lock_fh->close();
die sprintf 'Could not truncate %s, exiting.', $pidfile;
die sprintf 'Could not truncate %s: %s', $pidfile, $errno;
}

print $lock_fh $pid . "\n";
Expand All @@ -363,9 +366,10 @@ sub write_pid {
group => Sympa::Constants::GROUP,
)
) {
## Unlock pid file
my $errno = $ERRNO;
# Unlock pid file
$lock_fh->close();
die sprintf 'Unable to set rights on %s', $pidfile;
die sprintf 'Unable to set rights on %s: %s', $pidfile, $errno;
}
## Unlock pid file
$lock_fh->close();
Expand Down Expand Up @@ -445,7 +449,10 @@ sub _get_pids_in_pid_file {

my $lock_fh = Sympa::LockedFile->new($pidfile, 5, '<');
unless ($lock_fh) {
$log->syslog('err', 'Unable to open PID file %s: %m', $pidfile);
$log->syslog(
'err', 'Unable to open PID file %s: %s',
$pidfile, Sympa::LockedFile->last_error
);
return;
}
my $l = <$lock_fh>;
Expand Down
10 changes: 6 additions & 4 deletions src/lib/Sympa/Request/Handler/update_automatic_list.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright 2018, 2019, 2020 The Sympa Community. See the AUTHORS.md
# file at the top-level directory of this distribution and at
# Copyright 2018, 2019, 2020, 2024 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
#
# This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -148,8 +148,10 @@ sub _twist {
## Lock config before openning the config file
my $lock_fh = Sympa::LockedFile->new($list->{'dir'} . '/config', 5, '>');
unless ($lock_fh) {
$log->syslog('err', 'Impossible to create %s/config: %s',
$list->{'dir'}, $ERRNO);
$log->syslog(
'err', 'Impossible to create %s/config: %s',
$list->{'dir'}, Sympa::LockedFile->last_error
);
$self->add_stash($request, 'intern');
return undef;
}
Expand Down
Loading