Skip to contentSkip to conversation

rt-utils: Remove access to /sys/kernel/realtime

PATCH In review Sebastian Andrzej Siewior 3 participants 3 messages Sep 23 – Nov 2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rt-utils: Remove access to /sys/kernel/realtime

The json file reads /sys/kernel/realtime and then writes the attribute 'realtime' = 1 if its content was 1. That file is only created with the PREEMPT_RT patch applied will not be submitted upstream.
The information can be deducted from the uname(2) function which is used and all fields are written into the json file.

Set the 'realtime' attribute to 1 if the version field contains 'PREEMPT_RT'. This was always the case.

---
 src/lib/rt-utils.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
src/lib/rt-utils.c +4 -11
index aa70c788d0259..6622f5364c07f 100644
@@ -508,11 +508,9 @@ void rt_write_json(const char *filename, int return_code,
 		  void (*cb)(FILE *, void *),
 		  void *data)
 {
-	unsigned char buf[1];
 	struct utsname uts;
 	char ts_end[MAX_TS_SIZE];
-	FILE *f, *s;
-	size_t n;
+	FILE *f;
 	int rt = 0;
 
 	if (!filename || !strcmp("-", filename)) {
@@ -525,17 +523,12 @@ void rt_write_json(const char *filename, int return_code,
 
 	get_timestamp(ts_end);
 
-	s = fopen("/sys/kernel/realtime", "r");
-	if (s) {
-		n = fread(buf, 1, 1, s);
-		if (n == 1 && buf[0] == '1')
-			rt = 1;
-		fclose(s);
-	}
-
 	if (uname(&uts))
 		err_exit(errno, "Could not retrieve system information");
 
+	if (strstr(uts.version, "PREEMPT_RT"))
+		rt = 1;
+
 	fprintf(f, "{\n");
 	fprintf(f, "  \"file_version\": 1,\n");
 	fprintf(f, "  \"cmdline:\": \"%s\",\n", test_cmdline);
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Sebastian Andrzej Siewior

The json file reads /sys/kernel/realtime and then writes the attribute 'realtime' = 1 if its content was 1. That file is only created with the PREEMPT_RT patch applied will not be submitted upstream.
The information can be deducted from the uname(2) function which is used and all fields are written into the json file.

Set the 'realtime' attribute to 1 if the version field contains 'PREEMPT_RT'. This was always the case.

Makes sense to get rid of the dependency on /sys/kernel/realtime. Thanks!