]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/Daemon.pm
bump version to 8.2.1
[pve-common.git] / src / PVE / Daemon.pm
index 905635a70046f4690ed7c1d9c0ac890b526c157d..63fd5eed29195d8f07f8400e2a066481347df448 100644 (file)
@@ -114,10 +114,10 @@ my $writepidfile = sub {
 
     my $pidfile = $self->{pidfile};
 
-    die "can't open pid file '$pidfile' - $!\n" if !open (PIDFH, ">$pidfile");
+    open (my $PID_FH, '>', "$pidfile") or die "can't open pid file '$pidfile' - $!\n";
 
-    print PIDFH "$$\n";
-    close (PIDFH);
+    print $PID_FH "$$\n";
+    close ($PID_FH);
 };
 
 my $server_cleanup = sub {
@@ -243,8 +243,7 @@ sub setup {
 
     initlog($self->{name});
 
-    my $restart = $ENV{RESTART_PVE_DAEMON};
-    delete $ENV{RESTART_PVE_DAEMON};
+    my $restart = delete $ENV{RESTART_PVE_DAEMON};
     $self->{env_restart_pve_daemon} = $restart;
 
     my $lockfd = $ENV{PVE_DAEMON_LOCK_FD};
@@ -311,8 +310,8 @@ my $server_run = sub {
     $self->init();
 
     if (!$debug) {
-       open STDIN,  '</dev/null' || die "can't read /dev/null";
-       open STDOUT, '>/dev/null' || die "can't write /dev/null";
+       open STDIN,  '<', '/dev/null' or die "can't read /dev/null - $!";
+       open STDOUT, '>', '/dev/null' or die "can't write /dev/null - $!";
     }
 
     if (!$self->{env_restart_pve_daemon} && !$debug) {
@@ -573,7 +572,6 @@ my $read_pid = sub {
 
 # checks if the process was started by systemd
 my $init_ppid = sub {
-
     if (getppid() == 1) {
        return 1;
     } else {
@@ -819,15 +817,23 @@ sub create_reusable_socket {
        $socket->fcntl(Fcntl::F_SETFD(), Fcntl::FD_CLOEXEC);
     } else {
 
-       $socket = IO::Socket::IP->new(
-           Domain => PF_INET6,
-           LocalHost => $host,
+       my %sockargs = (
            LocalPort => $port,
            Listen => SOMAXCONN,
            Proto  => 'tcp',
            GetAddrInfoFlags => 0,
-           ReuseAddr => 1) ||
-           die "unable to create socket - $@\n";
+           ReuseAddr => 1,
+       );
+       if (defined($host)) {
+           $socket = IO::Socket::IP->new( LocalHost => $host, %sockargs) ||
+               die "unable to create socket - $@\n";
+       } else {
+           # disabling AF_INET6 (by adding ipv6.disable=1 to the kernel cmdline)
+           # causes bind on :: to fail, try 0.0.0.0 in that case
+           $socket = IO::Socket::IP->new( LocalHost => '::', %sockargs) //
+               IO::Socket::IP->new( LocalHost => '0.0.0.0', %sockargs);
+           die "unable to create socket - $@\n" if !$socket;
+       }
 
        # we often observe delays when using Nagle algorithm,
        # so we disable that to maximize performance