Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
/src/server/autom4te.cache
/src/client/autom4te.cache
/src/fe/autom4te.cache

.vscode
.idea/
tags

#Need if someone does an in-source configure/build
Expand Down Expand Up @@ -34,5 +35,3 @@ run_driver
run_driver_rm
preload_file_list
build

.idea/
3 changes: 3 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H

/* ld.so exports the _dl_argv variable */
#undef HAVE_DL_ARGV

/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H

Expand Down
27 changes: 27 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -17290,6 +17290,33 @@ _ACEOF

fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking wheter ld.so has the _dl_argv variable" >&5
$as_echo_n "checking wheter ld.so has the _dl_argv variable... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
extern char **_dl_argv;
int
main ()
{
(void) _dl_argv;
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
HAVE_DL_ARGV="true";{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
if test "x$HAVE_DL_ARGV" == "xtrue"; then

$as_echo "#define HAVE_DL_ARGV 1" >>confdefs.h

fi

#Usage logging

Expand Down
8 changes: 7 additions & 1 deletion configure.common.ac
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,13 @@ if test "x$HAVE_NUMA" == "xtrue"; then
AC_DEFINE_UNQUOTED([NUMA_EXCLUDES], "[$NUMA_EXCLUDES_VAL]", [Exclusions for numa optimization])
fi


AC_MSG_CHECKING([wheter ld.so has the _dl_argv variable])
AC_LINK_IFELSE([AC_LANG_PROGRAM([extern char **_dl_argv;], [(void) _dl_argv;])],
[HAVE_DL_ARGV="true";AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
if test "x$HAVE_DL_ARGV" == "xtrue"; then
AC_DEFINE([HAVE_DL_ARGV], [1], [ld.so exports the _dl_argv variable])
fi

#Usage logging
AC_ARG_WITH(usage-logging,
[AS_HELP_STRING([--with-usage-logging=FILE],[File for writing usage logs])],
Expand Down
15 changes: 0 additions & 15 deletions src/client/auditclient/auditclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,8 @@ unsigned int spindle_la_objopen(struct link_map *map, Lmid_t lmid, uintptr_t *co
{
(void)lmid;
(void)cookie;
char buffer[4096];
char *exe_name, *exe_name2;

restore_pathpatch();
patch_on_linkactivity(map);
memset(buffer, 0, sizeof(buffer));
readlink("/proc/self/exe", buffer, sizeof(buffer));
exe_name = strrchr(buffer, '/');
if (exe_name)
exe_name++;
else
exe_name = buffer;
if (strstr(exe_name, "spindlens")) {
exe_name2 = strrchr(exe_name, '-');
if (exe_name2)
exe_name = exe_name2 + 1;
}
return LA_FLG_BINDTO | LA_FLG_BINDFROM;
}

Expand Down
5 changes: 3 additions & 2 deletions src/client/beboot/spindle_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static char *client_lib;
static char *opts_s;
static char **daemon_args;
static char *cachesize_s;
static char *executable_abspath;

opt_t opts;

Expand Down Expand Up @@ -231,7 +232,7 @@ static void get_executable()
}

debug_printf2("Sending request for executable %s\n", *cmdline);
exec_pathsearch(ldcsid, *cmdline, &executable, &errcode);
exec_pathsearch(ldcsid, *cmdline, &executable, &errcode, &executable_abspath);

if (executable == NULL) {
executable = *cmdline;
Expand All @@ -256,7 +257,7 @@ static void adjust_script()
if (!executable)
return;

result = adjust_if_script(*cmdline, executable, cmdline, &new_executable, &new_cmdline);
result = adjust_if_script(*cmdline, executable, cmdline, &new_executable, &new_cmdline, executable_abspath);
if (result != 0)
return;

Expand Down
2 changes: 1 addition & 1 deletion src/client/client/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/../logging -I$(top_srcdir)/client_comlib -I$(top_s

INTERCEPT_SRCS = intercept_open.c intercept_exec.c intercept_stat.c intercept_readlink.c intercept_spindleapi.c intercept.c spindle_regex.c patch_interception.c realpath.c $(top_srcdir)/../utils/fileutil.c

BASE_SRCS = client.c lookup.c should_intercept.c exec_util.c remap_exec.c lookup_libc.c $(top_srcdir)/../utils/parseloc.c $(top_srcdir)/../utils/getcpu.c
BASE_SRCS = client.c lookup.c should_intercept.c exec_util.c remap_exec.c lookup_libc.c $(top_srcdir)/../utils/parseloc.c $(top_srcdir)/../utils/getcpu.c adjust_argv.c

libspindlec_socket_la_SOURCES = $(BASE_SRCS)
libspindlec_socket_la_LIBADD = $(top_builddir)/client_comlib/libclient_socket.la $(top_builddir)/logging/libspindleclogc.la $(top_builddir)/shm_cache/libshmcache.la
Expand Down
10 changes: 7 additions & 3 deletions src/client/client/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ libspindlec_biter_la_DEPENDENCIES = \
am__objects_2 = client.lo lookup.lo should_intercept.lo exec_util.lo \
remap_exec.lo lookup_libc.lo \
$(top_builddir)/../utils/parseloc.lo \
$(top_builddir)/../utils/getcpu.lo
$(top_builddir)/../utils/getcpu.lo adjust_argv.lo
am_libspindlec_biter_la_OBJECTS = $(am__objects_2)
libspindlec_biter_la_OBJECTS = $(am_libspindlec_biter_la_OBJECTS)
@BITER_TRUE@am_libspindlec_biter_la_rpath =
Expand Down Expand Up @@ -173,7 +173,8 @@ am__maybe_remake_depfiles = depfiles
am__depfiles_remade = $(top_builddir)/../utils/$(DEPDIR)/getcpu.Plo \
$(top_builddir)/../utils/$(DEPDIR)/libspindle_audit_la-fileutil.Plo \
$(top_builddir)/../utils/$(DEPDIR)/parseloc.Plo \
./$(DEPDIR)/client.Plo ./$(DEPDIR)/exec_util.Plo \
./$(DEPDIR)/adjust_argv.Plo ./$(DEPDIR)/client.Plo \
./$(DEPDIR)/exec_util.Plo \
./$(DEPDIR)/libspindle_audit_la-intercept.Plo \
./$(DEPDIR)/libspindle_audit_la-intercept_exec.Plo \
./$(DEPDIR)/libspindle_audit_la-intercept_open.Plo \
Expand Down Expand Up @@ -376,7 +377,7 @@ noinst_LTLIBRARIES = libspindle_audit.la $(am__append_1) \
AM_CFLAGS = -fvisibility=hidden
AM_CPPFLAGS = -I$(top_srcdir)/../logging -I$(top_srcdir)/client_comlib -I$(top_srcdir)/../include -I$(top_srcdir)/shm_cache -I$(top_srcdir)/subaudit -I$(top_srcdir)/../utils -I$(top_srcdir)/auditclient
INTERCEPT_SRCS = intercept_open.c intercept_exec.c intercept_stat.c intercept_readlink.c intercept_spindleapi.c intercept.c spindle_regex.c patch_interception.c realpath.c $(top_srcdir)/../utils/fileutil.c
BASE_SRCS = client.c lookup.c should_intercept.c exec_util.c remap_exec.c lookup_libc.c $(top_srcdir)/../utils/parseloc.c $(top_srcdir)/../utils/getcpu.c
BASE_SRCS = client.c lookup.c should_intercept.c exec_util.c remap_exec.c lookup_libc.c $(top_srcdir)/../utils/parseloc.c $(top_srcdir)/../utils/getcpu.c adjust_argv.c
libspindlec_socket_la_SOURCES = $(BASE_SRCS)
libspindlec_socket_la_LIBADD = $(top_builddir)/client_comlib/libclient_socket.la $(top_builddir)/logging/libspindleclogc.la $(top_builddir)/shm_cache/libshmcache.la
libspindlec_pipe_la_SOURCES = $(BASE_SRCS)
Expand Down Expand Up @@ -468,6 +469,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@$(top_builddir)/../utils/$(DEPDIR)/getcpu.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@$(top_builddir)/../utils/$(DEPDIR)/libspindle_audit_la-fileutil.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@$(top_builddir)/../utils/$(DEPDIR)/parseloc.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/adjust_argv.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/client.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exec_util.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libspindle_audit_la-intercept.Plo@am__quote@ # am--include-marker
Expand Down Expand Up @@ -721,6 +723,7 @@ distclean: distclean-am
-rm -f $(top_builddir)/../utils/$(DEPDIR)/getcpu.Plo
-rm -f $(top_builddir)/../utils/$(DEPDIR)/libspindle_audit_la-fileutil.Plo
-rm -f $(top_builddir)/../utils/$(DEPDIR)/parseloc.Plo
-rm -f ./$(DEPDIR)/adjust_argv.Plo
-rm -f ./$(DEPDIR)/client.Plo
-rm -f ./$(DEPDIR)/exec_util.Plo
-rm -f ./$(DEPDIR)/libspindle_audit_la-intercept.Plo
Expand Down Expand Up @@ -784,6 +787,7 @@ maintainer-clean: maintainer-clean-am
-rm -f $(top_builddir)/../utils/$(DEPDIR)/getcpu.Plo
-rm -f $(top_builddir)/../utils/$(DEPDIR)/libspindle_audit_la-fileutil.Plo
-rm -f $(top_builddir)/../utils/$(DEPDIR)/parseloc.Plo
-rm -f ./$(DEPDIR)/adjust_argv.Plo
-rm -f ./$(DEPDIR)/client.Plo
-rm -f ./$(DEPDIR)/exec_util.Plo
-rm -f ./$(DEPDIR)/libspindle_audit_la-intercept.Plo
Expand Down
79 changes: 79 additions & 0 deletions src/client/client/adjust_argv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
This file is part of Spindle. For copyright information see the COPYRIGHT
file in the top level directory, or at
https://github.com/hpc/Spindle/blob/master/COPYRIGHT

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (as published by the Free Software
Foundation) version 2.1 dated February 1999. This program is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY; without even the IMPLIED
WARRANTY OF MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms
and conditions of the GNU Lesser General Public License for more details. You should
have received a copy of the GNU Lesser General Public License along with this
program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "config.h"
#include "client_api.h"
#include "client.h"

extern int is_in_spindle_cache(const char *pathname);
extern int ldcsid;

#if defined(HAVE_DL_ARGV)
extern char **_dl_argv;
static char **get_argv()
{
return _dl_argv;
}
#else
static char **get_argv()
{
return NULL;
}
#endif

static void do_adjust(int arg_i, char **argv)
{
int result;
char newpath[MAX_PATH_LEN+1], *s;

if (!argv[arg_i])
return;

debug_printf2("Checking if argv[%d] (%s) needs to be fixed up\n", arg_i, argv[0]);
if (!is_in_spindle_cache(argv[arg_i])) {
return;
}

newpath[0] = '\0';
result = send_orig_path_request(ldcsid, argv[arg_i], newpath);
if (result == -1) {
debug_printf("Warning, not adjusting argv because server communication failed\n");
return;
}

if (strlen(argv[arg_i]) > strlen(newpath)) {
strcpy(argv[arg_i], newpath);
debug_printf2("Replaced argv[%d] with %s in place\n", arg_i, newpath);
}
else {
s = strdup(newpath);
argv[arg_i] = s;
debug_printf2("Replaced argv[%d] with %s from heap\n", arg_i, s);
}
}

void adjust_argv_if_needed()
{
char **argv;

argv = get_argv();
if (!argv) {
return;
}

do_adjust(0, argv);
do_adjust(1, argv);
}
3 changes: 3 additions & 0 deletions src/client/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ char *orig_location;
number_t number;
static int have_stat_patches;

extern void adjust_argv_if_needed();

static char *concatStrings(const char *str1, const char *str2)
{
static char buffer[MAX_PATH_LEN+1];
Expand Down Expand Up @@ -380,6 +382,7 @@ int client_init()
{
remap_executable(ldcsid);
}
adjust_argv_if_needed();

if (opts & OPT_PATCHLDSO) {
result = init_intercept_ldso_stat();
Expand Down
37 changes: 24 additions & 13 deletions src/client/client/exec_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static int parse_interp_args(char *interp_line, char **interp_exec, char ***inte
}


int adjust_if_script(const char *orig_path, char *reloc_path, char **argv, char **interp_path, char ***new_argv)
int adjust_if_script(const char *orig_path, char *reloc_path, char **argv, char **interp_path, char ***new_argv, char *found_from_pathsearch)
{
int result, fd, argc, interp_argc, i, j, errcode;
char interpreter_line[MAX_PATH_LEN+1];
Expand All @@ -139,10 +139,10 @@ int adjust_if_script(const char *orig_path, char *reloc_path, char **argv, char

if (argv && argv[0] && strcmp(argv[0], orig_path) != 0) {
char *lastslash = strrchr(orig_path, '/');
if (lastslash && strcmp(lastslash+1, argv[0]) != 0) {
if (!lastslash || (lastslash && strcmp(lastslash+1, argv[0]) != 0)) {
debug_printf2("Not treating %s as a script because it's argv[0] (%s) is different than the executable, "
"and Spindle can't emulate that\n", orig_path, argv[0]);
return SCRIPT_NOTSCRIPT;
return SCRIPT_CANTEMULATE;
}
}
if (opts & OPT_REMAPEXEC) {
Expand Down Expand Up @@ -177,7 +177,7 @@ int adjust_if_script(const char *orig_path, char *reloc_path, char **argv, char
if (result == -1) {
return SCRIPT_ENOENT;
}

debug_printf2("Exec operation requesting interpreter %s for script %s\n", interpreter, orig_path);
get_relocated_file(ldcsid, interpreter, 1, &new_interpreter, &errcode, NULL);
debug_printf2("Changed interpreter %s to %s for script %s\n",
Expand All @@ -195,29 +195,34 @@ int adjust_if_script(const char *orig_path, char *reloc_path, char **argv, char
*new_argv = (char **) spindle_malloc(sizeof(char*) * (argc + interp_argc + 2));
j = 0;

for (i = 0; i < interp_argc; i++)
for (i = 0; i < interp_argc; i++) {
(*new_argv)[j++] = spindle_strdup(interpreter_args[i]);
/* If argv[0] is not a path, replace with absolute path to mimic kernel behavior */
char *orig_path_copy = strdup( orig_path ); /* Preserve constness of orig_path. */
(*new_argv)[j++] = (argv[0] && strchr(argv[0], '/')) ? argv[0] : orig_path_copy;
}

if (found_from_pathsearch) {
(*new_argv)[j++] = spindle_strdup(found_from_pathsearch);
}
else {
char *orig_path_copy = spindle_strdup( orig_path ); /* Preserve constness of orig_path. */
(*new_argv)[j++] = (argv[0] && strchr(argv[0], '/')) ? argv[0] : orig_path_copy;
}
for (i = 1; i < argc; i++) {
(*new_argv)[j++] = argv[i];
}
(*new_argv)[j++] = NULL;

*interp_path = new_interpreter;
debug_printf3("Rewritten interpreter cmdline is: ");
for (i = 0; i<argc+1; i++) {
bare_printf3("%s ", (*new_argv)[i]);
debug_printf3("Rewritten interpreter '%s' cmdline is: ", *interp_path ? *interp_path : "NULL");
for (i = 0; (*new_argv)[i]; i++) {
bare_printf3("%s ", (*new_argv)[i] ? (*new_argv)[i] : "NULL");
}
bare_printf3("\n");

spindle_free(interpreter_args);

return 0;
}

int exec_pathsearch(int ldcsid, const char *orig_exec, char **reloc_exec, int *errcode)
int exec_pathsearch(int ldcsid, const char *orig_exec, char **reloc_exec, int *errcode, char **orig_file_abspath)
{
char *saveptr = NULL, *path, *cur;
char newexec[MAX_PATH_LEN+1];
Expand All @@ -227,6 +232,9 @@ int exec_pathsearch(int ldcsid, const char *orig_exec, char **reloc_exec, int *e
*reloc_exec = NULL;
return -1;
}
if (orig_file_abspath) {
*orig_file_abspath = NULL;
}

if (orig_exec[0] == '/' || orig_exec[0] == '.') {
get_relocated_file(ldcsid, (char *) orig_exec, 1, reloc_exec, errcode, NULL);
Expand Down Expand Up @@ -273,6 +281,9 @@ int exec_pathsearch(int ldcsid, const char *orig_exec, char **reloc_exec, int *e
get_relocated_file(ldcsid, newexec, 1, reloc_exec, errcode, NULL);
debug_printf2("Exec search request returned %s -> %s\n", newexec, *reloc_exec ? *reloc_exec : "NULL");
if (*reloc_exec) {
if (orig_file_abspath) {
*orig_file_abspath = spindle_strdup(newexec);
}
found = 1;
break;
}
Expand Down
5 changes: 3 additions & 2 deletions src/client/client/exec_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
#define SCRIPT_ERR -1
#define SCRIPT_ENOENT -2
#define SCRIPT_NOTSCRIPT -3
#define SCRIPT_CANTEMULATE -4

int adjust_if_script(const char *orig_path, char *reloc_path, char **argv, char **interp_path, char ***new_argv);
int exec_pathsearch(int ldcsid, const char *orig_exec, char **new_exec, int *errcode);
int adjust_if_script(const char *orig_path, char *reloc_path, char **argv, char **interp_path, char ***new_argv, char *found_from_pathsearch);
int exec_pathsearch(int ldcsid, const char *orig_exec, char **new_exec, int *errcode, char **orig_file_abspath);
int isExecExcluded(const char *fname);
int get_dirlists(char ***prefixes, char ***eexecs);

Expand Down
Loading
Loading