History

tools/power turbostat: Fix 32-bit capabilities warning

warning: `turbostat' uses 32-bit capabilities (legacy support in use)

Len Brown committed 6 years ago

Commit fcaa6811 parent 1f81c5e2 files · +31 −17Browse files

Unified · Split

2 files
  1. tools/power/x86/turbostat/Makefile +1 −1
  2. tools/power/x86/turbostat/turbostat.c +30 −16
tools/power/x86/turbostat/Makefile+1−1
@@ -16,7 +16,7 @@ override CFLAGS += -D_FORTIFY_SOURCE=2 · 15 unmodified lines
1616
1717 %: %.c
1818 @mkdir -p $(BUILD_OUTPUT)
19− $(CC) $(CFLAGS) $< -o $(BUILD_OUTPUT)/$@ $(LDFLAGS)
19+ $(CC) $(CFLAGS) $< -o $(BUILD_OUTPUT)/$@ $(LDFLAGS) -lcap
2020
2121 .PHONY : clean
2222 clean :
tools/power/x86/turbostat/turbostat.c+30−16
@@ -30,7 +30,7 @@ · 29 unmodified lines
3030 #include <sched.h>
3131 #include <time.h>
3232 #include <cpuid.h>
33−#include <linux/capability.h>
33+#include <sys/capability.h>
3434 #include <errno.h>
3535 #include <math.h>
3636
@@ -3150,28 +3150,42 @@ void check_dev_msr() · 3113 unmodified lines
31503150 err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" ");
31513151 }
31523152
3153−void check_permissions()
3153+/*
3154+ * check for CAP_SYS_RAWIO
3155+ * return 0 on success
3156+ * return 1 on fail
3157+ */
3158+int check_for_cap_sys_rawio(void)
31543159 {
3155− struct __user_cap_header_struct cap_header_data;
3156− cap_user_header_t cap_header = &cap_header_data;
3157− struct __user_cap_data_struct cap_data_data;
3158− cap_user_data_t cap_data = &cap_data_data;
3159− extern int capget(cap_user_header_t hdrp, cap_user_data_t datap);
3160− int do_exit = 0;
3161− char pathname[32];
3160+ cap_t caps;
3161+ cap_flag_value_t cap_flag_value;
31623162
3163− /* check for CAP_SYS_RAWIO */
3164− cap_header->pid = getpid();
3165− cap_header->version = _LINUX_CAPABILITY_VERSION;
3166− if (capget(cap_header, cap_data) < 0)
3167− err(-6, "capget(2) failed");
3163+ caps = cap_get_proc();
3164+ if (caps == NULL)
3165+ err(-6, "cap_get_proc\n");
31683166
3169− if ((cap_data->effective & (1 << CAP_SYS_RAWIO)) == 0) {
3170− do_exit++;
3167+ if (cap_get_flag(caps, CAP_SYS_RAWIO, CAP_EFFECTIVE, &cap_flag_value))
3168+ err(-6, "cap_get\n");
3169+
3170+ if (cap_flag_value != CAP_SET) {
31713171 warnx("capget(CAP_SYS_RAWIO) failed,"
31723172 " try \"# setcap cap_sys_rawio=ep %s\"", progname);
3173+ return 1;
31733174 }
31743175
3176+ if (cap_free(caps) == -1)
3177+ err(-6, "cap_free\n");
3178+
3179+ return 0;
3180+}
3181+void check_permissions(void)
3182+{
3183+ int do_exit = 0;
3184+ char pathname[32];
3185+
3186+ /* check for CAP_SYS_RAWIO */
3187+ do_exit += check_for_cap_sys_rawio();
3188+
31753189 /* test file permissions */
31763190 sprintf(pathname, "/dev/cpu/%d/msr", base_cpu);
31773191 if (euidaccess(pathname, R_OK)) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t