Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/pmc Check argc, and add a message.



details:   https://anonhg.NetBSD.org/src/rev/4051f82e8c59
branches:  trunk
changeset: 824692:4051f82e8c59
user:      maxv <maxv%NetBSD.org@localhost>
date:      Wed Jun 14 17:54:01 2017 +0000

description:
Check argc, and add a message.

diffstat:

 usr.bin/pmc/pmc.c |  17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diffs (38 lines):

diff -r b21d5f45a244 -r 4051f82e8c59 usr.bin/pmc/pmc.c
--- a/usr.bin/pmc/pmc.c Wed Jun 14 17:48:40 2017 +0000
+++ b/usr.bin/pmc/pmc.c Wed Jun 14 17:54:01 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmc.c,v 1.23 2017/03/24 18:30:44 maxv Exp $    */
+/*     $NetBSD: pmc.c,v 1.24 2017/06/14 17:54:01 maxv Exp $    */
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: pmc.c,v 1.23 2017/03/24 18:30:44 maxv Exp $");
+__RCSID("$NetBSD: pmc.c,v 1.24 2017/06/14 17:54:01 maxv Exp $");
 #endif
 
 #include <inttypes.h>
@@ -585,8 +585,17 @@
        setprogname(argv[0]);
        argv += 1;
 
-       if (x86_pmc_info(&pmcinfo) < 0)
-               errx(EXIT_FAILURE, "PMC support not compiled into the kernel");
+       if (argc < 2)
+               usage();
+
+       if (x86_pmc_info(&pmcinfo) < 0) {
+               if (errno == EPERM)
+                       errx(EXIT_FAILURE,
+                           "PMC operations require root privileges");
+               else
+                       errx(EXIT_FAILURE,
+                           "PMC support not compiled into the kernel");
+       }
        if (pmcinfo.vers != 1)
                errx(EXIT_FAILURE, "Wrong PMC version");
        pmc_ncounters = pmcinfo.nctrs;



Home | Main Index | Thread Index | Old Index