From: Jaroslav Kysela Date: Tue, 22 Aug 2017 07:43:33 +0000 (+0200) Subject: mpegts pass muxer: add kill signal / timeout fields X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e40100d427009dcd6352ad1397f5dd5991b4d59b;p=thirdparty%2Ftvheadend.git mpegts pass muxer: add kill signal / timeout fields --- diff --git a/Makefile b/Makefile index 8fbec0fe7..9dbb1c1fe 100644 --- a/Makefile +++ b/Makefile @@ -203,6 +203,7 @@ SRCS-1 = \ src/tvhlog.c \ src/idnode.c \ src/prop.c \ + src/proplib.c \ src/utils.c \ src/wrappers.c \ src/access.c \ diff --git a/src/input/mpegts/iptv/iptv_mux.c b/src/input/mpegts/iptv/iptv_mux.c index 10f474b99..27fe7e85c 100644 --- a/src/input/mpegts/iptv/iptv_mux.c +++ b/src/input/mpegts/iptv/iptv_mux.c @@ -97,20 +97,6 @@ iptv_mux_url_set ( void *p, const void *v ) return iptv_url_set(&im->mm_iptv_url, &im->mm_iptv_url_sane, v, 1, 1); } -static htsmsg_t * -iptv_muxdvr_class_kill_list ( void *o, const char *lang ) -{ - static const struct strtab tab[] = { - { N_("SIGKILL"), IPTV_KILL_KILL }, - { N_("SIGTERM"), IPTV_KILL_TERM }, - { N_("SIGINT"), IPTV_KILL_INT, }, - { N_("SIGHUP"), IPTV_KILL_HUP }, - { N_("SIGUSR1"), IPTV_KILL_USR1 }, - { N_("SIGUSR2"), IPTV_KILL_USR2 }, - }; - return strtab2htsmsg(tab, 1, lang); -} - const idclass_t iptv_mux_class = { .ic_super = &mpegts_mux_class, @@ -207,7 +193,7 @@ const idclass_t iptv_mux_class = .id = "iptv_kill", .name = N_("Kill signal (pipe)"), .off = offsetof(iptv_mux_t, mm_iptv_kill), - .list = iptv_muxdvr_class_kill_list, + .list = proplib_kill_list, .opts = PO_EXPERT }, { diff --git a/src/input/mpegts/iptv/iptv_pipe.c b/src/input/mpegts/iptv/iptv_pipe.c index f744c532c..43d5c0c36 100644 --- a/src/input/mpegts/iptv/iptv_pipe.c +++ b/src/input/mpegts/iptv/iptv_pipe.c @@ -25,7 +25,6 @@ #include #include #include -#include #include /* @@ -76,26 +75,13 @@ err: return -1; } -static int -iptv_pipe_kill_sig(iptv_mux_t *im) -{ - switch (im->mm_iptv_kill) { - case IPTV_KILL_TERM: return SIGTERM; - case IPTV_KILL_INT: return SIGINT; - case IPTV_KILL_HUP: return SIGHUP; - case IPTV_KILL_USR1: return SIGUSR1; - case IPTV_KILL_USR2: return SIGUSR2; - } - return SIGKILL; -} - static void iptv_pipe_stop ( iptv_mux_t *im ) { int rd = im->mm_iptv_fd; pid_t pid = (intptr_t)im->im_data; - spawn_kill(pid, iptv_pipe_kill_sig(im), im->mm_iptv_kill_timeout); + spawn_kill(pid, tvh_kill_to_sig(im->mm_iptv_kill), im->mm_iptv_kill_timeout); if (rd > 0) close(rd); im->mm_iptv_fd = -1; @@ -120,7 +106,7 @@ iptv_pipe_read ( iptv_mux_t *im ) if (r <= 0) { close(rd); pid = (intptr_t)im->im_data; - spawn_kill(pid, iptv_pipe_kill_sig(im), im->mm_iptv_kill_timeout); + spawn_kill(pid, tvh_kill_to_sig(im->mm_iptv_kill), im->mm_iptv_kill_timeout); im->mm_iptv_fd = -1; im->im_data = NULL; if (mclk() < im->mm_iptv_respawn_last + sec2mono(2)) { diff --git a/src/input/mpegts/iptv/iptv_private.h b/src/input/mpegts/iptv/iptv_private.h index 3b108bacc..970afb2ca 100644 --- a/src/input/mpegts/iptv/iptv_private.h +++ b/src/input/mpegts/iptv/iptv_private.h @@ -29,13 +29,6 @@ #define IPTV_PKTS 32 #define IPTV_PKT_PAYLOAD 1472 -#define IPTV_KILL_KILL 0 -#define IPTV_KILL_TERM 1 -#define IPTV_KILL_INT 2 -#define IPTV_KILL_HUP 3 -#define IPTV_KILL_USR1 4 -#define IPTV_KILL_USR2 5 - extern pthread_mutex_t iptv_lock; typedef struct iptv_input iptv_input_t; diff --git a/src/muxer.h b/src/muxer.h index 8cf565245..865883d2d 100644 --- a/src/muxer.h +++ b/src/muxer.h @@ -74,6 +74,8 @@ typedef struct muxer_config { int m_rewrite_eit; char *m_cmdline; char *m_mime; + int m_killsig; + int m_killtimeout; } pass; struct { int m_dvbsub_reorder; diff --git a/src/muxer/muxer_pass.c b/src/muxer/muxer_pass.c index 511b7f6d1..b764f8a7f 100644 --- a/src/muxer/muxer_pass.c +++ b/src/muxer/muxer_pass.c @@ -598,7 +598,8 @@ pass_muxer_close(muxer_t *m) pass_muxer_t *pm = (pass_muxer_t*)m; if(pm->pm_spawn_pid > 0) - spawn_kill(pm->pm_spawn_pid, SIGTERM, 15); + spawn_kill(pm->pm_spawn_pid, tvh_kill_to_sig(pm->m_config.u.pass.m_killsig), + pm->m_config.u.pass.m_killtimeout); if(pm->pm_seekable && close(pm->pm_ofd)) { pm->pm_error = errno; tvherror(LS_PASS, "%s: Unable to close file, close failed -- %s", diff --git a/src/profile.c b/src/profile.c index be5e7ed39..a47b20745 100644 --- a/src/profile.c +++ b/src/profile.c @@ -1434,6 +1434,8 @@ typedef struct profile_mpegts_spawn { profile_t; char *pro_cmdline; char *pro_mime; + int pro_killsig; + int pro_killtimeout; } profile_mpegts_spawn_t; const idclass_t profile_mpegts_spawn_class = @@ -1472,6 +1474,25 @@ const idclass_t profile_mpegts_spawn_class = .off = offsetof(profile_mpegts_spawn_t, pro_mime), .group = 2 }, + { + .type = PT_INT, + .id = "killsig", + .name = N_("Kill signal (pipe)"), + .off = offsetof(profile_mpegts_spawn_t, pro_killsig), + .list = proplib_kill_list, + .opts = PO_EXPERT, + .def.i = TVH_KILL_TERM, + .group = 2 + }, + { + .type = PT_INT, + .id = "kill_timeout", + .name = N_("Kill timeout (pipe/secs)"), + .off = offsetof(profile_mpegts_spawn_t, pro_killtimeout), + .opts = PO_EXPERT, + .def.i = 15, + .group = 2 + }, { } } }; @@ -1497,6 +1518,8 @@ profile_mpegts_spawn_reopen(profile_chain_t *prch, c.u.pass.m_rewrite_eit = 1; mystrset(&c.u.pass.m_cmdline, pro->pro_cmdline); mystrset(&c.u.pass.m_mime, pro->pro_mime); + c.u.pass.m_killsig = pro->pro_killsig; + c.u.pass.m_killtimeout = pro->pro_killtimeout; assert(!prch->prch_muxer); prch->prch_muxer = muxer_create(&c); @@ -1533,6 +1556,8 @@ profile_mpegts_spawn_builder(void) pro->pro_free = profile_mpegts_spawn_free; pro->pro_reopen = profile_mpegts_spawn_reopen; pro->pro_open = profile_mpegts_spawn_open; + pro->pro_killsig = TVH_KILL_TERM; + pro->pro_killtimeout = 15; return (profile_t *)pro; } diff --git a/src/prop.h b/src/prop.h index c1f083723..ae9ea2a80 100644 --- a/src/prop.h +++ b/src/prop.h @@ -160,6 +160,9 @@ prop_doc_##name(const struct property *p, const char *lang) \ { return prop_md_doc(tvh_doc_##name##_property, lang); } +/* helpers */ +htsmsg_t *proplib_kill_list ( void *o, const char *lang ); + #endif /* __TVH_PROP_H__ */ /****************************************************************************** diff --git a/src/proplib.c b/src/proplib.c new file mode 100644 index 000000000..057b46181 --- /dev/null +++ b/src/proplib.c @@ -0,0 +1,40 @@ +/* + * Tvheadend - property system library (part of idnode) + * + * Copyright (C) 2017 Jaroslav Kysela + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "tvheadend.h" +#include "prop.h" +#include "tvh_locale.h" +#include "lang_str.h" + +htsmsg_t * +proplib_kill_list ( void *o, const char *lang ) +{ + static const struct strtab tab[] = { + { N_("SIGKILL"), TVH_KILL_KILL }, + { N_("SIGTERM"), TVH_KILL_TERM }, + { N_("SIGINT"), TVH_KILL_INT, }, + { N_("SIGHUP"), TVH_KILL_HUP }, + { N_("SIGUSR1"), TVH_KILL_USR1 }, + { N_("SIGUSR2"), TVH_KILL_USR2 }, + }; + return strtab2htsmsg(tab, 1, lang); +} diff --git a/src/tvheadend.h b/src/tvheadend.h index 175b1e05c..27850a45e 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -266,6 +266,18 @@ LIST_HEAD(dvr_timerec_entry_list, dvr_timerec_entry); TAILQ_HEAD(th_pktref_queue, th_pktref); LIST_HEAD(streaming_target_list, streaming_target); +/** + * + */ +#define TVH_KILL_KILL 0 +#define TVH_KILL_TERM 1 +#define TVH_KILL_INT 2 +#define TVH_KILL_HUP 3 +#define TVH_KILL_USR1 4 +#define TVH_KILL_USR2 5 + +int tvh_kill_to_sig(int tvh_kill); + /** * Stream component types */ diff --git a/src/utils.c b/src/utils.c index c34762cf4..b2860f096 100644 --- a/src/utils.c +++ b/src/utils.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -868,3 +869,16 @@ gmtime2local(time_t gmt, char *buf, size_t buflen) strftime(buf, buflen, "%F;%T(%z)", &tm); return buf; } + +int +tvh_kill_to_sig(int tvh_kill) +{ + switch (tvh_kill) { + case TVH_KILL_TERM: return SIGTERM; + case TVH_KILL_INT: return SIGINT; + case TVH_KILL_HUP: return SIGHUP; + case TVH_KILL_USR1: return SIGUSR1; + case TVH_KILL_USR2: return SIGUSR2; + } + return SIGKILL; +}