Skip to content

Commit

Permalink
Refactored snoopy enabling/disabling:
Browse files Browse the repository at this point in the history
- moved snoopy-enable.sh into snoopy-enable
- created snoopy-disable
- both are now installed in sbin/
- snoopy path is now hardcoded into them at ./configure time
- added 'make disable' option
- 'make uninstall' now also executes 'make disable'
- configure.ac: require sed
- configure.ac: added some AC_SUBST macros that are required by features listed above
  • Loading branch information
bostjan committed Oct 30, 2014
1 parent 2797551 commit 719afbc
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Makefile
.deps
.libs
/src/libsnoopy.so
/bin/snoopy-disable
/bin/snoopy-enable
/bin/snoopy-test-all-inputs
/bin/snoopy-test-output
/bin/snoopy-detect
Expand Down
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ o Feature: Implemented internal filtering, with the following filters available:
o Feature: Added optional support for INI configuration file
o Feature: Added envp data to intputdatastorage if execve() is used. Prepared
for future inputs to consume it.
o Feature: Created snoopy-enable and snoopy-disable system scripts.

o Refactoring: Separated data gathering into separate functions, to be
used at will - now they are called "input providers"
Expand All @@ -46,6 +47,7 @@ o Refactoring: created proper initialization/shutdown methods
o Documentation: added into about writing new input providers
o Bugfix: fixed compilation failure on debian in inputs/cwd.c (thanks Sébastien Gross)
o Bugfix: missing snoopy.ini in distribution tarball (thanks Jeremy Brown)
o Bugfix: When uninstalling, also disable snoopy (remove from /etc/ld.so.preload).


2013-04-06 - Version 1.9.0
Expand Down
16 changes: 13 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src bin etc

EXTRA_DIST +=\
autogen.sh \
bin/snoopy-enable.sh
autogen.sh

enable: install
$(top_srcdir)/bin/snoopy-enable.sh $(libdir)
echo ; \
$(top_srcdir)/bin/snoopy-enable ; \
echo ;

disable:
echo ; \
$(top_srcdir)/bin/snoopy-disable \
echo ;

# Disable it if we are uninstalling it, to avoid error messages
# about missing library that should be preloaded.
uninstall-local: disable
9 changes: 9 additions & 0 deletions bin/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
AM_CFLAGS = -I$(top_srcdir)/src



### Scripts to enable/disable snoopy
#
sbin_SCRIPTS = \
snoopy-enable \
snoopy-disable



### Test programs
#
# Some development/testing programs here
Expand Down
44 changes: 44 additions & 0 deletions bin/snoopy-disable.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh



# This is a script that disables system-wide snoopy installation.
# You have to run this script as a privileged user.
# This script is also run when you execute "make disable".



### Where is the library installed?
#
LIBDIR="@SNOOPY_LIBDIR@"



### Check user that is running this script
#
touch /etc/ld.so.preload
if [ ! -w /etc/ld.so.preload ]; then
echo
echo 'SNOOPY ERROR: /etc/ld.so.preload not writable - are you running this script as a unprivileged user?'
echo
exit 1
fi



### Do the actual installation
#
COUNT=`grep -Ec "/(lib)?snoopy.so" /etc/ld.so.preload`
if [ "$COUNT" -gt "1" ]; then
echo
echo "SNOOPY ERROR: Multiple instances of (lib)snoopy.so found in /etc/ld.so.preload. Unable to proceed."
echo
exit 1
elif [ "$COUNT" -eq "1" ]; then
echo -n "SNOOPY: Removing from /etc/ld.so.preload: "
cat /etc/ld.so.preload | grep -E "/(lib)?snoopy.so"
sed -i "/\/\(lib\)\?snoopy.so/d" /etc/ld.so.preload
echo "SNOOPY: Disabled."
else
echo "SNOOPY: Snoopy is NOT enabled on this system."
fi
25 changes: 8 additions & 17 deletions bin/snoopy-enable.sh → bin/snoopy-enable.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@

