summaryrefslogtreecommitdiff
path: root/.config/wmii-hg/workarounds.sh
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-02-27 18:31:31 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-02-27 20:06:11 -0500
commit5e5e5029e76d88b3887bb175e28709a9022323a8 (patch)
treeeb77f3f626988f6592a6d51b2e08914f290b896b /.config/wmii-hg/workarounds.sh
parentc2ee55d77f093d7a5abf8118870900b866dbba52 (diff)
X11 systemd stuff
Diffstat (limited to '.config/wmii-hg/workarounds.sh')
-rw-r--r--.config/wmii-hg/workarounds.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/.config/wmii-hg/workarounds.sh b/.config/wmii-hg/workarounds.sh
new file mode 100644
index 0000000..b3d50fe
--- /dev/null
+++ b/.config/wmii-hg/workarounds.sh
@@ -0,0 +1,42 @@
+#!/hint/bash
+
+##
+# Just like systemd-notify(1), but slower, which is a shitty
+# workaround for a race condition in systemd.
+##
+systemd-notify() {
+ local args
+ args="$(getopt -n systemd-notify -o h -l help,version,ready,pid::,status:,booted -- "$@")"
+ ret=$?; [[ $ret == 0 ]] || return $ret
+ eval set -- "$args"
+
+ local arg_ready=false
+ local arg_pid=0
+ local arg_status=
+ while [[ $# -gt 0 ]]; do
+ case "$1" in
+ -h|--help) command systemd-notify --help; return $?;;
+ --version) command systemd-notify --version; return $?;;
+ --ready) arg_ready=true; shift 1;;
+ --pid) arg_pid=${2:-$$}; shift 2;;
+ --status) arg_status=$2; shift 2;;
+ --booted) command systemd-notify --booted; return $?;;
+ --) shift 1; break;;
+ esac
+ done
+
+ local our_env=()
+ if $arg_ready; then
+ our_env+=("READY=1")
+ fi
+ if [[ -n "$arg_status" ]]; then
+ our_env+=("STATUS=$arg_status")
+ fi
+ if [[ "$arg_pid" -gt 0 ]]; then
+ our_env+=("MAINPID=$arg_pid")
+ fi
+ our_env+=("$@")
+ local n
+ printf -v n '%s\n' "${our_env[@]}"
+ socat STDIO UNIX-SENDTO:"$NOTIFY_SOCKET" <<<"$n"
+}