Skip to content

Commit

Permalink
pnp: fix race condition in mkdir
Browse files Browse the repository at this point in the history
if multiple worker try to create the rrd folder at the same time, there will be an error.
  • Loading branch information
sni committed Feb 28, 2023
1 parent c81a285 commit 868f423
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/pnp4nagios/patches/205-improve-mkdir.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--- a/scripts/process_perfdata.pl.in 2023-02-28 15:22:09.112254795 +0100
+++ b/scripts/process_perfdata.pl.in 2023-02-28 15:25:47.864254899 +0100
@@ -28,6 +28,7 @@
use strict;
use POSIX;
use Getopt::Long;
+use File::Path qw(make_path);
use Time::HiRes qw(gettimeofday tv_interval);
use vars qw ( $TEMPLATE %NAGIOS $t0 $t1 $rt $delayed_write $rrdfile @ds_create $count $line $name $ds_update $dstype %CTPL);

@@ -429,20 +430,11 @@
$NAGIOS{MULTI_PARENT} = $data[0]{multi_parent} || "";
$TEMPLATE = $data[0]{template};

- unless ( -d "$conf{RRDPATH}" ) {
- unless ( mkdir "$conf{RRDPATH}" ) {
- print_log( "mkdir $conf{RRDPATH}, permission denied ", 1 );
- print_log( "PNP exiting ...", 1 );
- exit 5;
- }
- }
-
+ make_path($conf{RRDPATH}."/".$NAGIOS{HOSTNAME});
unless ( -d "$conf{RRDPATH}/$NAGIOS{HOSTNAME}" ) {
- unless ( mkdir "$conf{RRDPATH}/$NAGIOS{HOSTNAME}" ) {
- print_log( "mkdir $conf{RRDPATH}/$NAGIOS{HOSTNAME}, permission denied ", 1 );
- print_log( "PNP exiting ...", 1 );
- exit 6;
- }
+ print_log( "mkdir $conf{RRDPATH}/$NAGIOS{HOSTNAME}: ".$!, 1 );
+ print_log( "PNP exiting ...", 1 );
+ exit 6;
}

#

0 comments on commit 868f423

Please sign in to comment.