remove rootlessport socket to prevent EADDRINUSE
When we restart a container via podman restart or restart policy the
rootlessport process fails with `address already in use` because the
socketfile still exists.
This is a regression and was introduced in commit abdedc31a2.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
			
			
This commit is contained in:
		
							parent
							
								
									0f3d3bd21d
								
							
						
					
					
						commit
						32424d9a9b
					
				| 
						 | 
					@ -218,6 +218,9 @@ outer:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// we only need to have a socket to reload ports when we run under rootless cni
 | 
						// we only need to have a socket to reload ports when we run under rootless cni
 | 
				
			||||||
	if cfg.RootlessCNI {
 | 
						if cfg.RootlessCNI {
 | 
				
			||||||
 | 
							socketfile := filepath.Join(socketDir, cfg.ContainerID)
 | 
				
			||||||
 | 
							// make sure to remove the file if it exists to prevent EADDRINUSE
 | 
				
			||||||
 | 
							_ = os.Remove(socketfile)
 | 
				
			||||||
		// workaround to bypass the 108 char socket path limit
 | 
							// workaround to bypass the 108 char socket path limit
 | 
				
			||||||
		// open the fd and use the path to the fd as bind argument
 | 
							// open the fd and use the path to the fd as bind argument
 | 
				
			||||||
		fd, err := unix.Open(socketDir, unix.O_PATH, 0)
 | 
							fd, err := unix.Open(socketDir, unix.O_PATH, 0)
 | 
				
			||||||
| 
						 | 
					@ -229,6 +232,8 @@ outer:
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		err = unix.Close(fd)
 | 
							err = unix.Close(fd)
 | 
				
			||||||
 | 
							// remove the socket file on exit
 | 
				
			||||||
 | 
							defer os.Remove(socketfile)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			logrus.Warnf("failed to close the socketDir fd: %v", err)
 | 
								logrus.Warnf("failed to close the socketDir fd: %v", err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue