Commit 99f76fd1 authored by Gabor Buella's avatar Gabor Buella
Browse files

syscall format - fcntl fixes

parent 3f7e7a12
......@@ -214,7 +214,11 @@ static char *
print_flag_set(char *buffer_start, char *c, long flags,
const struct flag_desc *desc)
{
while (flags != 0 && desc->flag != 0) {
bool is_zero = flags == 0;
while (flags != 0 && desc->printable_name != NULL) {
if (is_zero && desc->flag == 0)
return print_flag(buffer_start, c,
desc->printable_name);
if ((flags & desc->flag) != 0) {
c = print_flag(buffer_start, c, desc->printable_name);
flags &= ~desc->flag;
......@@ -543,7 +547,7 @@ static const struct flag_desc flock_type[] = {
FLAG_ENTRY(F_RDLCK),
FLAG_ENTRY(F_WRLCK),
FLAG_ENTRY(F_UNLCK),
{ .flag = 0, }
{ 0, }
};
static char *
......@@ -599,13 +603,15 @@ static const struct flag_desc fcntl_cmds[] = {
FLAG_ENTRY(F_SEAL_GROW),
FLAG_ENTRY(F_SEAL_WRITE),
#endif
{ .flag = 0, }
{ 0, }
};
static char *
print_fcntl_cmd(char *buffer, int cmd)
{
for (const struct flag_desc *d = fcntl_cmds; d->flag != 0; ++d) {
for (const struct flag_desc *d = fcntl_cmds;
d->printable_name != NULL;
++d) {
if (d->flag == cmd)
return print_cstr(buffer, d->printable_name);
}
......@@ -633,11 +639,11 @@ print_fcntl_flock(char *buffer, long arg)
buffer = print_signed_dec(buffer, fl->l_type);
buffer = print_cstr(buffer, " (");
buffer = print_flag_set(buffer, buffer, fl->l_type, flock_type);
buffer = print_cstr(buffer, " ), .l_whence = ");
buffer = print_cstr(buffer, "), .l_whence = ");
buffer = print_signed_dec(buffer, fl->l_whence);
buffer = print_cstr(buffer, " (");
buffer = print_seek_whence(buffer, fl->l_whence);
buffer = print_cstr(buffer, " ), .l_start = ");
buffer = print_cstr(buffer, "), .l_start = ");
buffer = print_signed_dec(buffer, fl->l_start);
buffer = print_cstr(buffer, ", .l_len = ");
buffer = print_signed_dec(buffer, fl->l_len);
......@@ -650,7 +656,7 @@ print_fcntl_flock(char *buffer, long arg)
static char *
arg_print_fcntl_args(char *buffer, const struct syscall_desc *desc, int i,
arg_print_fcntl_cmd(char *buffer, const struct syscall_desc *desc, int i,
enum intercept_log_result result_status,
long result)
{
......@@ -662,23 +668,23 @@ arg_print_fcntl_args(char *buffer, const struct syscall_desc *desc, int i,
buffer = print_signed_dec(buffer, cmd);
buffer = print_cstr(buffer, " (");
buffer = print_fcntl_cmd(buffer, cmd);
buffer = print_cstr(buffer, "), ");
buffer = print_pointer(buffer, desc->args[i + 1]);
switch (cmd) {
case F_GETLK:
case F_SETLK:
case F_SETLKW:
case F_OFD_GETLK:
case F_OFD_SETLK:
case F_OFD_SETLKW:
buffer = print_fcntl_flock(buffer, desc->args[i + 1]);
break;
}
buffer = print_cstr(buffer, ")");
return buffer;
}
static char *
arg_print_flock(char *buffer, const struct syscall_desc *desc, int i,
enum intercept_log_result result_status,
long result)
{
(void) result_status;
(void) result;
buffer = print_pointer(buffer, desc->args[i]);
return print_fcntl_flock(buffer, desc->args[i]);
}
static char *
arg_print_clone_flags(char *buffer, const struct syscall_desc *desc, int i,
enum intercept_log_result result_status,
......@@ -757,12 +763,13 @@ static const arg_printer_func arg_printer_func_table[] = {
[arg_cstr] = arg_print_cstr,
[arg_buf_in] = arg_print_input_buf,
[arg_buf_out] = arg_print_output_buf,
[arg_fcntl_args] = arg_print_fcntl_args,
[arg_fcntl_cmd] = arg_print_fcntl_cmd,
[arg_clone_flags] = arg_print_clone_flags,
[arg_seek_whence] = arg_print_seek_whence,
[arg_2fds] = arg_print_2fds,
[arg_pipe2_flags] = arg_print_pipe2_flags,
[arg_access_mode] = arg_print_access_mode
[arg_access_mode] = arg_print_access_mode,
[arg_flock] = arg_print_flock
};
static const return_value_printer_func return_value_printer_table[] = {
......
......@@ -113,7 +113,7 @@ static const struct syscall_format formats[] = {
SARGS(msgsnd, rdec, arg_, arg_, arg_, arg_),
SARGS(msgrcv, rdec, arg_, arg_, arg_, arg_, arg_),
SARGS(msgctl, rdec, arg_, arg_, arg_),
SARGS(fcntl, rdec, arg_fd, arg_fcntl_args, arg_),
SARGS(fcntl, rdec, arg_fd, arg_fcntl_cmd, arg_),
SARGS(flock, rdec, arg_fd, arg_),
SARGS(fsync, rdec, arg_fd),
SARGS(fdatasync, rdec, arg_fd),
......@@ -402,9 +402,31 @@ static struct syscall_format open_with_o_creat = {.name = "open", rdec,
static struct syscall_format openat_with_o_creat = {.name = "openat", rdec,
{arg_atfd, arg_cstr, arg_open_flags, arg_oct_mode}};
static struct syscall_format fcntl_with_flock = {.name = "fcntl", rdec,
{arg_fd, arg_fcntl_cmd, arg_flock}};
static struct syscall_format unkown = {.name = NULL, rdec,
{arg_, arg_, arg_, arg_, arg_, arg_}};
static bool
is_fcntl_with_flock(const struct syscall_desc *desc)
{
if (desc->nr != SYS_fcntl)
return false;
switch ((int)desc->args[1]) {
case F_GETLK:
case F_SETLK:
case F_SETLKW:
case F_OFD_GETLK:
case F_OFD_SETLK:
case F_OFD_SETLKW:
return true;
default:
return false;
}
}
const struct syscall_format *
get_syscall_format(const struct syscall_desc *desc)
{
......@@ -420,5 +442,8 @@ get_syscall_format(const struct syscall_desc *desc)
if (desc->nr == SYS_openat && ((desc->args[2] & O_CREAT) == O_CREAT))
return &openat_with_o_creat;
if (is_fcntl_with_flock(desc))
return &fcntl_with_flock;
return formats + desc->nr;
}
......@@ -59,12 +59,13 @@ enum arg_format {
arg_fd, /* fd argument - not the first argument of *at syscalls */
arg_atfd, /* fd argument - the first argument of *at syscalls */
arg_pointer, /* general pointer argument */
arg_fcntl_args, /* 2nd (and 3rd) argument of fcntl */
arg_fcntl_cmd, /* 2nd argument of fcntl */
arg_clone_flags, /* 1st argument of clone */
arg_seek_whence, /* 3rd argument of lseek */
arg_2fds, /* array of 2 int fd numbers */
arg_pipe2_flags, /* second argument of pipe2 */
arg_access_mode /* second argument of access */
arg_access_mode, /* second argument of access */
arg_flock /* pointer to struct flock */
};
/*
......
......@@ -300,10 +300,12 @@ $(S) $(XX) -- msgrcv(0x1, 0x123000, 0x1, 0x1, 0x1) = ?
$(S) $(XX) -- msgrcv(0x1, 0x123000, 0x1, 0x1, 0x1) = 22
$(S) $(XX) -- msgctl(0x1, 0x2, 0x123000) = ?
$(S) $(XX) -- msgctl(0x1, 0x2, 0x123000) = 22
$(S) $(XX) -- fcntl(1, 1030 (unknown), 0x0000000000000003, 0x3) = ?
$(S) $(XX) -- fcntl(1, 1030 (unknown), 0x0000000000000003, 0x3) = 22
$(S) $(XX) -- fcntl(10, 4 (unknown), 0x0000000000040000, 0x40000) = ?
$(S) $(XX) -- fcntl(10, 4 (unknown), 0x0000000000040000, 0x40000) = 22
$(S) $(XX) -- fcntl(1, 1030 (F_DUPFD_CLOEXEC), 0x3) = ?
$(S) $(XX) -- fcntl(1, 1030 (F_DUPFD_CLOEXEC), 0x3) = 22
$(S) $(XX) -- fcntl(10, 4 (F_SETFL), 0x40000) = ?
$(S) $(XX) -- fcntl(10, 4 (F_SETFL), 0x40000) = 22
$(S) $(XX) -- fcntl(11, 6 (F_SETLK), $(XX) ({.l_type = 1 (F_WRLCK), .l_whence = 2 (SEEK_END), .l_start = 123, .l_len = 456, .l_pid = 768})) = ?
$(S) $(XX) -- fcntl(11, 6 (F_SETLK), $(XX) ({.l_type = 1 (F_WRLCK), .l_whence = 2 (SEEK_END), .l_start = 123, .l_len = 456, .l_pid = 768})) = 22
$(S) $(XX) -- flock(1, 0x2) = ?
$(S) $(XX) -- flock(1, 0x2) = 22
$(S) $(XX) -- fsync(2) = ?
......
......@@ -245,6 +245,14 @@ main(int argc, char **argv)
struct utsname uname_buf;
struct flock fl = {
.l_type = F_WRLCK,
.l_whence = SEEK_END,
.l_start = 123,
.l_len = 456,
.l_pid = 768
};
magic_syscall_start_log(argv[1], "1");
......@@ -445,6 +453,7 @@ main(int argc, char **argv)
fcntl(1, F_DUPFD_CLOEXEC, 3, 4);
fcntl(10, F_SETFL, O_NOATIME);
fcntl(11, F_SETLK, &fl);
flock(1, LOCK_EX);
fsync(2);
fdatasync(2);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment