Skip to content

Commit

Permalink
removed need to 'sudo setcap' on DT executable
Browse files Browse the repository at this point in the history
  • Loading branch information
carterscottm committed Oct 26, 2018
1 parent b968ffd commit 646f4aa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
3 changes: 3 additions & 0 deletions pack/df_linux/distro_fixes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ if [ -n "$ZLIB_PATH" ]; then
dlog INFO "Attempting to use zlib at $ZLIB_PATH"
fi

# Include set_ptracer_any.so in PRELOAD_LIB to remove the necessity to run setcap on the Dwarf Therapist executable
export PRELOAD_LIB="${PRELOAD_LIB:+$PRELOAD_LIB:}./libs/set_ptracer_any.so"

dlog "INFO" "PRELOAD_LIB: $PRELOAD_LIB"
dlog "INFO" "LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
dlog "INFO" "Done"
12 changes: 12 additions & 0 deletions pack/df_linux/libs/set_ptracer_any.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/prctl.h>

void set_ptracer_any() __attribute__((constructor));

void set_ptracer_any()
{
if (-1 == prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0))
perror("prctl");
}
Binary file added pack/df_linux/libs/set_ptracer_any.so
Binary file not shown.
15 changes: 0 additions & 15 deletions pack/startlnp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,5 @@ if [ ! -d df_linux ]; then
echo "working directory: $(pwd)"
fi

gcap="$(whereis -b getcap | cut -f2 -d":" | tr -d " ")"
scap="$(whereis -b setcap | cut -f2 -d":" | tr -d " ")"

if [ -x $gcap ] && [ -x $scap ]; then
#Check whether Dwarf Therapist can read from DF memory:
dt_capabilities=$($gcap LNP/utilities/dwarf_therapist/dwarftherapist |cut -f2 -d"="|tr -d " ")
dt_capabilities=${dt_capabilities:=0}
if [ ${dt_capabilities} != "cap_sys_ptrace+eip" ]; then
msg="Enable Dwarf Therapist to read from Dwarf Fortress memory"
xterm -e "echo $msg;sudo $scap cap_sys_ptrace=eip LNP/utilities/dwarf_therapist/dwarftherapist"
fi
else
warn "Could not find getcap and/or setcap"
fi

#run Lazy Newb Pack
./PyLNP "$@" || warn "Failed to start PyLNP"

1 comment on commit 646f4aa

@carterscottm
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source code provided by Clément in the below forum post.

http://www.bay12forums.com/smf/index.php?topic=168411.msg7742913#msg7742913

Please sign in to comment.