From f044fcc4c818e228f5d563d15feebaa627d05f80 Mon Sep 17 00:00:00 2001 From: Zdenek Styblik Date: Sat, 13 Jul 2024 20:02:48 +0200 Subject: [PATCH 1/7] Use format in printf instead of variable --- iibot-ng | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iibot-ng b/iibot-ng index a9518cd..abc101d 100755 --- a/iibot-ng +++ b/iibot-ng @@ -25,7 +25,7 @@ monitor() continue fi # strip < and >. if msg is by ourself ignore it - nick=$(printf -- "${nick}" | sed -e 's@^<@@' | sed -e 's@>$@@') + nick=$(printf -- "%s" "${nick}" | sed -e 's@^<@@' | sed -e 's@>$@@') if [ "${nick}" = "${nickname}" ]; then continue fi @@ -78,7 +78,7 @@ monitor_link() remove_lock() { if [ -n "${pids}" ]; then - printf -- "${pids}" | xargs kill || true + printf -- "%s" "${pids}" | xargs kill || true fi rmdir "${LOCK_DIR}" } From 66a6aeadccc4957080ca46005fbb792341bf2d57 Mon Sep 17 00:00:00 2001 From: Zdenek Styblik Date: Sat, 13 Jul 2024 20:08:35 +0200 Subject: [PATCH 2/7] Use double quotes around IRC_CONFIG variable --- iibot-ng | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iibot-ng b/iibot-ng index abc101d..a1ad9d0 100755 --- a/iibot-ng +++ b/iibot-ng @@ -89,7 +89,7 @@ LOCK_DIR="/tmp/${IRC_CONFIG_NAME}.lock" if [ ! -r "${IRC_CONFIG}" ]; then printf "Config file '%s' doesn't exist or is not readable.\n" \ - ${IRC_CONFIG} 1>&2 + "${IRC_CONFIG}" 1>&2 exit 2 fi From 16e1b6d4e337846bca2c580987fc687dd1160671 Mon Sep 17 00:00:00 2001 From: Zdenek Styblik Date: Sat, 13 Jul 2024 20:14:38 +0200 Subject: [PATCH 3/7] Use double quotes in tail args just to be safe --- iibot-ng | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iibot-ng b/iibot-ng index a1ad9d0..06ce7c3 100755 --- a/iibot-ng +++ b/iibot-ng @@ -17,7 +17,7 @@ set -u monitor() { local iipid="${1}" - tail -f -n1 --pid=${iipid} "${ircdir}/${network}/${channel}/out" | \ + tail -f -n1 --pid="${iipid}" "${ircdir}/${network}/${channel}/out" | \ # NOTE: format of output changed in v1.8 while read -r nixtime nick msg; do # if msg is by the system ignore it @@ -65,7 +65,7 @@ monitor_link() local iipid=${1} IFS=' ' - tail -f -n1 --pid=${iipid} "${ircdir}/${network}/out" | \ + tail -f -n1 --pid="${iipid}" "${ircdir}/${network}/out" | \ while read -r response; do if printf -- "%s" "${response}" | grep -q -i -e 'Closing Link' -E -e "${nickname}.*ping timeout"; then printf "Killing bot.\n" 1>&2 From 30178043e1cb3e9a5d4e8f04ac4d44146f9a018b Mon Sep 17 00:00:00 2001 From: Zdenek Styblik Date: Sat, 13 Jul 2024 20:21:55 +0200 Subject: [PATCH 4/7] Read file contents with cat instead of bashism ... somewhere along the way, I've either missed this or checkbashism did. --- iibot-ng | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iibot-ng b/iibot-ng index 06ce7c3..920b2d9 100755 --- a/iibot-ng +++ b/iibot-ng @@ -143,7 +143,7 @@ pids=$(printf -- "%s %s" "${pids}" $!) # auth to services if [ -e "${ircdir}/${network}/ident" ]; then printf -- "/j nickserv identify %s\n" \ - "$(<"${ircdir}/${network}/ident")" > "${ircdir}/${network}/in" + "$(cat "${ircdir}/${network}/ident")" > "${ircdir}/${network}/in" fi # clean that up - ident passwd is in there rm -f "${ircdir}/${network}/nickserv/out" From 4c313e94b17683d660fb8a6cf6cbc2e175a2ff7c Mon Sep 17 00:00:00 2001 From: Zdenek Styblik Date: Sat, 13 Jul 2024 22:54:13 +0200 Subject: [PATCH 5/7] Use double quotes when assigning fn arg into variable --- iibot-ng | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iibot-ng b/iibot-ng index 920b2d9..9475fef 100755 --- a/iibot-ng +++ b/iibot-ng @@ -62,7 +62,7 @@ monitor() monitor_link() { - local iipid=${1} + local iipid="${1}" IFS=' ' tail -f -n1 --pid="${iipid}" "${ircdir}/${network}/out" | \ From b5a324c7ab99299d3a11119b7d9e57b05e1c8c14 Mon Sep 17 00:00:00 2001 From: Zdenek Styblik Date: Sat, 13 Jul 2024 22:59:03 +0200 Subject: [PATCH 6/7] Cleanup channel's "in" file before trying to join It might(and it did) happen that channel's "in" wasn't pipe, but file. This might be because something is "stale", ii got killed and couldn't cleanup or bug in iibot-ng. We do this with main "in" pipe(file), I see no reason why we couldn't do it for channels as well. --- iibot-ng | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iibot-ng b/iibot-ng index 9475fef..a9c6260 100755 --- a/iibot-ng +++ b/iibot-ng @@ -151,10 +151,11 @@ rm -f "${ircdir}/${network}/nickserv/out" sleep 3 # join channels for channel in $(printf -- "%s" "${net_conf}" | awk -F':' '{ print $3 }'); do - printf -- "/j %s\n" "${channel}" > "${ircdir}/${network}/in" + rm -f "${ircdir}/${network}/${channel}/in" if [ ! -e "${ircdir}/${network}/${channel}/out" ]; then touch "${ircdir}/${network}/${channel}/out" fi + printf -- "/j %s\n" "${channel}" > "${ircdir}/${network}/in" monitor "${pid}" & pids=$(printf -- "%s %s" "${pids}" $!) done From a0a07df869fcc366a9acf137d47499c2618014ce Mon Sep 17 00:00:00 2001 From: Zdenek Styblik Date: Sun, 14 Jul 2024 09:04:31 +0200 Subject: [PATCH 7/7] Exit instead of continue if we didn't get "in" pipe after 60s Commit increases wait-on-connection time from 15 to 60 seconds. Also, if we didn't get "in" pipe after 60 seconds, exit. Because if we don't exit, we end up with files instead of pipes. It's possible that wait-on-connection timeout will have to be adjusted further. --- iibot-ng | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/iibot-ng b/iibot-ng index a9c6260..a305c29 100755 --- a/iibot-ng +++ b/iibot-ng @@ -132,8 +132,15 @@ time_slept=0 while ! test -p "${ircdir}/${network}/in"; do sleep 1 time_slept=$((time_slept + 1)) - if [ ${time_slept} -ge 15 ]; then - break + if [ ${time_slept} -ge 60 ]; then + # We either didn't get the connection or something went wrong -> crash. + # + # NOTE(zstyblik): we cannot continue without pipe. If we do, then it + # looks like we will end up with files instead of pipes(which is bad). + # This doesn't mean that pipe cannot go away later, but still. + printf "Pipe '%s' still does not exist - giving up.\n" \ + "${ircdir}/${network}/in" 1>&2 + exit 1 fi done