From 510ffbdbebe6b2a5f145da459994fc4dbe4fec02 Mon Sep 17 00:00:00 2001 From: Salt Date: Fri, 21 Jun 2019 19:09:46 -0500 Subject: [PATCH] Clean up README, add exit status table, add more error handling --- README.md | 14 +++++++++++++- firestarter | 15 +++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 627217e..707c08a 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ By setting a dummy execution line, one can effectively prevent an entire configu command -v lemonbar ~/.bin/lemonbar.sh | lemonbar -After all these programs have been started, the last thing firestarter does is execute `~/.firestarterrc`, if it exists. +After all these programs have been started, firestarter executes `~/.firestarterrc` if it exists. # Logging @@ -36,6 +36,18 @@ All STDOUT and STDERR messages from these commands are saved to a logfile in `~/ If you set the variable `FS_NOLOG` to a nonempty value, firestarter will not keep logs. +# Exit Codes + +| code | meaning | +| --: | --- | +| 0 | Success | +| 40 | Firestarter is already running | +| 50 | Unrecognized argument | +| 51 | Invalid option for an argument | +| 52 | Failed to create configuration directory | +| 53 | Failed to create logging directory (and logging is enabled) | +| 54 | `HOME` does not exist or is unreadable | + ## Contribution Firestarter by no means contains an exhaustive list of all possible programs. If you know of or have created a program that should be added, *please* open an issue about it. The script should be light but its choices massive. diff --git a/firestarter b/firestarter index 17a1fc4..de4018b 100755 --- a/firestarter +++ b/firestarter @@ -12,6 +12,7 @@ _name="firestarter" _configdir="${XDG_CONFIG_HOME:-$HOME/.config}/$_name" _logdir="${XDG_DATA_HOME:-$HOME/.local/share}/$_name/logs" _firestarterrc="$HOME/.firestarterrc" +_sessionid="$(< /proc/self/sessionid)" # Basic functions print() { @@ -279,11 +280,18 @@ EOF step_check() { if [ -z "$_dryrun" ]; then for pid in $(pgrep firestarter); do + # Skip invalid PIDs + ! [ -d "/proc/$pid" ] && continue + # If it's not our session then who cares + [ "$_sessionid" != "$(< "/proc/$pid/sessionid")" ] && continue if [ "$pid" != "$BASHPID" ]; then - err "Firestarter is already running" 61 + err "Firestarter is already running" 40 fi done fi + if ! [ -d "$HOME" ] || ! [ -r "$HOME" ]; then + err "Inaccessible home directory: \"$HOME\"" 54 + fi return 0 } step_preexecute() { @@ -422,9 +430,8 @@ step_logout() { log "Logging out" if command -v loginctl > /dev/null 2>&1; then # Use loginctl if possible - local sessionid="$(< /proc/self/sessionid)" - if [ -n "$sessionid" ]; then - loginctl terminate-session "$sessionid" + if [ -n "$_sessionid" ]; then + loginctl terminate-session "$_sessionid" fi else # Otherwise just brute it