static volatile int timer_tick;
static struct timeval start_time;
static int ticks_per_sec;
static volatile int timer_tick;
static struct timeval start_time;
static int ticks_per_sec;
#if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ > 0
/* glibc 2.1 or newer -> has lseek64 */
#if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ > 0
/* glibc 2.1 or newer -> has lseek64 */
if (long_seek(mem_fd, addr, SEEK_SET) < 0)
die("long_seek(mem): %m");
remains = read(mem_fd, end, l);
if (remains < 0)
die("read(mem): %m");
if (!remains)
if (long_seek(mem_fd, addr, SEEK_SET) < 0)
die("long_seek(mem): %m");
remains = read(mem_fd, end, l);
if (remains < 0)
die("read(mem): %m");
if (!remains)
signal_int(int unused UNUSED)
{
/* Interrupts are fatal, so no synchronization requirements. */
signal_int(int unused UNUSED)
{
/* Interrupts are fatal, so no synchronization requirements. */
timeradd(&rus.ru_utime, &rus.ru_stime, &total);
total_ms = total.tv_sec*1000 + total.tv_usec/1000;
gettimeofday(&now, NULL);
timersub(&now, &start_time, &wall);
wall_ms = wall.tv_sec*1000 + wall.tv_usec/1000;
if (timeout && total_ms > timeout)
timeradd(&rus.ru_utime, &rus.ru_stime, &total);
total_ms = total.tv_sec*1000 + total.tv_usec/1000;
gettimeofday(&now, NULL);
timersub(&now, &start_time, &wall);
wall_ms = wall.tv_sec*1000 + wall.tv_usec/1000;
if (timeout && total_ms > timeout)
fprintf(stderr, "OK (%d.%03d sec real, %d.%03d sec wall, %d syscalls)\n",
(int) total.tv_sec, (int) total.tv_usec/1000,
(int) wall.tv_sec, (int) wall.tv_usec/1000,
fprintf(stderr, "OK (%d.%03d sec real, %d.%03d sec wall, %d syscalls)\n",
(int) total.tv_sec, (int) total.tv_usec/1000,
(int) wall.tv_sec, (int) wall.tv_usec/1000,
- log(">> Syscall %3ld (%08lx,%08lx,%08lx) ", u.regs.orig_eax, u.regs.ebx, u.regs.ecx, u.regs.edx);
- syscall_count++;
- if (!valid_syscall(&u))
+ msg(">> Syscall %3ld (%08lx,%08lx,%08lx) ", u.regs.orig_eax, u.regs.ebx, u.regs.ecx, u.regs.edx);
+ if (!exec_seen)
+ {
+ msg("[master] ");
+ if (u.regs.orig_eax == __NR_execve)
+ exec_seen = 1;
+ }
+ else if (valid_syscall(&u))
+ syscall_count++;
+ else
u.regs.orig_eax = 0xffffffff;
if (ptrace(PTRACE_SETREGS, box_pid, NULL, &u) < 0)
die("ptrace(PTRACE_SETREGS): %m");
u.regs.orig_eax = 0xffffffff;
if (ptrace(PTRACE_SETREGS, box_pid, NULL, &u) < 0)
die("ptrace(PTRACE_SETREGS): %m");
ptrace(PTRACE_SYSCALL, box_pid, 0, 0);
}
else if (sig != SIGSTOP && sig != SIGXCPU && sig != SIGXFSZ)
{
ptrace(PTRACE_SYSCALL, box_pid, 0, 0);
}
else if (sig != SIGSTOP && sig != SIGXCPU && sig != SIGXFSZ)
{
ptrace(PTRACE_SYSCALL, box_pid, 0, sig);
}
else
ptrace(PTRACE_SYSCALL, box_pid, 0, sig);
}
else
rl.rlim_cur = rl.rlim_max = 64;
if (setrlimit(RLIMIT_NOFILE, &rl) < 0)
die("setrlimit: %m");
rl.rlim_cur = rl.rlim_max = 64;
if (setrlimit(RLIMIT_NOFILE, &rl) < 0)
die("setrlimit: %m");
- if (filter_syscalls && ptrace(PTRACE_TRACEME) < 0)
- die("ptrace(PTRACE_TRACEME): %m");
+ if (filter_syscalls)
+ {
+ if (ptrace(PTRACE_TRACEME) < 0)
+ die("ptrace(PTRACE_TRACEME): %m");
+ /* Trick: Make sure that we are stopped until the boxkeeper wakes up. */
+ signal(SIGCHLD, SIG_IGN);
+ raise(SIGCHLD);
+ }
execve(args[0], args, (pass_environ ? environ : env));
die("execve(\"%s\"): %m", args[0]);
}
execve(args[0], args, (pass_environ ? environ : env));
die("execve(\"%s\"): %m", args[0]);
}