diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-02-07 18:30:10 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-02-07 19:03:15 -0500 |
commit | 1f354aad891c7a372c96f1a7004d260baf5b580f (patch) | |
tree | 9a61283fc3fa701a208159daa83099bdd494114f | |
parent | 476b1f43d073cc14f132198726aa453661e9d932 (diff) | |
download | mbsyncloop-1f354aad891c7a372c96f1a7004d260baf5b580f.tar.gz mbsyncloop-1f354aad891c7a372c96f1a7004d260baf5b580f.zip |
more refactoring
-rwxr-xr-x | mbsyncloop | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -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 +} |