name = NULL;
free(name2);
- } while (tvheadend_running && avahi_do_restart);
+ } while (tvheadend_is_running() && avahi_do_restart);
return NULL;
}
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);
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));
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))
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;
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;
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;
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);
}
/* Session main loop */
- while(tvheadend_running) {
+ while(tvheadend_is_running()) {
readmsg:
reply = NULL;
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;
}
/**
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;
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");
char ubuf[UUID_HEX_SIZE];
const char *uuid = idnode_uuid_as_str(in, ubuf);
- if (!tvheadend_running)
+ if (!tvheadend_is_running())
return;
while (ic) {
if (r < 0)
goto error_lock;
- while (tvheadend_running) {
+ while (tvheadend_is_running()) {
r = tvhpoll_wait(efd, &ev, 1, -1);
if (r < 0)
break;
imagecache_image_t *img;
pthread_mutex_lock(&global_lock);
- while (tvheadend_running) {
+ while (tvheadend_is_running()) {
/* Check we're enabled */
if (!imagecache_conf.enabled) {
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);
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) {
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) {
{
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]);
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,
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;
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;
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)
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,
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);
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));
/* TODO: flush buffer? */
- while(tvheadend_running) {
+ while(tvheadend_is_running()) {
nfds = tvhpoll_wait(efd, ev, 1, -1);
if (nfds < 1) continue;
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);
}
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);
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);
const char *fcn;
#endif
- while (tvheadend_running) {
+ while (tvheadend_is_running()) {
now = mdispatch_clock_update();
/* Global monoclock timers */
const char *fcn;
#endif
- while (tvheadend_running) {
+ while (tvheadend_is_running()) {
now = gdispatch_clock_update();
/* Global timers */
umask(0);
}
- tvheadend_running = 1;
+ atomic_set(&tvheadend_running, 1);
/* Start log thread (must be done post fork) */
tvhlog_start();
htsmsg_t *m = NULL, *e = NULL;
htsmsg_field_t *f;
- if (!tvheadend_running)
+ if (!tvheadend_is_running())
return;
pthread_mutex_lock(¬ify_mutex);
pthread_mutex_lock(¬ify_mutex);
- while (tvheadend_running) {
+ while (tvheadend_is_running()) {
/* Get queue */
if (!notify_queue) {
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);
pthread_mutex_lock(&global_lock);
- while (tvheadend_running) {
+ while (tvheadend_is_running()) {
/* Wait for work */
while (!(smi = TAILQ_FIRST(&service_mapper_queue))) {
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);
/* 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);
streaming_msg_free(sm);
pthread_mutex_lock(&sq->sq_mutex);
}
- if (!tvheadend_running)
+ if (!tvheadend_is_running())
break;
streaming_queue_clear(&sq->sq_queue);
timeout = 0;
while (1) {
- if (!tvheadend_running) {
+ if (!tvheadend_is_running()) {
errbuf[0] = '\0';
tvhpoll_destroy(efd);
close(fd);
if(x == 0)
return ETIMEDOUT;
if(x == -1) {
- if (!tvheadend_running)
+ if (!tvheadend_is_running())
return ECONNRESET;
if (ERRNO_AGAIN(errno))
continue;
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;
}
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
#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;
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) {