Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 317341 | Differences between
and this patch

Collapse All | Expand All

(-)a/configure.ac (-1 / +15 lines)
Lines 74-79 AC_CHECK_HEADERS_ONCE([ \ Link Here
74
	execinfo.h \
74
	execinfo.h \
75
	fcntl.h \
75
	fcntl.h \
76
	grp.h \
76
	grp.h \
77
	kvm.h \
77
	libgen.h \
78
	libgen.h \
78
	limits.h \
79
	limits.h \
79
	memory.h \
80
	memory.h \
Lines 99-110 AC_CHECK_HEADERS_ONCE([ \ Link Here
99
	sys/reg.h \
100
	sys/reg.h \
100
	sys/stat.h \
101
	sys/stat.h \
101
	sys/syscall.h \
102
	sys/syscall.h \
103
	sys/sysctl.h \
102
	sys/time.h \
104
	sys/time.h \
103
	sys/types.h \
105
	sys/types.h \
104
	sys/user.h \
106
	sys/user.h \
105
	sys/wait.h \
107
	sys/wait.h \
106
	asm/ptrace.h \
108
	asm/ptrace.h \
107
	linux/ptrace.h \
109
	linux/ptrace.h \
110
	machine/reg.h \
108
])
111
])
109
112
110
dnl Checks for typedefs, structures, and compiler characteristics.
113
dnl Checks for typedefs, structures, and compiler characteristics.
Lines 119-125 AC_CHECK_TYPES([sighandler_t, sig_t, __sighandler_t],,,[#include <signal.h>]) Link Here
119
122
120
save_CPPFLAGS=$CPPFLAGS
123
save_CPPFLAGS=$CPPFLAGS
121
CPPFLAGS="-I$srcdir $CPPFLAGS"
124
CPPFLAGS="-I$srcdir $CPPFLAGS"
122
AC_CHECK_TYPES([struct user_regs_struct, struct pt_regs],,,[#include "headers.h"])
125
AC_CHECK_TYPES([struct user_regs_struct, struct pt_regs, struct reg],,,[#include "headers.h"])
123
CPPFLAGS=$save_CPPFLAGS
126
CPPFLAGS=$save_CPPFLAGS
124
127
125
dnl Checks for library functions.
128
dnl Checks for library functions.
Lines 180-185 AC_CHECK_LIB([sigsegv], [stackoverflow_install_handler], Link Here
180
	[HAVE_LIBSIGSEGV=false])
183
	[HAVE_LIBSIGSEGV=false])
181
AM_CONDITIONAL(HAVE_LIBSIGSEGV, $HAVE_LIBSIGSEGV)
184
AM_CONDITIONAL(HAVE_LIBSIGSEGV, $HAVE_LIBSIGSEGV)
182
185
186
have_libkvm="no"
187
AC_CHECK_LIB([kvm], [kvm_open],
188
	[have_libkvm="yes"],
189
	[have_libkvm="no"])
190
LIBKVM=""
191
if test "x$have_libkvm" = xyes ; then
192
	AC_DEFINE([HAVE_LIBKVM], [1], [libkvm is available])
193
	LIBKVM=-lkvm
194
fi
195
AC_SUBST(LIBKVM)
196
183
dnl Check for gcc atomic primitives
197
dnl Check for gcc atomic primitives
184
AC_MSG_CHECKING([for __sync_lock_test_and_set])
198
AC_MSG_CHECKING([for __sync_lock_test_and_set])
185
sltas=no
199
sltas=no
(-)a/headers.h (+9 lines)
Lines 32-37 Link Here
32
#ifdef HAVE_GRP_H
32
#ifdef HAVE_GRP_H
33
# include <grp.h>
33
# include <grp.h>
34
#endif
34
#endif
35
#ifdef HAVE_KVM_H
36
# include <kvm.h>
37
#endif
35
#ifdef HAVE_LIBGEN_H
38
#ifdef HAVE_LIBGEN_H
36
# include <libgen.h>
39
# include <libgen.h>
37
#endif
40
#endif
Lines 107-112 Link Here
107
#ifdef HAVE_SYS_SYSCALL_H
110
#ifdef HAVE_SYS_SYSCALL_H
108
# include <sys/syscall.h>
111
# include <sys/syscall.h>
109
#endif
112
#endif
113
#ifdef HAVE_SYS_SYSCTL_H
114
# include <sys/sysctl.h>
115
#endif
110
#ifdef HAVE_SYS_TIME_H
116
#ifdef HAVE_SYS_TIME_H
111
# include <sys/time.h>
117
# include <sys/time.h>
112
#endif
118
#endif
Lines 119-124 Link Here
119
#ifdef HAVE_SYS_WAIT_H
125
#ifdef HAVE_SYS_WAIT_H
120
# include <sys/wait.h>
126
# include <sys/wait.h>
121
#endif
127
#endif
128
#ifdef HAVE_MACHINE_REG_H
129
# include <machine/reg.h>
130
#endif
122
131
123
#ifdef __ia64__ /* what a pos */
132
#ifdef __ia64__ /* what a pos */
124
# define ia64_fpreg FU_ia64_fpreg
133
# define ia64_fpreg FU_ia64_fpreg
(-)a/libsandbox/Makefile.am (-1 / +1 lines)
Lines 14-20 libsandbox_la_CFLAGS = $(CFLAG_EXCEPTIONS) Link Here
14
#	$(top_builddir)/libsbutil/libsbutil.la
14
#	$(top_builddir)/libsbutil/libsbutil.la
15
libsandbox_la_LIBSBLIB = $(top_builddir)/libsbutil/.libs/libsbutil.a
15
libsandbox_la_LIBSBLIB = $(top_builddir)/libsbutil/.libs/libsbutil.a
16
libsandbox_la_LIBADD = \
16
libsandbox_la_LIBADD = \
17
	-lc $(LIBDL) \
17
	-lc $(LIBDL) $(LIBKVM) \
18
	$(libsandbox_la_LIBSBLIB)
18
	$(libsandbox_la_LIBSBLIB)
19
# Do not add -nostdlib or -nostartfiles, as then our constructor
19
# Do not add -nostdlib or -nostartfiles, as then our constructor
20
# and destructor will not be executed ...
20
# and destructor will not be executed ...
(-)a/libsandbox/libsandbox.c (-3 / +43 lines)
Lines 124-129 static const char *sb_get_fd_dir(void) Link Here
124
#endif
124
#endif
125
}
125
}
126
126
127
#ifdef HAVE_LIBKVM
128
static const char *sb_get_cmdline(pid_t pid)
129
{
130
	return "libkvm"; /* we will get the command line directly later via libkvm */
131
}
132
#else /* HAVE_LIBKVM */
127
static const char *sb_get_cmdline(pid_t pid)
133
static const char *sb_get_cmdline(pid_t pid)
128
{
134
{
129
#if !defined(SANDBOX_PROC_1_CMDLINE) && !defined(SANDBOX_PROC_SELF_CMDLINE) && !defined(SANDBOX_PROC_dd_CMDLINE)
135
#if !defined(SANDBOX_PROC_1_CMDLINE) && !defined(SANDBOX_PROC_SELF_CMDLINE) && !defined(SANDBOX_PROC_dd_CMDLINE)
Lines 135-140 static const char *sb_get_cmdline(pid_t pid) Link Here
135
	sprintf(path, "/proc/%i/cmdline", pid);
141
	sprintf(path, "/proc/%i/cmdline", pid);
136
	return path;
142
	return path;
137
}
143
}
144
#endif /* HAVE_LIBKVM */
138
145
139
int canonicalize(const char *path, char *resolved_path)
146
int canonicalize(const char *path, char *resolved_path)
140
{
147
{
Lines 358-364 char *egetcwd(char *buf, size_t size) Link Here
358
	return tmpbuf;
365
	return tmpbuf;
359
}
366
}
360
367
361
static int sb_copy_file_to_fd(const char *file, int ofd)
368
#ifdef HAVE_LIBKVM
369
static int sb_copy_file_or_pid_cmdline_to_fd(const char *file, pid_t pid, int ofd)
370
{
371
	int ret = -1;
372
	int cnt =  0;
373
	char **str;
374
375
	kvm_t *kt = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
376
	if (!kt)
377
		return ret;
378
379
	struct kinfo_proc *proc = kvm_getprocs(kt, KERN_PROC_PID | KERN_PROC_ALL, pid ? pid : getpid(), &cnt);
380
	if (!proc || !cnt)
381
		goto error;
382
383
	str = kvm_getargv(kt, proc, 0);
384
	if (!str)
385
		goto error;
386
387
	for (cnt = 0; str[cnt]; cnt++) {
388
		size_t len = strlen(str[cnt]);
389
		if (sb_write(ofd, str[cnt], len) != len)
390
			goto error;
391
		if (str[cnt+1] && sb_write(ofd, " ", 1) != 1)
392
			goto error;
393
	}
394
	ret = 0;
395
error:
396
	kvm_close(kt);
397
	return ret;
398
}
399
#else /* HAVE_LIBKVM */
400
static int sb_copy_file_or_pid_cmdline_to_fd(const char *file, pid_t pid, int ofd)
362
{
401
{
363
	int ret = -1;
402
	int ret = -1;
364
403
Lines 388-393 static int sb_copy_file_to_fd(const char *file, int ofd) Link Here
388
	free(buf);
427
	free(buf);
389
	return ret;
428
	return ret;
390
}
429
}
430
#endif /* HAVE_LIBKVM */
391
431
392
void sb_dump_backtrace(void)
432
void sb_dump_backtrace(void)
393
{
433
{
Lines 399-405 void sb_dump_backtrace(void) Link Here
399
#endif
439
#endif
400
	const char *cmdline = sb_get_cmdline(trace_pid);
440
	const char *cmdline = sb_get_cmdline(trace_pid);
401
	sb_printf("%s: ", cmdline);
441
	sb_printf("%s: ", cmdline);
402
	sb_copy_file_to_fd(cmdline, STDERR_FILENO);
442
	sb_copy_file_or_pid_cmdline_to_fd(cmdline, trace_pid, STDERR_FILENO);
403
	sb_printf("\n\n");
443
	sb_printf("\n\n");
404
}
444
}
405
445
Lines 493-499 static bool write_logfile(const char *logfile, const char *func, const char *pat Link Here
493
533
494
	_SB_WRITE_STR("\nC: ");
534
	_SB_WRITE_STR("\nC: ");
495
	const char *cmdline = sb_get_cmdline(trace_pid);
535
	const char *cmdline = sb_get_cmdline(trace_pid);
496
	if (sb_copy_file_to_fd(cmdline, logfd)) {
536
	if (sb_copy_file_or_pid_cmdline_to_fd(cmdline, trace_pid, logfd)) {
497
		_SB_WRITE_STR("unable to read ");
537
		_SB_WRITE_STR("unable to read ");
498
		_SB_WRITE_STR(cmdline);
538
		_SB_WRITE_STR(cmdline);
499
	}
539
	}
(-)a/localdecls.h (-1 / +2 lines)
Lines 67-72 typedef __sighandler_t sighandler_t; Link Here
67
typedef struct pt_regs trace_regs;
67
typedef struct pt_regs trace_regs;
68
#elif defined(HAVE_STRUCT_USER_REGS_STRUCT)
68
#elif defined(HAVE_STRUCT_USER_REGS_STRUCT)
69
typedef struct user_regs_struct trace_regs;
69
typedef struct user_regs_struct trace_regs;
70
#elif defined(HAVE_STRUCT_REG)
71
typedef struct reg trace_regs;
70
#else
72
#else
71
# error "unable to find struct for tracing regs"
73
# error "unable to find struct for tracing regs"
72
#endif
74
#endif
73
- 

Return to bug 317341