diff options
author | Krytarik Raido <krytarik@tuxgarage.com> | 2019-07-17 02:34:04 +0200 |
---|---|---|
committer | Krytarik Raido <krytarik@tuxgarage.com> | 2019-07-17 02:34:04 +0200 |
commit | 182615555cd57567c53919b31d41aec8aee4e1fd (patch) | |
tree | 6c81a1c32bc94418b4479c8c415817715c4d2c6a | |
parent | 96702ad68c5ba1061a54273ff8a4eda548682604 (diff) | |
download | mini-dinstall-182615555cd57567c53919b31d41aec8aee4e1fd.tar.bz2 mini-dinstall-182615555cd57567c53919b31d41aec8aee4e1fd.tar.xz mini-dinstall-182615555cd57567c53919b31d41aec8aee4e1fd.tar.zst |
Add error handling on empty PID file.
Closes: #894890
-rwxr-xr-x | mini-dinstall | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/mini-dinstall b/mini-dinstall index f0f8ce4..a777b27 100755 --- a/mini-dinstall +++ b/mini-dinstall @@ -265,12 +265,21 @@ def process_exists(pid): return True if os.access(lockfilename, os.R_OK): - pid = int(open(lockfilename).read()) - if not process_exists(pid): + pid = open(lockfilename).read() + error = '' + if not pid: + error = "Lockfile present but empty; use mini-dinstall -k to remove it" + warn = "Lockfile present but empty, removing it" + else: + pid = int(pid) + if not process_exists(pid): + error = "No process running at %d; use mini-dinstall -k to remove lockfile" % pid + warn = "No process running at %d, removing lockfile" % pid + if error: if run_mode: - logger.error("No process running at %d; use mini-dinstall -k to remove lockfile") + logger.error(error) sys.exit(1) - logger.warn("No process running at %d, removing lockfile" % pid) + logger.warn(warn) os.unlink(lockfilename) if kill_mode: sys.exit(0) |