]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
mpegts pass muxer: add kill signal / timeout fields
authorJaroslav Kysela <perex@perex.cz>
Tue, 22 Aug 2017 07:43:33 +0000 (09:43 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 22 Aug 2017 08:14:58 +0000 (10:14 +0200)
Makefile
src/input/mpegts/iptv/iptv_mux.c
src/input/mpegts/iptv/iptv_pipe.c
src/input/mpegts/iptv/iptv_private.h
src/muxer.h
src/muxer/muxer_pass.c
src/profile.c
src/prop.h
src/proplib.c [new file with mode: 0644]
src/tvheadend.h
src/utils.c

index 8fbec0fe735aa04825f82487c7bc6b5b7e047721..9dbb1c1fe0540edfa68cfde16f23de1dbd8a6bb6 100644 (file)
--- 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 \
index 10f474b99cba888c95f455aeec805702a8657efc..27fe7e85c8dd8e9948b2db61b7e984de37e4f48a 100644 (file)
@@ -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
     },
     {
index f744c532cc1f6fd16361d0badc8fb3a4aa8b68d1..43d5c0c362dc4b377bee7c3655ca4c5db0ab27aa 100644 (file)
@@ -25,7 +25,6 @@
 #include <sys/types.h>
 #include <sys/ioctl.h>
 #include <fcntl.h>
-#include <signal.h>
 #include <assert.h>
 
 /*
@@ -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)) {
index 3b108bacc0eb16061ded2f03b325fdceb6924399..970afb2caad7954fd8dfdc73d912933880166d8c 100644 (file)
 #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;
index 8cf5652458808cd3a393a1a05bdc2402c5dcd0c8..865883d2dcd2d1594235fa9ab7044636a52cc2fe 100644 (file)
@@ -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;
index 511b7f6d15aa451babe866740ffbe4633482dbe0..b764f8a7f34c3772df258385e49c0555fcd03199 100644 (file)
@@ -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",
index be5e7ed397a6d8d613045c7bacc20e9785ece385..a47b20745f99101529a0e7276353a8ea1f4997fc 100644 (file)
@@ -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;
 }
 
index c1f08372379cb5f4e72a37244b40c5907ea9389d..ae9ea2a805490c63783693e3c386f594b93c678e 100644 (file)
@@ -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 (file)
index 0000000..057b461
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#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);
+}
index 175b1e05cb942cf96646f0748388e52ce780ab6e..27850a45e7af58857f5d494e297c15872b1a2835 100644 (file)
@@ -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
  */
index c34762cf42998423313190bfc5117c751354cc94..b2860f096b3f606a1adc50920b33fe093e2a4ce6 100644 (file)
@@ -26,6 +26,7 @@
 #include <dirent.h>
 #include <unistd.h>
 #include <ctype.h>
+#include <signal.h>
 #include <net/if.h>
 
 #include <openssl/sha.h>
@@ -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;
+}