]> granicus.if.org Git - strace/commitdiff
process.c: move getgroups* and setgroups* parsers to a separate file
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 11 Dec 2014 19:25:02 +0000 (19:25 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 11 Dec 2014 22:52:03 +0000 (22:52 +0000)
* groups.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c: Move sys_setgroups, sys_getgroups, sys_setgroups32,
sys_getgroups32, and related code to groups.c.

Makefile.am
groups.c [new file with mode: 0644]
process.c

index c344338d277522b9d08f3c9a092845554604bea7..52f7f46db83fdfc77d1ff9f2ca21fff9b83cf6cc 100644 (file)
@@ -39,6 +39,7 @@ strace_SOURCES =      \
        get_robust_list.c \
        getcpu.c        \
        getcwd.c        \
+       groups.c        \
        inotify.c       \
        io.c            \
        ioctl.c         \
diff --git a/groups.c b/groups.c
new file mode 100644 (file)
index 0000000..2b4350c
--- /dev/null
+++ b/groups.c
@@ -0,0 +1,237 @@
+#include "defs.h"
+
+#include <asm/posix_types.h>
+#undef GETGROUPS_T
+#define GETGROUPS_T __kernel_gid_t
+#undef GETGROUPS32_T
+#define GETGROUPS32_T __kernel_gid32_t
+
+int
+sys_setgroups(struct tcb *tcp)
+{
+       if (entering(tcp)) {
+               unsigned long len, size, start, cur, end, abbrev_end;
+               GETGROUPS_T gid;
+               int failed = 0;
+
+               len = tcp->u_arg[0];
+               tprintf("%lu, ", len);
+               if (len == 0) {
+                       tprints("[]");
+                       return 0;
+               }
+               start = tcp->u_arg[1];
+               if (start == 0) {
+                       tprints("NULL");
+                       return 0;
+               }
+               size = len * sizeof(gid);
+               end = start + size;
+               if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
+                       tprintf("%#lx", start);
+                       return 0;
+               }
+               if (abbrev(tcp)) {
+                       abbrev_end = start + max_strlen * sizeof(gid);
+                       if (abbrev_end < start)
+                               abbrev_end = end;
+               } else {
+                       abbrev_end = end;
+               }
+               tprints("[");
+               for (cur = start; cur < end; cur += sizeof(gid)) {
+                       if (cur > start)
+                               tprints(", ");
+                       if (cur >= abbrev_end) {
+                               tprints("...");
+                               break;
+                       }
+                       if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
+                               tprints("?");
+                               failed = 1;
+                               break;
+                       }
+                       tprintf("%lu", (unsigned long) gid);
+               }
+               tprints("]");
+               if (failed)
+                       tprintf(" %#lx", tcp->u_arg[1]);
+       }
+       return 0;
+}
+
+int
+sys_getgroups(struct tcb *tcp)
+{
+       unsigned long len;
+
+       if (entering(tcp)) {
+               len = tcp->u_arg[0];
+               tprintf("%lu, ", len);
+       } else {
+               unsigned long size, start, cur, end, abbrev_end;
+               GETGROUPS_T gid;
+               int failed = 0;
+
+               len = tcp->u_rval;
+               if (len == 0) {
+                       tprints("[]");
+                       return 0;
+               }
+               start = tcp->u_arg[1];
+               if (start == 0) {
+                       tprints("NULL");
+                       return 0;
+               }
+               if (tcp->u_arg[0] == 0) {
+                       tprintf("%#lx", start);
+                       return 0;
+               }
+               size = len * sizeof(gid);
+               end = start + size;
+               if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
+                   size / sizeof(gid) != len || end < start) {
+                       tprintf("%#lx", start);
+                       return 0;
+               }
+               if (abbrev(tcp)) {
+                       abbrev_end = start + max_strlen * sizeof(gid);
+                       if (abbrev_end < start)
+                               abbrev_end = end;
+               } else {
+                       abbrev_end = end;
+               }
+               tprints("[");
+               for (cur = start; cur < end; cur += sizeof(gid)) {
+                       if (cur > start)
+                               tprints(", ");
+                       if (cur >= abbrev_end) {
+                               tprints("...");
+                               break;
+                       }
+                       if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
+                               tprints("?");
+                               failed = 1;
+                               break;
+                       }
+                       tprintf("%lu", (unsigned long) gid);
+               }
+               tprints("]");
+               if (failed)
+                       tprintf(" %#lx", tcp->u_arg[1]);
+       }
+       return 0;
+}
+
+int
+sys_setgroups32(struct tcb *tcp)
+{
+       if (entering(tcp)) {
+               unsigned long len, size, start, cur, end, abbrev_end;
+               GETGROUPS32_T gid;
+               int failed = 0;
+
+               len = tcp->u_arg[0];
+               tprintf("%lu, ", len);
+               if (len == 0) {
+                       tprints("[]");
+                       return 0;
+               }
+               start = tcp->u_arg[1];
+               if (start == 0) {
+                       tprints("NULL");
+                       return 0;
+               }
+               size = len * sizeof(gid);
+               end = start + size;
+               if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
+                       tprintf("%#lx", start);
+                       return 0;
+               }
+               if (abbrev(tcp)) {
+                       abbrev_end = start + max_strlen * sizeof(gid);
+                       if (abbrev_end < start)
+                               abbrev_end = end;
+               } else {
+                       abbrev_end = end;
+               }
+               tprints("[");
+               for (cur = start; cur < end; cur += sizeof(gid)) {
+                       if (cur > start)
+                               tprints(", ");
+                       if (cur >= abbrev_end) {
+                               tprints("...");
+                               break;
+                       }
+                       if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
+                               tprints("?");
+                               failed = 1;
+                               break;
+                       }
+                       tprintf("%lu", (unsigned long) gid);
+               }
+               tprints("]");
+               if (failed)
+                       tprintf(" %#lx", tcp->u_arg[1]);
+       }
+       return 0;
+}
+
+int
+sys_getgroups32(struct tcb *tcp)
+{
+       unsigned long len;
+
+       if (entering(tcp)) {
+               len = tcp->u_arg[0];
+               tprintf("%lu, ", len);
+       } else {
+               unsigned long size, start, cur, end, abbrev_end;
+               GETGROUPS32_T gid;
+               int failed = 0;
+
+               len = tcp->u_rval;
+               if (len == 0) {
+                       tprints("[]");
+                       return 0;
+               }
+               start = tcp->u_arg[1];
+               if (start == 0) {
+                       tprints("NULL");
+                       return 0;
+               }
+               size = len * sizeof(gid);
+               end = start + size;
+               if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
+                   size / sizeof(gid) != len || end < start) {
+                       tprintf("%#lx", start);
+                       return 0;
+               }
+               if (abbrev(tcp)) {
+                       abbrev_end = start + max_strlen * sizeof(gid);
+                       if (abbrev_end < start)
+                               abbrev_end = end;
+               } else {
+                       abbrev_end = end;
+               }
+               tprints("[");
+               for (cur = start; cur < end; cur += sizeof(gid)) {
+                       if (cur > start)
+                               tprints(", ");
+                       if (cur >= abbrev_end) {
+                               tprints("...");
+                               break;
+                       }
+                       if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
+                               tprints("?");
+                               failed = 1;
+                               break;
+                       }
+                       tprintf("%lu", (unsigned long) gid);
+               }
+               tprints("]");
+               if (failed)
+                       tprintf(" %#lx", tcp->u_arg[1]);
+       }
+       return 0;
+}
index cd0c516d58fe85730477b760c4e658d7e68592f2..720559d2bb35955d6074a90b33126596c47b3556 100644 (file)
--- a/process.c
+++ b/process.c
 #endif
 
 #include <asm/posix_types.h>
