From: Jaroslav Kysela Date: Tue, 8 Mar 2016 17:12:17 +0000 (+0100) Subject: tvheadend_running -> tvheadend_is_running() change X-Git-Tag: v4.2.1~930 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b4bb4344a28dbb2852040968036986a180464f1;p=thirdparty%2Ftvheadend.git tvheadend_running -> tvheadend_is_running() change --- diff --git a/src/avahi.c b/src/avahi.c index 923986e23..afa5b953f 100644 --- a/src/avahi.c +++ b/src/avahi.c @@ -290,7 +290,7 @@ avahi_thread(void *aux) name = NULL; free(name2); - } while (tvheadend_running && avahi_do_restart); + } while (tvheadend_is_running() && avahi_do_restart); return NULL; } diff --git a/src/descrambler/capmt.c b/src/descrambler/capmt.c index 11e0d9882..796f405fd 100644 --- a/src/descrambler/capmt.c +++ b/src/descrambler/capmt.c @@ -491,7 +491,7 @@ capmt_connect(capmt_t *capmt, int i) fd = tcp_connect(capmt->capmt_sockfile, capmt->capmt_port, NULL, errbuf, sizeof(errbuf), 2); - if (fd < 0 && tvheadend_running) { + if (fd < 0 && tvheadend_is_running()) { tvhlog(LOG_ERR, "capmt", "%s: Cannot connect to %s:%i (%s); Do you have OSCam running?", capmt_name(capmt), capmt->capmt_sockfile, capmt->capmt_port, errbuf); @@ -512,7 +512,7 @@ capmt_connect(capmt_t *capmt, int i) if (fd < 0 || connect(fd, (const struct sockaddr*)&serv_addr_un, sizeof(serv_addr_un)) != 0) { - if (tvheadend_running) + if (tvheadend_is_running()) tvhlog(LOG_ERR, "capmt", "%s: Cannot connect to %s (%s); Do you have OSCam running?", capmt_name(capmt), capmt->capmt_sockfile, strerror(errno)); diff --git a/src/descrambler/cwc.c b/src/descrambler/cwc.c index cf619a81d..37fbdcc19 100644 --- a/src/descrambler/cwc.c +++ b/src/descrambler/cwc.c @@ -946,7 +946,7 @@ cwc_read(cwc_t *cwc, void *buf, size_t len, int timeout) r = tcp_read_timeout(cwc->cwc_fd, buf, len, timeout); pthread_mutex_lock(&cwc->cwc_mutex); - if (r && tvheadend_running) + if (r && tvheadend_is_running()) tvhwarn("cwc", "read error %d (%s)", r, strerror(r)); if(cwc_must_break(cwc)) @@ -966,7 +966,7 @@ cwc_read_message(cwc_t *cwc, const char *state, int timeout) int msglen, r; if((r = cwc_read(cwc, buf, 2, timeout))) { - if (tvheadend_running) + if (tvheadend_is_running()) tvhlog(LOG_INFO, "cwc", "%s:%i: %s: Read error (header): %s", cwc->cwc_hostname, cwc->cwc_port, state, strerror(r)); return -1; @@ -974,7 +974,7 @@ cwc_read_message(cwc_t *cwc, const char *state, int timeout) msglen = (buf[0] << 8) | buf[1]; if(msglen >= CWS_NETMSGSIZE) { - if (tvheadend_running) + if (tvheadend_is_running()) tvhlog(LOG_INFO, "cwc", "%s:%i: %s: Invalid message size: %d", cwc->cwc_hostname, cwc->cwc_port, state, msglen); return -1; @@ -984,7 +984,7 @@ cwc_read_message(cwc_t *cwc, const char *state, int timeout) so just wait 1 second here */ if((r = cwc_read(cwc, cwc->cwc_buf + 2, msglen, 1000))) { - if (tvheadend_running) + if (tvheadend_is_running()) tvhlog(LOG_INFO, "cwc", "%s:%i: %s: Read error: %s", cwc->cwc_hostname, cwc->cwc_port, state, strerror(r)); return -1; diff --git a/src/epggrab/otamux.c b/src/epggrab/otamux.c index 63d1e9b81..60bf4fd27 100644 --- a/src/epggrab/otamux.c +++ b/src/epggrab/otamux.c @@ -688,7 +688,7 @@ epggrab_ota_service_trace ( epggrab_ota_mux_t *ota, if (mm && svc) { mpegts_mux_nice_name(mm, buf, sizeof(buf)); tvhtrace("epggrab", "ota %s %s service %s", buf, op, svc->s_nicename); - } else if (tvheadend_running) + } else if (tvheadend_is_running()) tvhtrace("epggrab", "ota %s, problem? (%p %p)", op, mm, svc); } diff --git a/src/htsp_server.c b/src/htsp_server.c index 08998a29e..a0e031368 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -3061,7 +3061,7 @@ htsp_read_loop(htsp_connection_t *htsp) /* Session main loop */ - while(tvheadend_running) { + while(tvheadend_is_running()) { readmsg: reply = NULL; @@ -3128,7 +3128,7 @@ readmsg: pthread_mutex_lock(&global_lock); tcp_connection_land(tcp_id); pthread_mutex_unlock(&global_lock); - return tvheadend_running ? r : 0; + return tvheadend_is_running() ? r : 0; } /** diff --git a/src/httpc.c b/src/httpc.c index e404a8a14..978ec0959 100644 --- a/src/httpc.c +++ b/src/httpc.c @@ -1839,7 +1839,7 @@ http_client_testsuite_run( void ) urlinit(&u2); http_arg_init(&args); efd = tvhpoll_create(1); - while (fgets(line, sizeof(line), fp) != NULL && tvheadend_running) { + while (fgets(line, sizeof(line), fp) != NULL && tvheadend_is_running()) { if (line[0] == '\0') continue; s = line + strlen(line) - 1; @@ -1954,7 +1954,7 @@ http_client_testsuite_run( void ) fprintf(stderr, "HTTPCTS Send Failed %s\n", strerror(-r)); goto fatal; } - while (tvheadend_running) { + while (tvheadend_is_running()) { fprintf(stderr, "HTTPCTS: Enter Poll\n"); r = tvhpoll_wait(efd, &ev, 1, -1); fprintf(stderr, "HTTPCTS: Leave Poll: %i (%s)\n", r, r < 0 ? val2str(-r, ERRNO_tab) : "OK"); diff --git a/src/idnode.c b/src/idnode.c index 37ede547c..cc54b5f63 100644 --- a/src/idnode.c +++ b/src/idnode.c @@ -1732,7 +1732,7 @@ idnode_notify ( idnode_t *in, const char *action ) char ubuf[UUID_HEX_SIZE]; const char *uuid = idnode_uuid_as_str(in, ubuf); - if (!tvheadend_running) + if (!tvheadend_is_running()) return; while (ic) { diff --git a/src/imagecache.c b/src/imagecache.c index 0466e2fa2..b87057757 100644 --- a/src/imagecache.c +++ b/src/imagecache.c @@ -295,7 +295,7 @@ imagecache_image_fetch ( imagecache_image_t *img ) if (r < 0) goto error_lock; - while (tvheadend_running) { + while (tvheadend_is_running()) { r = tvhpoll_wait(efd, &ev, 1, -1); if (r < 0) break; @@ -341,7 +341,7 @@ imagecache_thread ( void *p ) imagecache_image_t *img; pthread_mutex_lock(&global_lock); - while (tvheadend_running) { + while (tvheadend_is_running()) { /* Check we're enabled */ if (!imagecache_conf.enabled) { diff --git a/src/input/mpegts/iptv/iptv.c b/src/input/mpegts/iptv/iptv.c index a14086727..19182c332 100644 --- a/src/input/mpegts/iptv/iptv.c +++ b/src/input/mpegts/iptv/iptv.c @@ -457,10 +457,10 @@ iptv_input_thread ( void *aux ) iptv_mux_t *im; tvhpoll_event_t ev; - while ( tvheadend_running ) { + while ( tvheadend_is_running() ) { nfds = tvhpoll_wait(iptv_poll, &ev, 1, -1); if ( nfds < 0 ) { - if (tvheadend_running && !ERRNO_AGAIN(errno)) { + if (tvheadend_is_running() && !ERRNO_AGAIN(errno)) { tvhlog(LOG_ERR, "iptv", "poll() error %s, sleeping 1 second", strerror(errno)); sleep(1); diff --git a/src/input/mpegts/linuxdvb/linuxdvb_ca.c b/src/input/mpegts/linuxdvb/linuxdvb_ca.c index 41b586592..c28b4d44a 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_ca.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_ca.c @@ -700,7 +700,7 @@ linuxdvb_ca_en50221_thread ( void *aux ) lca->lca_tc = en50221_tl_new_tc(lca->lca_tl, slot_id); - while (tvheadend_running && lca->lca_en50221_thread_running) { + while (tvheadend_is_running() && lca->lca_en50221_thread_running) { int error; if ((error = en50221_tl_poll(lca->lca_tl)) != 0) { if (error != lasterror) { diff --git a/src/input/mpegts/linuxdvb/linuxdvb_frontend.c b/src/input/mpegts/linuxdvb/linuxdvb_frontend.c index b28b6747b..b7c9f264b 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_frontend.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_frontend.c @@ -1198,7 +1198,7 @@ linuxdvb_frontend_input_thread ( void *aux ) linuxdvb_update_pids(lfe, name, &tuned, pids, ARRAY_SIZE(pids)); /* Read */ - while (tvheadend_running) { + while (tvheadend_is_running()) { nfds = tvhpoll_wait(efd, ev, 1, 150); if (nfds == 0) { /* timeout */ if (nodata == 0) { diff --git a/src/input/mpegts/satip/satip.c b/src/input/mpegts/satip/satip.c index 667925486..0c5ff585a 100644 --- a/src/input/mpegts/satip/satip.c +++ b/src/input/mpegts/satip/satip.c @@ -1220,7 +1220,7 @@ satip_discovery_static_timer_cb(void *aux) { int i; - if (!tvheadend_running) + if (!tvheadend_is_running()) return; for (i = 0; i < satip_static_clients->num; i++) satip_discovery_static(satip_static_clients->str[i]); @@ -1230,7 +1230,7 @@ satip_discovery_static_timer_cb(void *aux) static void satip_discovery_timer_cb(void *aux) { - if (!tvheadend_running) + if (!tvheadend_is_running()) return; if (!upnp_running) { mtimer_arm_rel(&satip_discovery_timer, satip_discovery_timer_cb, diff --git a/src/input/mpegts/satip/satip_frontend.c b/src/input/mpegts/satip/satip_frontend.c index cb007bdd0..5d4f6cb0d 100644 --- a/src/input/mpegts/satip/satip_frontend.c +++ b/src/input/mpegts/satip/satip_frontend.c @@ -1226,7 +1226,7 @@ new_tune: nfds = tvhpoll_wait(efd, ev, 1, rtsp ? 50 : -1); - if (!tvheadend_running) { exit_flag = 1; goto done; } + if (!tvheadend_is_running()) { exit_flag = 1; goto done; } if (rtsp && getfastmonoclock() - u64_2 > 50000) /* 50ms */ satip_frontend_close_rtsp(lfe, buf, efd, &rtsp); if (nfds <= 0) continue; @@ -1349,7 +1349,7 @@ new_tune: tc = 1; nfds = tvhpoll_wait(efd, ev, 1, r); - if (!tvheadend_running) { exit_flag = 1; goto done; } + if (!tvheadend_is_running()) { exit_flag = 1; goto done; } if (nfds < 0) continue; if (nfds == 0) break; @@ -1463,7 +1463,7 @@ new_tune: nfds = tvhpoll_wait(efd, ev, 1, ms); - if (!tvheadend_running || exit_flag) { + if (!tvheadend_is_running() || exit_flag) { exit_flag = 1; running = 0; if (reply++ > 5) diff --git a/src/input/mpegts/tvhdhomerun/tvhdhomerun.c b/src/input/mpegts/tvhdhomerun/tvhdhomerun.c index 3706b9e6e..54ef35c3e 100644 --- a/src/input/mpegts/tvhdhomerun/tvhdhomerun.c +++ b/src/input/mpegts/tvhdhomerun/tvhdhomerun.c @@ -348,7 +348,7 @@ tvhdhomerun_device_discovery_thread( void *aux ) struct hdhomerun_discover_device_t result_list[MAX_HDHOMERUN_DEVICES]; int numDevices, brk; - while (tvheadend_running) { + while (tvheadend_is_running()) { numDevices = hdhomerun_discover_find_devices_custom(0, @@ -364,7 +364,7 @@ tvhdhomerun_device_discovery_thread( void *aux ) if ( cDev->device_type == HDHOMERUN_DEVICE_TYPE_TUNER ) { pthread_mutex_lock(&global_lock); if ( !tvhdhomerun_device_find(cDev->device_id) && - tvheadend_running ) { + tvheadend_is_running() ) { tvhlog(LOG_INFO, "tvhdhomerun","Found HDHomerun device %08x with %d tuners", cDev->device_id, cDev->tuner_count); tvhdhomerun_device_create(cDev); @@ -376,7 +376,7 @@ tvhdhomerun_device_discovery_thread( void *aux ) pthread_mutex_lock(&tvhdhomerun_discovery_lock); brk = 0; - if (tvheadend_running) { + if (tvheadend_is_running()) { brk = tvh_cond_timedwait(&tvhdhomerun_discovery_cond, &tvhdhomerun_discovery_lock, mclk() + sec2mono(15)); diff --git a/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c b/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c index 48459eb89..179774afc 100644 --- a/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c +++ b/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c @@ -172,7 +172,7 @@ tvhdhomerun_frontend_input_thread ( void *aux ) /* TODO: flush buffer? */ - while(tvheadend_running) { + while(tvheadend_is_running()) { nfds = tvhpoll_wait(efd, ev, 1, -1); if (nfds < 1) continue; diff --git a/src/main.c b/src/main.c index c6c37fb64..3ab20345e 100644 --- a/src/main.c +++ b/src/main.c @@ -209,7 +209,7 @@ doexit(int x) if (pthread_self() != main_tid) pthread_kill(main_tid, SIGTERM); pthread_cond_signal(>imer_cond); - tvheadend_running = 0; + atomic_set(&tvheadend_running, 0); signal(x, doexit); } @@ -442,7 +442,7 @@ tasklet_thread ( void *aux ) tvhtread_renice(20); pthread_mutex_lock(&tasklet_lock); - while (tvheadend_running) { + while (tvheadend_is_running()) { tsk = TAILQ_FIRST(&tasklets); if (tsk == NULL) { tvh_cond_wait(&tasklet_cond, &tasklet_lock); @@ -546,7 +546,7 @@ mdispatch_clock_update(void) static void * mtimer_tick_thread(void *aux) { - while (tvheadend_running) { + while (tvheadend_is_running()) { /* update clocks each 10x in one second */ atomic_set_s64(&__mdispatch_clock, getmonoclock()); tvh_safe_usleep(100000); @@ -569,7 +569,7 @@ mtimer_thread(void *aux) const char *fcn; #endif - while (tvheadend_running) { + while (tvheadend_is_running()) { now = mdispatch_clock_update(); /* Global monoclock timers */ @@ -642,7 +642,7 @@ mainloop(void) const char *fcn; #endif - while (tvheadend_running) { + while (tvheadend_is_running()) { now = gdispatch_clock_update(); /* Global timers */ @@ -1088,7 +1088,7 @@ main(int argc, char **argv) umask(0); } - tvheadend_running = 1; + atomic_set(&tvheadend_running, 1); /* Start log thread (must be done post fork) */ tvhlog_start(); diff --git a/src/notify.c b/src/notify.c index 4c7dd8f18..e05ec92be 100644 --- a/src/notify.c +++ b/src/notify.c @@ -55,7 +55,7 @@ notify_delayed(const char *id, const char *event, const char *action) htsmsg_t *m = NULL, *e = NULL; htsmsg_field_t *f; - if (!tvheadend_running) + if (!tvheadend_is_running()) return; pthread_mutex_lock(¬ify_mutex); @@ -88,7 +88,7 @@ notify_thread ( void *p ) pthread_mutex_lock(¬ify_mutex); - while (tvheadend_running) { + while (tvheadend_is_running()) { /* Get queue */ if (!notify_queue) { diff --git a/src/service.c b/src/service.c index 351345a49..4939f15a1 100644 --- a/src/service.c +++ b/src/service.c @@ -1448,7 +1448,7 @@ service_saver(void *aux) pthread_mutex_lock(&pending_save_mutex); - while(tvheadend_running) { + while(tvheadend_is_running()) { if((t = TAILQ_FIRST(&pending_save_queue)) == NULL) { tvh_cond_wait(&pending_save_cond, &pending_save_mutex); diff --git a/src/service_mapper.c b/src/service_mapper.c index b3f1a73cc..d04fc53de 100644 --- a/src/service_mapper.c +++ b/src/service_mapper.c @@ -304,7 +304,7 @@ service_mapper_thread ( void *aux ) pthread_mutex_lock(&global_lock); - while (tvheadend_running) { + while (tvheadend_is_running()) { /* Wait for work */ while (!(smi = TAILQ_FIRST(&service_mapper_queue))) { @@ -313,10 +313,10 @@ service_mapper_thread ( void *aux ) tvhinfo("service_mapper", "idle"); } tvh_cond_wait(&service_mapper_cond, &global_lock); - if (!tvheadend_running) + if (!tvheadend_is_running()) break; } - if (!tvheadend_running) + if (!tvheadend_is_running()) break; s = smi->s; service_mapper_remove(s); @@ -350,15 +350,15 @@ service_mapper_thread ( void *aux ) /* Wait */ run = 1; pthread_mutex_lock(&sq->sq_mutex); - while(tvheadend_running && run) { + while(tvheadend_is_running() && run) { /* Wait for message */ while((sm = TAILQ_FIRST(&sq->sq_queue)) == NULL) { tvh_cond_wait(&sq->sq_cond, &sq->sq_mutex); - if (!tvheadend_running) + if (!tvheadend_is_running()) break; } - if (!tvheadend_running) + if (!tvheadend_is_running()) break; streaming_queue_remove(sq, sm); @@ -382,7 +382,7 @@ service_mapper_thread ( void *aux ) streaming_msg_free(sm); pthread_mutex_lock(&sq->sq_mutex); } - if (!tvheadend_running) + if (!tvheadend_is_running()) break; streaming_queue_clear(&sq->sq_queue); diff --git a/src/tcp.c b/src/tcp.c index ebc6287eb..d45c26a49 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -148,7 +148,7 @@ tcp_connect(const char *hostname, int port, const char *bindaddr, timeout = 0; while (1) { - if (!tvheadend_running) { + if (!tvheadend_is_running()) { errbuf[0] = '\0'; tvhpoll_destroy(efd); close(fd); @@ -352,7 +352,7 @@ tcp_read_timeout(int fd, void *buf, size_t len, int timeout) if(x == 0) return ETIMEDOUT; if(x == -1) { - if (!tvheadend_running) + if (!tvheadend_is_running()) return ECONNRESET; if (ERRNO_AGAIN(errno)) continue; @@ -550,7 +550,7 @@ try_again: pthread_mutex_unlock(&global_lock); tvh_safe_usleep(250000); pthread_mutex_lock(&global_lock); - if (tvheadend_running) + if (tvheadend_is_running()) goto try_again; return NULL; } diff --git a/src/tvheadend.h b/src/tvheadend.h index ffc5d5503..43c5defe9 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -67,12 +67,18 @@ typedef struct { const char *name; const uint32_t *enabled; } tvh_caps_t; + extern int tvheadend_running; extern const char *tvheadend_version; extern const char *tvheadend_cwd; extern const char *tvheadend_webroot; extern const tvh_caps_t tvheadend_capabilities[]; +static inline int tvheadend_is_running(void) +{ + return atomic_get(&tvheadend_running); +} + htsmsg_t *tvheadend_capabilities_list(int check); typedef struct str_list @@ -85,8 +91,6 @@ typedef struct str_list #define PTS_UNSET INT64_C(0x8000000000000000) #define PTS_MASK INT64_C(0x00000001ffffffff) -extern int tvheadend_running; - extern pthread_mutex_t global_lock; extern pthread_mutex_t tasklet_lock; extern pthread_mutex_t fork_lock; diff --git a/src/webui/webui.c b/src/webui/webui.c index 8bf7f551a..5c2d3ed80 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -338,7 +338,7 @@ http_stream_run(http_connection_t *hc, profile_chain_t *prch, pthread_mutex_unlock(&sq->sq_mutex); } - while(!hc->hc_shutdown && run && tvheadend_running) { + while(!hc->hc_shutdown && run && tvheadend_is_running()) { pthread_mutex_lock(&sq->sq_mutex); sm = TAILQ_FIRST(&sq->sq_queue); if(sm == NULL) {