Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/power turbostat: graceful fail on garbage input

When invald MSR's are specified on the command line,
turbostat should simply print an error and exit.

Signed-off-by: Len Brown <len.brown@intel.com>

Len Brown d91bb17c 39300ffb

+18 -8
+18 -8
tools/power/x86/turbostat/turbostat.c
··· 206 206 retval = pread(fd, msr, sizeof *msr, offset); 207 207 close(fd); 208 208 209 - if (retval != sizeof *msr) 209 + if (retval != sizeof *msr) { 210 + fprintf(stderr, "%s offset 0x%zx read failed\n", pathname, offset); 210 211 return -1; 212 + } 211 213 212 214 return 0; 213 215 } ··· 1103 1101 1104 1102 restart: 1105 1103 retval = for_all_cpus(get_counters, EVEN_COUNTERS); 1106 - if (retval) { 1104 + if (retval < -1) { 1105 + exit(retval); 1106 + } else if (retval == -1) { 1107 1107 re_initialize(); 1108 1108 goto restart; 1109 1109 } ··· 1118 1114 } 1119 1115 sleep(interval_sec); 1120 1116 retval = for_all_cpus(get_counters, ODD_COUNTERS); 1121 - if (retval) { 1117 + if (retval < -1) { 1118 + exit(retval); 1119 + } else if (retval == -1) { 1122 1120 re_initialize(); 1123 1121 goto restart; 1124 1122 } ··· 1132 1126 flush_stdout(); 1133 1127 sleep(interval_sec); 1134 1128 retval = for_all_cpus(get_counters, EVEN_COUNTERS); 1135 - if (retval) { 1129 + if (retval < -1) { 1130 + exit(retval); 1131 + } else if (retval == -1) { 1136 1132 re_initialize(); 1137 1133 goto restart; 1138 1134 } ··· 1553 1545 int fork_it(char **argv) 1554 1546 { 1555 1547 pid_t child_pid; 1548 + int status; 1556 1549 1557 - for_all_cpus(get_counters, EVEN_COUNTERS); 1550 + status = for_all_cpus(get_counters, EVEN_COUNTERS); 1551 + if (status) 1552 + exit(status); 1558 1553 /* clear affinity side-effect of get_counters() */ 1559 1554 sched_setaffinity(0, cpu_present_setsize, cpu_present_set); 1560 1555 gettimeofday(&tv_even, (struct timezone *)NULL); ··· 1567 1556 /* child */ 1568 1557 execvp(argv[0], argv); 1569 1558 } else { 1570 - int status; 1571 1559 1572 1560 /* parent */ 1573 1561 if (child_pid == -1) { ··· 1578 1568 signal(SIGQUIT, SIG_IGN); 1579 1569 if (waitpid(child_pid, &status, 0) == -1) { 1580 1570 perror("wait"); 1581 - exit(1); 1571 + exit(status); 1582 1572 } 1583 1573 } 1584 1574 /* ··· 1595 1585 1596 1586 fprintf(stderr, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0); 1597 1587 1598 - return 0; 1588 + return status; 1599 1589 } 1600 1590 1601 1591 void cmdline(int argc, char **argv)