diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2016-03-05 19:49:08 +0100 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2016-03-05 19:49:08 +0100 |
commit | 76be3c7c47ace843ab3ebd216252c63411a1222e (patch) | |
tree | 5fbea96acdc8dba73d5ef4ba218fc45fe630b61d /pullimap | |
parent | 0c21fadd7683629c50d1068106b17e9ac1addc62 (diff) |
Ensure the FD_CLOEXEC bit is 1 on sockets, logger and state files.
Diffstat (limited to 'pullimap')
-rwxr-xr-x | pullimap | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -25,7 +25,7 @@ our $VERSION = '0.3'; my $NAME = 'pullimap'; use Errno 'EINTR'; -use Fcntl qw/O_CREAT O_RDWR O_DSYNC LOCK_EX SEEK_SET/; +use Fcntl qw/O_CREAT O_RDWR O_DSYNC LOCK_EX SEEK_SET F_GETFL F_SETFL FD_CLOEXEC/; use Getopt::Long qw/:config posix_default no_ignore_case gnu_getopt auto_version/; use List::Util 'first'; use Socket qw/PF_INET PF_INET6 SOCK_STREAM/; @@ -82,6 +82,9 @@ do { } sysopen($STATE, $statefile, O_CREAT|O_RDWR|O_DSYNC, 0600) or die "Can't open $statefile: $!"; + my $flags = fcntl($STATE, F_GETFL, 0) or die "fcntl F_GETFL: $!"; + fcntl($STATE, F_SETFL, $flags | FD_CLOEXEC) or die "fcntl F_SETFL: $!"; + flock($STATE, LOCK_EX) or die "Can't flock $statefile: $!"; @@ -90,6 +93,8 @@ do { require 'Time/HiRes.pm'; open $LOGGER_FD, '>>', $logfile or die "Can't open $logfile: $!\n"; $LOGGER_FD->autoflush(1); + my $flags = fcntl($LOGGER_FD, F_GETFL, 0) or die "fcntl F_GETFL: $!"; + fcntl($LOGGER_FD, F_SETFL, $flags | FD_CLOEXEC) or die "fcntl F_SETFL: $!"; } elsif ($CONFIG{debug}) { $LOGGER_FD = \*STDERR; @@ -253,7 +258,7 @@ sub pull(;$) { writeUID($uid); }, @$ignore); - # terminate the transmission channel gracefully, cf RFC 5321 section 4.5.3.2 + # terminate the SMTP transmission channel gracefully, cf RFC 5321 section 4.5.3.2 smtp_send('QUIT' => '221') if defined $SMTP; undef $SMTP; |