From owner-svn-src-stable@freebsd.org Mon Apr 16 17:30:34 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A833DF9663A; Mon, 16 Apr 2018 17:30:34 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5C72B80BD1; Mon, 16 Apr 2018 17:30:34 +0000 (UTC) (envelope-from trasz@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 3E2E5205BA; Mon, 16 Apr 2018 17:30:34 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w3GHUY0H032971; Mon, 16 Apr 2018 17:30:34 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w3GHUYiF032970; Mon, 16 Apr 2018 17:30:34 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201804161730.w3GHUYiF032970@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Mon, 16 Apr 2018 17:30:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r332628 - stable/11/tools/tools/syscall_timing X-SVN-Group: stable-11 X-SVN-Commit-Author: trasz X-SVN-Commit-Paths: stable/11/tools/tools/syscall_timing X-SVN-Commit-Revision: 332628 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Apr 2018 17:30:34 -0000 Author: trasz Date: Mon Apr 16 17:30:33 2018 New Revision: 332628 URL: https://svnweb.freebsd.org/changeset/base/332628 Log: MFC r325313: Make syscall_timing(1) default to a temporary file when run without -p. Modified: stable/11/tools/tools/syscall_timing/syscall_timing.c Directory Properties: stable/11/ (props changed) Modified: stable/11/tools/tools/syscall_timing/syscall_timing.c ============================================================================== --- stable/11/tools/tools/syscall_timing/syscall_timing.c Mon Apr 16 17:29:50 2018 (r332627) +++ stable/11/tools/tools/syscall_timing/syscall_timing.c Mon Apr 16 17:30:33 2018 (r332628) @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -792,15 +793,17 @@ main(int argc, char *argv[]) struct timespec ts_res; const struct test *the_test; const char *path; + char *tmp_dir, *tmp_path; long long ll; char *endp; - int ch, error, i, j, k; + int ch, fd, error, i, j, k, rv; uintmax_t iterations, loops; alarm_timeout = 1; iterations = 0; loops = 10; path = NULL; + tmp_path = NULL; while ((ch = getopt(argc, argv, "i:l:p:s:")) != -1) { switch (ch) { case 'i': @@ -859,7 +862,15 @@ main(int argc, char *argv[]) if (the_test == NULL) usage(); if ((the_test->t_flags & FLAG_PATH) && (path == NULL)) { - errx(-1, "%s requires -p", the_test->t_name); + tmp_dir = strdup("/tmp/syscall_timing.XXXXXXXX"); + if (tmp_dir == NULL) + err(1, "strdup"); + tmp_dir = mkdtemp(tmp_dir); + if (tmp_dir == NULL) + err(1, "mkdtemp"); + rv = asprintf(&tmp_path, "%s/testfile", tmp_dir); + if (rv <= 0) + err(1, "asprintf"); } } @@ -878,6 +889,19 @@ main(int argc, char *argv[]) the_test = &tests[i]; } + if (tmp_path != NULL) { + fd = open(tmp_path, O_WRONLY | O_CREAT, 0700); + if (fd < 0) + err(1, "cannot open %s", tmp_path); + error = ftruncate(fd, 1000000); + if (error != 0) + err(1, "ftruncate"); + error = close(fd); + if (error != 0) + err(1, "close"); + path = tmp_path; + } + /* * Run one warmup, then do the real thing (loops) times. */ @@ -903,5 +927,15 @@ main(int argc, char *argv[]) printf("0.%09ju\n", (uintmax_t)nsecsperit); } } + + if (tmp_path != NULL) { + error = unlink(tmp_path); + if (error != 0 && errno != ENOENT) + warn("cannot unlink %s", tmp_path); + error = rmdir(tmp_dir); + if (error != 0) + warn("cannot rmdir %s", tmp_dir); + } + return (0); }