From 3c2b5286c5d09dbbbc12363b7943a3112170e5f9 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 7 Jan 2024 17:44:40 +0100 Subject: [PATCH] Disable rtprio by default and abort, if given prio is not allowed --- src/dcf77/main.c | 26 ++++++++++++++------------ src/libmobile/main_mobile.c | 12 +++++++----- src/radio/main.c | 6 ++++-- src/tv/main.c | 6 ++++-- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/dcf77/main.c b/src/dcf77/main.c index 8a59ea6..f55e317 100755 --- a/src/dcf77/main.c +++ b/src/dcf77/main.c @@ -57,7 +57,7 @@ static int region = -1, region_advance; static int double_amplitude = 0; static int test_tone = 0; static int dsp_interval = 1; /* ms */ -static int rt_prio = 1; +static int rt_prio = 0; static int fast_math = 0; /* not static, in case we add libtimer some day, then compiler hits an error */ @@ -539,6 +539,19 @@ int main(int argc, char *argv[]) timestamp = dcf77_start_weather((time_t)timestamp, region, region_advance); } + /* set real time prio */ + if (rt_prio) { + struct sched_param schedp; + + memset(&schedp, 0, sizeof(schedp)); + schedp.sched_priority = rt_prio; + rc = sched_setscheduler(0, SCHED_RR, &schedp); + if (rc) { + fprintf(stderr, "Error setting SCHED_RR with prio %d\n", rt_prio); + goto error; + } + } + print_aaimage(); printf("DCF77 ready.\n"); @@ -550,17 +563,6 @@ int main(int argc, char *argv[]) term.c_cc[VTIME]=2; tcsetattr(0, TCSANOW, &term); - /* set real time prio */ - if (rt_prio) { - struct sched_param schedp; - - memset(&schedp, 0, sizeof(schedp)); - schedp.sched_priority = rt_prio; - rc = sched_setscheduler(0, SCHED_RR, &schedp); - if (rc) - fprintf(stderr, "Error setting SCHED_RR with prio %d\n", rt_prio); - } - signal(SIGINT, sighandler); signal(SIGHUP, sighandler); signal(SIGTERM, sighandler); diff --git a/src/libmobile/main_mobile.c b/src/libmobile/main_mobile.c index 487fe9e..9df29e8 100644 --- a/src/libmobile/main_mobile.c +++ b/src/libmobile/main_mobile.c @@ -77,7 +77,7 @@ int no_l16 = 0; int send_patterns = 1; static int release_on_disconnect = 1; int loopback = 0; -int rt_prio = 1; +int rt_prio = 0; int fast_math = 0; const char *write_tx_wave = NULL; const char *write_rx_wave = NULL; @@ -691,9 +691,6 @@ void main_mobile_loop(const char *name, int *quit, void (*myhandler)(void), cons if (console_open_audio(buffer_size, dsp_interval)) return; - if (!loopback) - print_aaimage(); - /* real time priority */ if (rt_prio > 0) { struct sched_param schedp; @@ -702,10 +699,15 @@ void main_mobile_loop(const char *name, int *quit, void (*myhandler)(void), cons memset(&schedp, 0, sizeof(schedp)); schedp.sched_priority = rt_prio; rc = sched_setscheduler(0, SCHED_RR, &schedp); - if (rc) + if (rc) { fprintf(stderr, "Error setting SCHED_RR with prio %d\n", rt_prio); + return; + } } + if (!loopback) + print_aaimage(); + /* prepare terminal */ tcgetattr(0, &term_orig); term = term_orig; diff --git a/src/radio/main.c b/src/radio/main.c index eb4ad93..e00ba9b 100644 --- a/src/radio/main.c +++ b/src/radio/main.c @@ -42,7 +42,7 @@ enum paging_signal; void *sender_head = NULL; int use_sdr = 0; int num_kanal = 1; /* only one channel used for debugging */ -int rt_prio = 1; +int rt_prio = 0; int fast_math = 0; void *get_sender_by_empfangsfrequenz() { return NULL; } @@ -385,8 +385,10 @@ int main(int argc, char *argv[]) memset(&schedp, 0, sizeof(schedp)); schedp.sched_priority = rt_prio; rc = sched_setscheduler(0, SCHED_RR, &schedp); - if (rc) + if (rc) { fprintf(stderr, "Error setting SCHED_RR with prio %d\n", rt_prio); + goto error; + } } double tx_frequencies[1], rx_frequencies[1]; diff --git a/src/tv/main.c b/src/tv/main.c index 74f40a9..00fd25e 100644 --- a/src/tv/main.c +++ b/src/tv/main.c @@ -48,7 +48,7 @@ enum paging_signal; void *sender_head = NULL; int use_sdr = 0; int num_kanal = 1; /* only one channel used for debugging */ -int rt_prio = 1; +int rt_prio = 0; void *get_sender_by_empfangsfrequenz() { return NULL; } @@ -331,8 +331,10 @@ static void tx_bas(sample_t *sample_bas, __attribute__((__unused__)) sample_t *s memset(&schedp, 0, sizeof(schedp)); schedp.sched_priority = rt_prio; rc = sched_setscheduler(0, SCHED_RR, &schedp); - if (rc) + if (rc) { fprintf(stderr, "Error setting SCHED_RR with prio %d\n", rt_prio); + goto error; + } } double tx_frequencies[1], rx_frequencies[1];