From 1f354aad891c7a372c96f1a7004d260baf5b580f Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 7 Feb 2022 18:30:10 -0500 Subject: more refactoring --- mbsyncloop | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mbsyncloop b/mbsyncloop index 0da9179..15480cb 100755 --- a/mbsyncloop +++ b/mbsyncloop @@ -3,6 +3,7 @@ use 5.016; use strict; use warnings; +use File::Spec; use POSIX 'mkfifo'; my $password_command = "rbw get mail.tozt.net doy\@tozt.net"; @@ -26,8 +27,7 @@ sub cleanup { $SIG{INT} = $SIG{TERM} = sub { cleanup; exit }; END { cleanup } -$pw_pipe = "/run/user/$>/mbsyncloop"; -mkfifo($pw_pipe, 0700) or die "couldn't create $pw_pipe: $!"; +$pw_pipe = make_pw_pipe(); $pid = fork; die "fork failed: $!" unless defined $pid; @@ -81,3 +81,14 @@ sub idle { } return 0; } + +sub make_pw_pipe { + my $dir = "/run/user/$>"; + if (!-d $dir) { + $dir = File::Spec->tmpdir(); + } + my $file = File::Spec->catfile($dir, "mbsyncloop-$$"); + unlink($file); + mkfifo($file, 0700) or die "couldn't create $file: $!"; + $file +} -- cgit v1.2.3-54-g00ecf