Date: Sun, 5 Jul 2020 19:53:54 +0000 (UTC) From: Pawel Biernacki <kaktus@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362947 - head/usr.bin/truss Message-ID: <202007051953.065Jrs9T018207@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kaktus Date: Sun Jul 5 19:53:54 2020 New Revision: 362947 URL: https://svnweb.freebsd.org/changeset/base/362947 Log: truss: print more information about traced sysctls MFC after: 2 weeks Sponsored by: Mysterious Code Ltd. Modified: head/usr.bin/truss/syscalls.c Modified: head/usr.bin/truss/syscalls.c ============================================================================== --- head/usr.bin/truss/syscalls.c Sun Jul 5 19:38:36 2020 (r362946) +++ head/usr.bin/truss/syscalls.c Sun Jul 5 19:53:54 2020 (r362947) @@ -1577,14 +1577,37 @@ print_cmsgs(FILE *fp, pid_t pid, bool receive, struct } static void -print_sysctl_oid(FILE *fp, int *oid, int len) +print_sysctl_oid(FILE *fp, int *oid, size_t len) { - int i; + size_t i; + bool first; - for (i = 0; i < len; i++) - fprintf(fp, ".%d", oid[i]); + first = true; + fprintf(fp, "{ "); + for (i = 0; i < len; i++) { + fprintf(fp, "%s%d", first ? "" : ".", oid[i]); + first = false; + } + fprintf(fp, " }"); } +static void +print_sysctl(FILE *fp, int *oid, size_t len) +{ + char name[BUFSIZ]; + int qoid[CTL_MAXNAME + 2]; + size_t i; + + qoid[0] = CTL_SYSCTL; + qoid[1] = CTL_SYSCTL_NAME; + memcpy(qoid + 2, oid, len * sizeof(int)); + i = sizeof(name); + if (sysctl(qoid, len + 2, name, &i, 0, 0) == -1) + print_sysctl_oid(fp, oid, len); + else + fprintf(fp, "%s", name); +} + /* * Converts a syscall argument into a string. Said string is * allocated via malloc(), so needs to be free()'d. sc is @@ -2298,9 +2321,8 @@ print_arg(struct syscall_args *sc, unsigned long *args break; case Sysctl: { char name[BUFSIZ]; - int oid[CTL_MAXNAME + 2], qoid[CTL_MAXNAME + 2]; - size_t i; - int len; + int oid[CTL_MAXNAME + 2]; + size_t len; memset(name, 0, sizeof(name)); len = args[sc->offset + 1]; @@ -2314,39 +2336,35 @@ print_arg(struct syscall_args *sc, unsigned long *args fprintf(fp, "debug"); break; case CTL_SYSCTL_NAME: - fprintf(fp, "name"); + fprintf(fp, "name "); print_sysctl_oid(fp, oid + 2, len - 2); break; case CTL_SYSCTL_NEXT: fprintf(fp, "next"); break; case CTL_SYSCTL_NAME2OID: - fprintf(fp, "name2oid"); + fprintf(fp, "name2oid %s", + get_string(pid, + args[sc->offset + 4], + args[sc->offset + 5])); break; case CTL_SYSCTL_OIDFMT: - fprintf(fp, "oidfmt"); - print_sysctl_oid(fp, oid + 2, len - 2); + fprintf(fp, "oidfmt "); + print_sysctl(fp, oid + 2, len - 2); break; case CTL_SYSCTL_OIDDESCR: - fprintf(fp, "oiddescr"); - print_sysctl_oid(fp, oid + 2, len - 2); + fprintf(fp, "oiddescr "); + print_sysctl(fp, oid + 2, len - 2); break; case CTL_SYSCTL_OIDLABEL: - fprintf(fp, "oidlabel"); - print_sysctl_oid(fp, oid + 2, len - 2); + fprintf(fp, "oidlabel "); + print_sysctl(fp, oid + 2, len - 2); break; default: - print_sysctl_oid(fp, oid + 1, len - 1); + print_sysctl(fp, oid + 1, len - 1); } } else { - qoid[0] = CTL_SYSCTL; - qoid[1] = CTL_SYSCTL_NAME; - memcpy(qoid + 2, oid, len * sizeof(int)); - i = sizeof(name); - if (sysctl(qoid, len + 2, name, &i, 0, 0) == -1) - print_sysctl_oid(fp, qoid + 2, len); - else - fprintf(fp, "%s", name); + print_sysctl(fp, oid, len); } fprintf(fp, "\""); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202007051953.065Jrs9T018207>