summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-02-07 18:30:10 -0500
committerJesse Luehrs <doy@tozt.net>2022-02-07 19:03:15 -0500
commitea190d359288e3b4db7d8f34afce7829c7378fbb (patch)
treecf9b74c30f2a39083fd6a651c9a47bd586fcf815
parentd70bb7647d322ab904cbd8834d41c94f7f01ecb2 (diff)
downloadconf-ea190d359288e3b4db7d8f34afce7829c7378fbb.tar.gz
conf-ea190d359288e3b4db7d8f34afce7829c7378fbb.zip
more refactoring
-rwxr-xr-xbin/mbsyncloop15
1 files changed, 13 insertions, 2 deletions
diff --git a/bin/mbsyncloop b/bin/mbsyncloop
index 0da9179..15480cb 100755
--- a/bin/mbsyncloop
+++ b/bin/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
+}