Skip to content

Commit 1d22326

Browse files
committed
Fix and improve report_sched_fifo_error()
1 parent 585dafb commit 1d22326

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

src/rtapi/uspace_rtapi_main.cc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ static inline int detect_preempt_dynamic() {
105105
}
106106

107107
#ifdef USPACE_RTAI
108-
static int detect_rtai() {
108+
static int detect_rtai_lxrt() {
109109
if(!has_setuid_root()) return 0;
110110
struct utsname u;
111111
uname(&u);
112112
return strcasestr (u.release, "-rtai") != 0;
113113
}
114114
#else
115-
static int detect_rtai() {
115+
static int detect_rtai_lxrt() {
116116
return 0;
117117
}
118118
#endif
@@ -166,13 +166,17 @@ static void report_sched_fifo_error(int sched_err){
166166
// between "no caps", "stock kernel", or "wrong rlimits" (issue
167167
// #3928). errno comes from the SCHED_FIFO probe in
168168
// can_set_sched_fifo(); cap state comes from libcap.
169-
#ifdef __linux__
170-
cap_t caps = cap_get_proc();
171-
const char *nice_s = cap_effective_str(caps, CAP_SYS_NICE);
172-
const char *lock_s = cap_effective_str(caps, CAP_IPC_LOCK);
173-
#else
174169
const char *nice_s = "unknown";
175170
const char *lock_s = "unknown";
171+
#ifdef __linux__
172+
cap_t caps = cap_get_proc();
173+
if(caps == NULL){
174+
rtapi_print_msg(RTAPI_MSG_ERR, "cap_get_proc failed: %m\n");
175+
}else{
176+
nice_s = cap_effective_str(caps, CAP_SYS_NICE);
177+
lock_s = cap_effective_str(caps, CAP_IPC_LOCK);
178+
cap_free(caps);
179+
}
176180
#endif
177181
rtapi_print_msg(RTAPI_MSG_ERR,
178182
"Note: realtime scheduling unavailable "
@@ -184,9 +188,6 @@ static void report_sched_fifo_error(int sched_err){
184188
" Override (testing only): set LINUXCNC_FORCE_REALTIME=1.\n",
185189
sched_err ? strerror(sched_err) : "denied",
186190
nice_s, lock_s);
187-
#ifdef __linux__
188-
if (caps) cap_free(caps);
189-
#endif
190191
}
191192

192193
// Success-probe for realtime scheduling: briefly try to set SCHED_FIFO on
@@ -231,7 +232,7 @@ rtapi_realtime_status_t rtapi_realtime_status(void){
231232
return cached;
232233
}
233234

234-
if(detect_rtai()){
235+
if(detect_rtai_lxrt()){
235236
cached = REALTIME_STATUS_LXRT;
236237
return cached;
237238
}

0 commit comments

Comments
 (0)