-#undef GETGROUPS_T
-#define GETGROUPS_T __kernel_gid_t
-#undef GETGROUPS32_T
-#define GETGROUPS32_T __kernel_gid32_t
 
 #if defined(IA64)
 # include <asm/ptrace_offsets.h>
@@ -344,236 +340,6 @@ sys_setresuid(struct tcb *tcp)
        return 0;
 }
 
-int
-sys_setgroups(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               unsigned long len, size, start, cur, end, abbrev_end;
-               GETGROUPS_T gid;
-               int failed = 0;
-
-               len = tcp->u_arg[0];
-               tprintf("%lu, ", len);
-               if (len == 0) {
-                       tprints("[]");
-                       return 0;
-               }
-               start = tcp->u_arg[1];
-               if (start == 0) {
-                       tprints("NULL");
-                       return 0;
-               }
-               size = len * sizeof(gid);
-               end = start + size;
-               if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
-                       tprintf("%#lx", start);
-                       return 0;
-               }
-               if (abbrev(tcp)) {
-                       abbrev_end = start + max_strlen * sizeof(gid);
-                       if (abbrev_end < start)
-                               abbrev_end = end;
-               } else {
-                       abbrev_end = end;
-               }
-               tprints("[");
-               for (cur = start; cur < end; cur += sizeof(gid)) {
-                       if (cur > start)
-                               tprints(", ");
-                       if (cur >= abbrev_end) {
-                               tprints("...");
-                               break;
-                       }
-                       if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
-                               tprints("?");
-                               failed = 1;
-                               break;
-                       }
-                       tprintf("%lu", (unsigned long) gid);
-               }
-               tprints("]");
-               if (failed)
-                       tprintf(" %#lx", tcp->u_arg[1]);
-       }
-       return 0;
-}
-
-int
-sys_getgroups(struct tcb *tcp)
-{
-       unsigned long len;
-
-       if (entering(tcp)) {
-               len = tcp->u_arg[0];
-               tprintf("%lu, ", len);
-       } else {
-               unsigned long size, start, cur, end, abbrev_end;
-               GETGROUPS_T gid;
-               int failed = 0;
-
-               len = tcp->u_rval;
-               if (len == 0) {
-                       tprints("[]");
-                       return 0;
-               }
-               start = tcp->u_arg[1];
-               if (start == 0) {
-                       tprints("NULL");
-                       return 0;
-               }
-               if (tcp->u_arg[0] == 0) {
-                       tprintf("%#lx", start);
-                       return 0;
-               }
-               size = len * sizeof(gid);
-               end = start + size;
-               if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
-                   size / sizeof(gid) != len || end < start) {
-                       tprintf("%#lx", start);
-                       return 0;
-               }
-               if (abbrev(tcp)) {
-                       abbrev_end = start + max_strlen * sizeof(gid);
-                       if (abbrev_end < start)
-                               abbrev_end = end;
-               } else {
-                       abbrev_end = end;
-               }
-               tprints("[");
-               for (cur = start; cur < end; cur += sizeof(gid)) {
-                       if (cur > start)
-                               tprints(", ");
-                       if (cur >= abbrev_end) {
-                               tprints("...");
-                               break;
-                       }
-                       if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
-                               tprints("?");
-                               failed = 1;
-                               break;
-                       }
-                       tprintf("%lu", (unsigned long) gid);
-               }
-               tprints("]");
-               if (failed)
-                       tprintf(" %#lx", tcp->u_arg[1]);
-       }
-       return 0;
-}
-
-int
-sys_setgroups32(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               unsigned long len, size, start, cur, end, abbrev_end;
-               GETGROUPS32_T gid;
-               int failed = 0;
-
-               len = tcp->u_arg[0];
-               tprintf("%lu, ", len);
-               if (len == 0) {
-                       tprints("[]");
-                       return 0;
-               }
-               start = tcp->u_arg[1];
-               if (start == 0) {
-                       tprints("NULL");
-                       return 0;
-               }
-               size = len * sizeof(gid);
-               end = start + size;
-               if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
-                       tprintf("%#lx", start);
-                       return 0;
-               }
-               if (abbrev(tcp)) {
-                       abbrev_end = start + max_strlen * sizeof(gid);
-                       if (abbrev_end < start)
-                               abbrev_end = end;
-               } else {
-                       abbrev_end = end;
-               }
-               tprints("[");
-               for (cur = start; cur < end; cur += sizeof(gid)) {
-                       if (cur > start)
-                               tprints(", ");
-                       if (cur >= abbrev_end) {
-                               tprints("...");
-                               break;
-                       }
-                       if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
-                               tprints("?");
-                               failed = 1;
-                               break;
-                       }
-                       tprintf("%lu", (unsigned long) gid);
-               }
-               tprints("]");
-               if (failed)
-                       tprintf(" %#lx", tcp->u_arg[1]);
-       }
-       return 0;
-}
-
-int
-sys_getgroups32(struct tcb *tcp)
-{
-       unsigned long len;
-
-       if (entering(tcp)) {
-               len = tcp->u_arg[0];
-               tprintf("%lu, ", len);
-       } else {
-               unsigned long size, start, cur, end, abbrev_end;
-               GETGROUPS32_T gid;
-               int failed = 0;
-
-               len = tcp->u_rval;
-               if (len == 0) {
-                       tprints("[]");
-                       return 0;
-               }
-               start = tcp->u_arg[1];
-               if (start == 0) {
-                       tprints("NULL");
-                       return 0;
-               }
-               size = len * sizeof(gid);
-               end = start + size;
-               if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
-                   size / sizeof(gid) != len || end < start) {
-                       tprintf("%#lx", start);
-                       return 0;
-               }
-               if (abbrev(tcp)) {
-                       abbrev_end = start + max_strlen * sizeof(gid);
-                       if (abbrev_end < start)
-                               abbrev_end = end;
-               } else {
-                       abbrev_end = end;
-               }
-               tprints("[");
-               for (cur = start; cur < end; cur += sizeof(gid)) {
-                       if (cur > start)
-                               tprints(", ");
-                       if (cur >= abbrev_end) {
-                               tprints("...");
-                               break;
-                       }
-                       if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
-                               tprints("?");
-                               failed = 1;
-                               break;
-                       }
-                       tprintf("%lu", (unsigned long) gid);
-               }
-               tprints("]");
-               if (failed)
-                       tprintf(" %#lx", tcp->u_arg[1]);
-       }
-       return 0;
-}
-
 #include "xlat/ptrace_cmds.h"
 #include "xlat/ptrace_setoptions_flags.h"
 #include "xlat/nt_descriptor_types.h"