]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
tvheadend_running -> tvheadend_is_running() change
authorJaroslav Kysela <perex@perex.cz>
Tue, 8 Mar 2016 17:12:17 +0000 (18:12 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 8 Mar 2016 17:12:17 +0000 (18:12 +0100)
22 files changed:
src/avahi.c
src/descrambler/capmt.c
src/descrambler/cwc.c
src/epggrab/otamux.c
src/htsp_server.c
src/httpc.c
src/idnode.c
src/imagecache.c
src/input/mpegts/iptv/iptv.c
src/input/mpegts/linuxdvb/linuxdvb_ca.c
src/input/mpegts/linuxdvb/linuxdvb_frontend.c
src/input/mpegts/satip/satip.c
src/input/mpegts/satip/satip_frontend.c
src/input/mpegts/tvhdhomerun/tvhdhomerun.c
src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c
src/main.c
src/notify.c
src/service.c
src/service_mapper.c
src/tcp.c
src/tvheadend.h
src/webui/webui.c

index 923986e23a449e64eb5eca515b254c0f09e5e835..afa5b953f441709840bf1b24b147aba65cdd5252 100644 (file)
@@ -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;
 }
index 11e0d9882209731acb106327633961f0d0931600..796f405fda6949e0ffef9a83eb3522c5d21368d1 100644 (file)
@@ -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));
index cf619a81d677a4b5e5ad5046ea2f38f0136d6d64..37fbdcc194b4f8962d45ccd2240476cdeaf4319e 100644 (file)
@@ -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;
index 63d1e9b81b0dcdb3dac86f5d2ceaaebad22a047b..60bf4fd27a87bbca89c0f2dd42393a5b09aa2e42 100644 (file)
@@ -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);
 }
 
index 08998a29e5cdec8344453b98d77e169999a87169..a0e031368b42e9c66203c0098e8ab5e0650d090d 100644 (file)
@@ -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;
 }
 
 /**
index e404a8a1402e726931e20005d4d934c3543c8e69..978ec0959dc61ac9be8434639070827c5ae824ce 100644 (file)
@@ -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");
index 37ede547c1f02eaa69cd4dd9a578080f6424cba9..cc54b5f63fd4e4d2dced21ebd3fb503bb7b4a4bb 100644 (file)
@@ -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) {
index 0466e2fa2b49821a15d9a56139890bd9626d1aba..b87057757efe29c8abd2d41ea645ac66052f6611 100644 (file)
@@ -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) {
index a140867273e2ef6954e4982419a4dab5fb1f8f57..19182c332375e61a9b0accbc2b7a3c03459d0d9f 100644 (file)
@@ -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);
index 41b586592f87dd219bab394fc1b1a8eea8b1bf49..c28b4d44ac27adc274efc10e4ba0f03b1ca68954 100644 (file)
@@ -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) {
index b28b6747b330a2a6b6d0337c68291bbe22a569a5..b7c9f264bb32e96404803babb3871417a5dbe833 100644 (file)
@@ -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) {
index 667925486405e93cf3fb8db670336f70e3a73b9d..0c5ff585a042583d874171891a5f5666ea73a667 100644 (file)
@@ -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,
index cb007bdd0f70b3e490aff61224953f976cc48b04..5d4f6cb0d4bde03b97be69208d8c2c26423cb1e4 100644 (file)
@@ -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)
index 3706b9e6e0f2d8dbb7ac0eda87b0cc25d6c4debe..54ef35c3e1a109fbfe4cc332c0bd9210352fc32c 100644 (file)
@@ -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));
index 48459eb890863f65fbf0a5935079730c66a6e92d..179774afc8aa75fb33b5ca6f04d9209d6d294d75 100644 (file)
@@ -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;
index c6c37fb64e9743deaa2a5336b8fc1351284607a7..3ab20345ea60d9fb8cb3301370320f6ffb286f1c 100644 (file)
@@ -209,7 +209,7 @@ doexit(int x)
   if (pthread_self() != main_tid)
     pthread_kill(main_tid, SIGTERM);
   pthread_cond_signal(&gtimer_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();
index 4c7dd8f18f9bd146fa535d028396aae99368fbd6..e05ec92be98418810528a016285fc94fc7f18f1c 100644 (file)
@@ -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(&notify_mutex);
@@ -88,7 +88,7 @@ notify_thread ( void *p )
 
   pthread_mutex_lock(&notify_mutex);
 
-  while (tvheadend_running) {
+  while (tvheadend_is_running()) {
 
     /* Get queue */
     if (!notify_queue) {
index 351345a49fcf84d0973e2ddd295201785dc816b6..4939f15a1447c9784b64bd8ab49f93e103b71f26 100644 (file)
@@ -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);
index b3f1a73cc5b5613d63fe6f6d246b8b245dd8fd29..d04fc53de4530d0267cc3a8cb15abdeae72235ce 100644 (file)
@@ -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);
index ebc6287ebb4567262e4a3ed443f885a0e959779d..d45c26a490fe7cae4e9421e356912c8944c80e9e 100644 (file)
--- 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;
     }
index ffc5d5503066f6e58c3b3427f2a742a415f5b86e..43c5defe9b23543782eef8e786ab084a976fa9df 100644 (file)
@@ -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;
index 8bf7f551a5a8b405133704bb1ef6b61697c1a7b9..5c2d3ed80e5a57a98b8d4ddb5d27569936bbfb20 100644 (file)
@@ -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) {