Skip to content
Snippets Groups Projects
  • Karel Kočí's avatar
    3d9bd73e
    utils: fix check_pid_path to work with deleted file as well · 3d9bd73e
    Karel Kočí authored
    
    check_pid_patch is checking if process with given PID and executable
    path is running. If this code fails the rest of the code can be
    convinced that program is no longer running and possibly spawns new
    instance that can collide with already running one. This behavior was
    reproduced with hostapd.
    
    Symbolic link exe in process subdirectory in /proc points to original
    executable. The problem is that it reads as original path plus string
    ' (deleted)' if file is removed. The process is still running but
    original file is no longer available on files system.
    
    This behavior is triggered not only when file is removed (unlinked) but
    also when file is replaced. This happens clearly on package update. In
    general this happens any time all references (hard links) to file are
    removed from file system.
    
    This is not ultimate fix as exe link points to any last reference on
    file system with preference for original one. The problem is if there
    are multiple references and the original one is removed. This can be
    reproduced just by copying executable (hard linking) and unlinking the
    original one. In such case exe link would point to copy and not to
    original deleted one.
    
    Signed-off-by: default avatarKarel Kočí <karel.koci@nic.cz>
    3d9bd73e
    History
    utils: fix check_pid_path to work with deleted file as well
    Karel Kočí authored
    
    check_pid_patch is checking if process with given PID and executable
    path is running. If this code fails the rest of the code can be
    convinced that program is no longer running and possibly spawns new
    instance that can collide with already running one. This behavior was
    reproduced with hostapd.
    
    Symbolic link exe in process subdirectory in /proc points to original
    executable. The problem is that it reads as original path plus string
    ' (deleted)' if file is removed. The process is still running but
    original file is no longer available on files system.
    
    This behavior is triggered not only when file is removed (unlinked) but
    also when file is replaced. This happens clearly on package update. In
    general this happens any time all references (hard links) to file are
    removed from file system.
    
    This is not ultimate fix as exe link points to any last reference on
    file system with preference for original one. The problem is if there
    are multiple references and the original one is removed. This can be
    reproduced just by copying executable (hard linking) and unlinking the
    original one. In such case exe link would point to copy and not to
    original deleted one.
    
    Signed-off-by: default avatarKarel Kočí <karel.koci@nic.cz>