Skip to content

Commit

Permalink
Merge remote-tracking branch 'ccl/pull/1252/head'
Browse files Browse the repository at this point in the history
* ccl/pull/1252/head:
  Do readlink on final exe path component.
  Add test case for cooperative-computing-lab#930.
  • Loading branch information
Patrick Donnelly committed Apr 11, 2016
2 parents 223d834 + 0685b0e commit b6f7b36
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
21 changes: 20 additions & 1 deletion parrot/src/pfs_dispatch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern "C" {
#include "int_sizes.h"
#include "macros.h"
#include "memfdexe.h"
#include "path.h"
#include "pattern.h"
#include "stringtools.h"
#include "tracer.h"
Expand Down Expand Up @@ -936,6 +937,22 @@ static void decode_execve( struct pfs_process *p, int entering, INT64_T syscall,
p->set_gid = p->egid;

tracer_copy_in_string(p->tracer,logical_name,POINTER(args[0]),sizeof(logical_name),0);

{
char buf[PATH_MAX] = "";
if(pfs_readlink(logical_name, buf, sizeof buf - 1) > 0) {
if (buf[0] == '/') {
snprintf(logical_name, sizeof logical_name, "%s", buf);
} else {
char *sep = strrchr(logical_name, '/');
if (!sep) {
sep = logical_name;
}
snprintf(sep, sizeof logical_name - (size_t)(sep-logical_name), "/%s", buf);
}
}
}

strncpy(p->new_logical_name, logical_name, sizeof(p->new_logical_name)-1);
p->exefd = -1;

Expand Down Expand Up @@ -997,7 +1014,9 @@ static void decode_execve( struct pfs_process *p, int entering, INT64_T syscall,

p->completing_execve = 0;
if (actual == 0) {
p->table->complete_at_path(AT_FDCWD, p->new_logical_name, p->name);
char path[PATH_MAX];
p->table->complete_at_path(AT_FDCWD, p->new_logical_name, path);
path_collapse(path, p->name, 1);
debug(D_PROCESS, "execve: %s (%s) succeeded in 32-bit mode", p->new_logical_name, p->name);
/* Undo "syscall_args_changed = 1" because execve returns multiple results in syscall argument registers. */
p->syscall_args_changed = 0;
Expand Down
21 changes: 20 additions & 1 deletion parrot/src/pfs_dispatch64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extern "C" {
#include "debug.h"
#include "int_sizes.h"
#include "macros.h"
#include "path.h"
#include "pattern.h"
#include "stringtools.h"
#include "tracer.h"
Expand Down Expand Up @@ -761,6 +762,22 @@ static void decode_execve( struct pfs_process *p, int entering, INT64_T syscall,
p->set_gid = p->egid;

tracer_copy_in_string(p->tracer,logical_name,POINTER(args[0]),sizeof(logical_name),0);

{
char buf[PATH_MAX] = "";
if(pfs_readlink(logical_name, buf, sizeof buf - 1) > 0) {
if (buf[0] == '/') {
snprintf(logical_name, sizeof logical_name, "%s", buf);
} else {
char *sep = strrchr(logical_name, '/');
if (!sep) {
sep = logical_name;
}
snprintf(sep, sizeof logical_name - (size_t)(sep-logical_name), "/%s", buf);
}
}
}

strncpy(p->new_logical_name, logical_name, sizeof(p->new_logical_name)-1);
p->exefd = -1;

Expand Down Expand Up @@ -822,7 +839,9 @@ static void decode_execve( struct pfs_process *p, int entering, INT64_T syscall,

p->completing_execve = 0;
if (actual == 0) {
p->table->complete_at_path(AT_FDCWD, p->new_logical_name, p->name);
char path[PATH_MAX];
p->table->complete_at_path(AT_FDCWD, p->new_logical_name, path);
path_collapse(path, p->name, 1);
debug(D_PROCESS, "execve: %s (%s) succeeded in 64-bit mode", p->new_logical_name, p->name);
/* Undo "syscall_args_changed = 1" because execve returns multiple results in syscall argument registers. */
p->syscall_args_changed = 0;
Expand Down
26 changes: 26 additions & 0 deletions parrot/test/TR_parrot_procexe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

set -ex

. ../../dttools/test/test_runner_common.sh
. ./parrot-test.sh

prepare()
{
cp "$(which find)" find || return 1
ln -sf ./find lfind || return 1
}

run()
{
[ "$(parrot ./lfind /proc/self/exe -printf %l)" = "$(./lfind /proc/self/exe -printf %l)" ] || return 1
}

clean()
{
rm -f find lfind
}

dispatch "$@"

# vim: set noexpandtab tabstop=4:

0 comments on commit b6f7b36

Please sign in to comment.