### Where is the library installed?
#
LIBDIR=$1
if [ "x$LIBDIR" = "x" ]; then
echo "ERROR: No argument given, libdir expected"
exit 1
fi
LIBDIR="@SNOOPY_LIBDIR@"



### Check snoopy installation
#
if [ ! -x $LIBDIR/libsnoopy.so ]; then
echo
echo "ERROR: $LIBDIR/libsnoopy.so is not installed or is not executable"
echo "SNOOPY ERROR: $LIBDIR/libsnoopy.so is not installed or is not executable"
echo
exit 1
fi
Expand All @@ -34,7 +30,7 @@ fi
touch /etc/ld.so.preload
if [ ! -w /etc/ld.so.preload ]; then
echo
echo 'ERROR: /etc/ld.so.preload not writable - are you running this script as a unprivileged user?'
echo 'SNOOPY ERROR: /etc/ld.so.preload not writable - are you running this script as a unprivileged user?'
echo
exit 1
fi
Expand All @@ -43,23 +39,18 @@ fi

### Do the actual installation
#
echo "ENABLE:"
COUNT=`grep -Ec "/(lib)?snoopy.so" /etc/ld.so.preload`
if [ "$COUNT" -gt "1" ]; then
echo
echo "ERROR: Multiple instances of (lib)snoopy.so found in /etc/ld.so.preload. Unable to proceed."
echo "SNOOPY ERROR: Multiple instances of (lib)snoopy.so found in /etc/ld.so.preload. Unable to proceed."
echo
exit 1
elif [ "$COUNT" -eq "1" ]; then
echo -n "ENABLE: Removing from /etc/ld.so.preload: "
echo -n "SNOOPY: Removing from /etc/ld.so.preload: "
cat /etc/ld.so.preload | grep -E "/(lib)?snoopy.so"
sed -i "/\/\(lib\)\?snoopy.so/d" /etc/ld.so.preload
fi
echo "ENABLE: Adding to /etc/ld.so.preload: $LIBDIR/libsnoopy.so"
echo "SNOOPY: Adding to /etc/ld.so.preload: $LIBDIR/libsnoopy.so"
echo "$LIBDIR/libsnoopy.so" >> /etc/ld.so.preload
echo "ENABLE:"
echo "ENABLE: SUCCESS!"
echo "ENABLE:"
echo "ENABLE: Snoopy is now added to /etc/ld.so.preload, which means it is enabled."
echo "ENABLE: Check your syslog files for output."
echo "ENABLE:"
echo "SNOOPY: Hint: check your syslog files for output."
echo "SNOOPY: Enabled."
13 changes: 13 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PROG_SED

dnl Checks for libraries.
dnl FIXME: Replace `main' with a function in `-ldl':
Expand All @@ -46,6 +47,16 @@ AC_CHECK_FUNCS([ \
strtol \
])

dnl Substitute these variables when creating (Make)files below - GENERIC
AC_SUBST([PREFIX])
AC_SUBST([SYSCONFDIR])

dnl Substitute these variables when creating (Make)files below - CUSTOM
dnl $libdir contains '${exec_prefix}' if not specified as ./configure --libdir=...
dnl ${exec_prefix} contains 'NONE' if not specified as ./configure --exec-prefix=...
SNOOPY_LIBDIR="`eval echo ${libdir} | sed -e s/^NONE/$prefix/ | sed -e s@^NONE@/usr/local@`"
AC_SUBST([SNOOPY_LIBDIR])

dnl Generate these (Make)files
AC_CONFIG_FILES([Makefile
bin/Makefile
Expand All @@ -55,6 +66,8 @@ AC_CONFIG_FILES([Makefile
src/lib/Makefile
src/filter/Makefile
src/input/Makefile])
AC_CONFIG_FILES([bin/snoopy-disable], [chmod +x bin/snoopy-disable])
AC_CONFIG_FILES([bin/snoopy-enable], [chmod +x bin/snoopy-enable])



Expand Down

0 comments on commit 719afbc

Please sign in to comment.