Skip to content

Commit

Permalink
bug when copying the shell files for missions 29 and 30
Browse files Browse the repository at this point in the history
when no compiler is found, the shell file were copied with a
shebang of "#!/usr/bin/env bash", so that their names wasn't used by ps.
(Instead, the processes appeared with a name of "bash")
  • Loading branch information
phyver committed Dec 10, 2024
1 parent bad0ecf commit be7a7ed
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion missions/processes/00_shared/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ _mission_init() (
"$GSH_TMP/test-proc-name" &
PID=$!
name=$(my_ps $PID | grep $PID | grep -v sh | grep "test-proc-name")
# kill -9 $PID
kill -9 $PID
if [ -z "$name" ]
then
echo "$(eval_gettext "Process names should be equal to the corresponding filename for mission \$MISSION_NAME.")" >&2
Expand Down
8 changes: 6 additions & 2 deletions missions/processes/01_ps_kill/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ _install_script() (
fi
mission_source "$MISSION_DIR/deps.sh" || return 1

cp "$MISSION_DIR/spell.sh" "$GSH_TMP/$(gettext "spell")"
chmod 755 "$GSH_TMP/$(gettext "spell")"
# make sure the shebang for the spell.sh script is a real path to sh
# otherwise, ps will not use the filename as the process name...
sh=$(command -v sh)
echo "#! $sh" > "$GSH_TMP/$(gettext "spell")"
cat "$MISSION_DIR/spell.sh" >> "$GSH_TMP/$(gettext "spell")"
chmod +x "$GSH_TMP/$(gettext "spell")"
)

if _compile || _install_script
Expand Down
11 changes: 7 additions & 4 deletions missions/processes/02_ps_kill_signal/init.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env sh

_compile() (

if command -v gcc >/dev/null
then
CC=gcc
Expand Down Expand Up @@ -59,9 +58,13 @@ _install_script() (
return 1
fi
mission_source "$MISSION_DIR/deps.sh" || return 1
cp "$MISSION_DIR/spell.sh" "$GSH_TMP/$(gettext "spell")"
chmod 755 "$GSH_TMP/$(gettext "spell")"

#
# make sure the shebang for the spell.sh script is a real path to sh
# otherwise, ps will not use the filename as the process name...
sh=$(command -v sh)
echo "#! $sh" > "$GSH_TMP/$(gettext "spell")"
cat "$MISSION_DIR/spell.sh" >> "$GSH_TMP/$(gettext "spell")"
chmod +x "$GSH_TMP/$(gettext "spell")"
)

if _compile || _install_script
Expand Down
9 changes: 4 additions & 5 deletions missions/processes/03_pstree_kill/init.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env sh

_compile() (

if ! command -v pstree >/dev/null
then
echo "$(eval_gettext "The command 'pstree' is required for mission \$MISSION_NAME.
Expand Down Expand Up @@ -81,21 +80,21 @@ _install_script() (

echo "#! $sh" > "$GSH_TMP/$(gettext "nice_fairy")"
cat "$MISSION_DIR/nice_fairy.sh" >> "$GSH_TMP/$(gettext "nice_fairy")"
chmod 755 "$GSH_TMP/$(gettext "nice_fairy")"
chmod +x "$GSH_TMP/$(gettext "nice_fairy")"

mkdir -p "$GSH_TMP/fairy/"
echo "#! $sh" > "$GSH_TMP/fairy/$(gettext "spell")"
cat "$MISSION_DIR/fairy/spell.sh" >> "$GSH_TMP/fairy/$(gettext "spell")"
chmod 755 "$GSH_TMP/fairy/$(gettext "spell")"
chmod +x "$GSH_TMP/fairy/$(gettext "spell")"

echo "#! $sh" > "$GSH_TMP/$(gettext "mischievous_imp")"
cat "$MISSION_DIR/mischievous_imp.sh" >> "$GSH_TMP/$(gettext "mischievous_imp")"
chmod 755 "$GSH_TMP/$(gettext "mischievous_imp")"
chmod +x "$GSH_TMP/$(gettext "mischievous_imp")"

mkdir -p "$GSH_TMP/imp/"
echo "#! $sh" > "$GSH_TMP/imp/$(gettext "spell")"
cat "$MISSION_DIR/imp/spell.sh" >> "$GSH_TMP/imp/$(gettext "spell")"
chmod 755 "$GSH_TMP/imp/$(gettext "spell")"
chmod +x "$GSH_TMP/imp/$(gettext "spell")"
)


Expand Down

0 comments on commit be7a7ed

Please sign in to comment.