#include "syscall.h"
-#define NumElem(a) ((int)((sizeof (a))/((sizeof (a)[0]))))
-
#define MAXSELECTED 256 /* max number of "selected" paths */
static const char *selected[MAXSELECTED]; /* paths selected for tracing */
static int
pathmatch(const char *path)
{
- int i;
+ unsigned int i;
- for (i = 0; i < NumElem(selected); ++i)
- {
+ for (i = 0; i < ARRAY_SIZE(selected); ++i) {
if (selected[i] == NULL)
return 0;
if (!strcmp(path, selected[i]))
static int
upathmatch(struct tcb *tcp, unsigned long upath)
{
- char path[PATH_MAX + 1];
+ char path[PATH_MAX + 1];
return umovestr(tcp, upath, sizeof path, path) == 0 &&
pathmatch(path);
static int
storepath(const char *path)
{
- int i;
+ unsigned int i;
- if (path == NULL)
- {
- for (i = 0; i < NumElem(selected); ++i)
- if (selected[i])
- {
+ if (path == NULL) {
+ for (i = 0; i < ARRAY_SIZE(selected); ++i)
+ if (selected[i]) {
free((char *) selected[i]);
selected[i] = NULL;
}
return 0;
}
- for (i = 0; i < NumElem(selected); ++i)
- if (!selected[i])
- {
+ for (i = 0; i < ARRAY_SIZE(selected); ++i)
+ if (!selected[i]) {
selected[i] = path;
return 0;
}
- fprintf(stderr, "Max trace paths exceeded, only using first %d\n",
- NumElem(selected));
+ fprintf(stderr, "Max trace paths exceeded, only using first %u\n",
+ (unsigned int) ARRAY_SIZE(selected));
return -1;
}
return 0;
/* if realpath and specified path are same, we're done */
- if (!strcmp(path, rpath))
- {
+ if (!strcmp(path, rpath)) {
free(rpath);
return 0;
}
s->sys_func == sys_dup3 ||
s->sys_func == sys_sendfile ||
s->sys_func == sys_sendfile64 ||
- !strcmp(s->sys_name, "tee"))
+ !strcmp(s->sys_name, "tee"))
{
/* fd, fd */
return fdmatch(tcp, tcp->u_arg[0]) ||
s->sys_func == sys_readlinkat ||
s->sys_func == sys_utimensat ||
s->sys_func == sys_fchownat ||
- s->sys_func == sys_pipe2)
+ s->sys_func == sys_pipe2)
{
/* fd, path */
return fdmatch(tcp, tcp->u_arg[0]) ||
s->sys_func == sys_pivotroot ||
s->sys_func == sys_rename ||
s->sys_func == sys_symlink ||
- s->sys_func == sys_mount)
+ s->sys_func == sys_mount)
{
/* path, path */
return upathmatch(tcp, tcp->u_arg[0]) ||
}
if (s->sys_func == sys_renameat ||
- s->sys_func == sys_linkat)
+ s->sys_func == sys_linkat)
{
/* fd, path, fd, path */
return fdmatch(tcp, tcp->u_arg[0]) ||
upathmatch(tcp, tcp->u_arg[3]);
}
- if (s->sys_func == sys_old_mmap || s->sys_func == sys_mmap)
- {
+ if (s->sys_func == sys_old_mmap || s->sys_func == sys_mmap) {
/* x, x, x, x, fd */
return fdmatch(tcp, tcp->u_arg[4]);
}
- if (s->sys_func == sys_symlinkat)
- {
+ if (s->sys_func == sys_symlinkat) {
/* path, fd, path */
return fdmatch(tcp, tcp->u_arg[1]) ||
upathmatch(tcp, tcp->u_arg[0]) ||
- upathmatch(tcp, tcp->u_arg[2]);
+ upathmatch(tcp, tcp->u_arg[2]);
}
- if (!strcmp(s->sys_name, "splice"))
- {
+ if (!strcmp(s->sys_name, "splice")) {
/* fd, x, fd, x, x */
return fdmatch(tcp, tcp->u_arg[0]) ||
fdmatch(tcp, tcp->u_arg[2]);
}
- if (s->sys_func == sys_epoll_ctl)
- {
+ if (s->sys_func == sys_epoll_ctl) {
/* x, x, fd, x */
return fdmatch(tcp, tcp->u_arg[2]);
}
if (s->sys_func == sys_select ||
s->sys_func == sys_oldselect ||
- s->sys_func == sys_pselect6)
+ s->sys_func == sys_pselect6)
{
int i, j, nfds;
long *args, oldargs[5];
unsigned fdsize;
fd_set *fds;
- if (s->sys_func == sys_oldselect)
- {
+ if (s->sys_func == sys_oldselect) {
if (umoven(tcp, tcp->u_arg[0], sizeof oldargs,
(char*) oldargs) < 0)
{
& -sizeof(long));
fds = malloc(fdsize);
- if (fds == NULL)
- {
+ if (fds == NULL) {
fprintf(stderr, "out of memory\n");
return 0;
}
- for (i = 1; i <= 3; ++i)
- {
+ for (i = 1; i <= 3; ++i) {
if (args[i] == 0)
continue;
- if (umoven(tcp, args[i], fdsize, (char *) fds) < 0)
- {
+ if (umoven(tcp, args[i], fdsize, (char *) fds) < 0) {
fprintf(stderr, "umoven() failed\n");
continue;
}
for (j = 0; j < nfds; ++j)
- if (FD_ISSET(j, fds) && fdmatch(tcp, j))
- {
+ if (FD_ISSET(j, fds) && fdmatch(tcp, j)) {
free(fds);
return 1;
}
}
if (s->sys_func == sys_poll ||
- s->sys_func == sys_ppoll)
+ s->sys_func == sys_ppoll)
{
struct pollfd fds;
unsigned nfds;