From owner-svn-src-head@freebsd.org Sun Jul 5 19:53:55 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3B55834BE21; Sun, 5 Jul 2020 19:53:55 +0000 (UTC) (envelope-from kaktus@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4B0KC70qG0z4KYf; Sun, 5 Jul 2020 19:53:55 +0000 (UTC) (envelope-from kaktus@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F361312929; Sun, 5 Jul 2020 19:53:54 +0000 (UTC) (envelope-from kaktus@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 065JrsaB018208; Sun, 5 Jul 2020 19:53:54 GMT (envelope-from kaktus@FreeBSD.org) Received: (from kaktus@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 065Jrs9T018207; Sun, 5 Jul 2020 19:53:54 GMT (envelope-from kaktus@FreeBSD.org) Message-Id: <202007051953.065Jrs9T018207@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kaktus set sender to kaktus@FreeBSD.org using -f From: Pawel Biernacki Date: Sun, 5 Jul 2020 19:53:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362947 - head/usr.bin/truss X-SVN-Group: head X-SVN-Commit-Author: kaktus X-SVN-Commit-Paths: head/usr.bin/truss X-SVN-Commit-Revision: 362947 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Jul 2020 19:53:55 -0000 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, "\""); }