tsdecrypt reads and decrypts CSA encrypted incoming mpeg transport stream over UDP/RTP using code words obtained from OSCAM or similar CAM server. tsdecrypt communicates with CAM server using cs378x (camd35 over tcp) protocol or newcamd protocol. https://georgi.unixsol.org/programs/tsdecrypt/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tsdecrypt.c 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. /*
  2. * tsdecrypt
  3. * Copyright (C) 2011 Unix Solutions Ltd.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  17. */
  18. #include <stdlib.h>
  19. #include <unistd.h>
  20. #include <getopt.h>
  21. #include <string.h>
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24. #include <signal.h>
  25. #include <fcntl.h>
  26. #include <errno.h>
  27. #include "data.h"
  28. #include "util.h"
  29. #include "camd.h"
  30. #include "process.h"
  31. #include "udp.h"
  32. #define PROGRAM_NAME "tsdecrypt"
  33. static const char *program_id = PROGRAM_NAME " " GIT_VER " build " BUILD_ID;
  34. static int keep_running = 1;
  35. static void LOG_func(const char *msg) {
  36. char date[64];
  37. struct tm tm;
  38. time_t now;
  39. now = time(NULL);
  40. localtime_r(&now, &tm);
  41. strftime(date, sizeof(date), "%F %H:%M:%S", localtime(&now));
  42. fprintf(stderr, "%s | %s", date, msg);
  43. }
  44. static const struct option long_options[] = {
  45. { "ident", required_argument, NULL, 'i' },
  46. { "daemon", required_argument, NULL, 'd' },
  47. { "syslog-host", required_argument, NULL, 'l' },
  48. { "syslog-port", required_argument, NULL, 'L' },
  49. { "input", required_argument, NULL, 'I' },
  50. { "input-rtp", no_argument, NULL, 'R' },
  51. { "input-ignore-disc", no_argument, NULL, 'z' },
  52. { "output", required_argument, NULL, 'O' },
  53. { "output-intf", required_argument, NULL, 'o' },
  54. { "output-ttl", required_argument, NULL, 't' },
  55. { "output-filter", no_argument, NULL, 'p' },
  56. { "ca-system", required_argument, NULL, 'c' },
  57. { "camd-server", required_argument, NULL, 's' },
  58. { "camd-user", required_argument, NULL, 'U' },
  59. { "camd-pass", required_argument, NULL, 'P' },
  60. { "camd-pkt-delay", required_argument, NULL, 'y' },
  61. { "emm", no_argument, NULL, 'e' },
  62. { "emm-pid", required_argument, NULL, 'Z' },
  63. { "emm-only", no_argument, NULL, 'E' },
  64. { "emm-report-time", required_argument, NULL, 'f' },
  65. { "ecm-pid", required_argument, NULL, 'X' },
  66. { "ecm-irdeto-type", required_argument, NULL, 'G' },
  67. { "debug", required_argument, NULL, 'D' },
  68. { "help", no_argument, NULL, 'h' },
  69. { 0, 0, 0, 0 }
  70. };
  71. static void show_help(struct ts *ts) {
  72. printf("%s\n", program_id);
  73. printf("Copyright (c) 2011 Unix Solutions Ltd.\n");
  74. printf("\n");
  75. printf(" Usage: " PROGRAM_NAME " [opts]\n");
  76. printf("\n");
  77. printf("Daemon options:\n");
  78. printf(" -i --ident <server> | Format PROVIDER/CHANNEL. Default: empty\n");
  79. printf(" -d --daemon <pidfile> | Daemonize program with pid file. Default: do not daemonize\n");
  80. printf(" -l --syslog-host <host> | Syslog server address. Default: disabled\n");
  81. printf(" -L --syslog-port <port> | Syslog server port. Default: %d\n", ts->syslog_port);
  82. printf("\n");
  83. printf("Input options:\n");
  84. printf(" -I --input <source> | Where to read from. Supports files and multicast. Default: stdin\n");
  85. printf(" | -I 224.0.0.1:5000 (multicast receive)\n");
  86. printf(" | -I file.ts (read from file)\n");
  87. printf(" | -I - (read from STDIN)\n");
  88. printf(" -R --input-rtp | Enable RTP input\n");
  89. printf(" -z --input-ignore-disc | Report discontinuty errors in input stream. Default: %s\n", ts->ts_discont ? "enabled" : "disabled");
  90. printf("\n");
  91. printf("Output options:\n");
  92. printf(" -O --output <dest> | Where to send output. Supports files and multicast. Default: stdout\n");
  93. printf(" | -O 239.0.0.1:5000 (multicast send)\n");
  94. printf(" | -O file.ts (write to file)\n");
  95. printf(" | -O - (write to STDOUT)\n");
  96. printf(" -o --output-intf <addr> | Set multicast output interface. Default: %s\n", inet_ntoa(ts->output.intf));
  97. printf(" -t --output-ttl <ttl> | Set multicast ttl. Default: %d\n", ts->output.ttl);
  98. printf(" -p --output-filter | Output filter. Default: %s\n", ts->pid_filter ? "enabled" : "disabled");
  99. printf(" | - When output filter is enabled only PAT/PMT/SDT and data\n");
  100. printf(" | - packets are left in the output. Everything else (NIT, EIT,\n");
  101. printf(" | - TDT, etc.) is removed.\n");
  102. printf("\n");
  103. printf("CAMD server options:\n");
  104. printf(" -c --ca-system <ca_sys> | Process input EMM/ECM from <ca_sys>. Default: %s\n", ts_get_CA_sys_txt(ts->req_CA_sys));
  105. printf(" | Valid idents are: CONAX, CRYPTOWORKS, IRDETO, SECA (MEDIAGUARD),\n");
  106. printf(" | VIACCESS, VIDEOGUARD (NDS), NAGRA and DRECRYPT.\n");
  107. printf(" -s --camd-server <addr> | CAMD server address and port. Example: 1.2.3.4:2233. Default: not set\n");
  108. printf(" -U --camd-user <user> | CAMD server user. Default: %s\n", ts->camd35.user);
  109. printf(" -P --camd-pass <pass> | CAMD server password. Default: %s\n", ts->camd35.pass);
  110. printf(" -y --camd-pkt-delay <us> | Sleep <us> usec between sending ECM/EMM packets to CAMD. Default: %d\n", ts->packet_delay);
  111. printf("\n");
  112. printf("EMM options:\n");
  113. printf(" -e --emm | Enable sending EMM's to CAMD for processing. Default: %s\n", ts->emm_send ? "enabled" : "disabled");
  114. printf(" -E --emm-only | Send only EMMs to CAMD, without decoding input stream. Default: %s\n", ts->emm_only ? "enabled" : "disabled");
  115. printf(" -Z --emm-pid <pid> | Force EMM pid. Default: none\n");
  116. printf(" -f --emm-report-time <sec> | Report how much EMMs has been send for processing each <sec> seconds.\n");
  117. printf(" | Set <sec> to 0 to disable reporting. Default: %d\n", ts->camd35.emm_count_report_interval);
  118. printf("\n");
  119. printf("ECM options:\n");
  120. printf(" -X --ecm-pid <pid> | Force ECM pid. Default: none\n");
  121. printf(" -G --ecm-irdeto-type <int> | Process only IRDETO ECMs with selected type (0,1,2,3). Default: %d\n", ts->irdeto_ecm);
  122. printf("\n");
  123. printf("Misc options:\n");
  124. printf(" -D --debug <level> | Message debug level. Higher levels includes the levels bellow.\n");
  125. printf(" | 0 = default messages, 1 = show PSI tables, 2 = show EMMs\n");
  126. printf(" | 3 = show duplicate ECMs, 4 = packet debug\n");
  127. printf(" -h --help | Show help screen.\n");
  128. printf("\n");
  129. }
  130. static int parse_io_param(struct io *io, char *opt, int open_flags, mode_t open_mode) {
  131. io->type = WTF_IO;
  132. char *p = strrchr(opt, ':');
  133. if (!p) {
  134. io->type = FILE_IO;
  135. if (strcmp(opt, "-") != 0) {
  136. io->fd = open(opt, open_flags, open_mode);
  137. if (io->fd < 0) {
  138. fprintf(stderr, "ERROR: Can not open file (%s): %s\n", opt, strerror(errno));
  139. exit(1);
  140. }
  141. }
  142. io->fname = strdup(opt);
  143. return 0;
  144. }
  145. *p = 0x00;
  146. io->type = NET_IO;
  147. io->port = atoi(p + 1);
  148. if (inet_aton(opt, &io->addr) == 0)
  149. return 1;
  150. return 0;
  151. }
  152. static void parse_options(struct ts *ts, int argc, char **argv) {
  153. int j, i, ca_err = 0, server_err = 1, input_addr_err = 0, output_addr_err = 0, output_intf_err = 0, ident_err = 0;
  154. while ( (j = getopt_long(argc, argv, "i:d:l:L:I:RzO:o:t:pc:s:U:P:y:eZ:Ef:X:G:D:h", long_options, NULL)) != -1 ) {
  155. char *p = NULL;
  156. switch (j) {
  157. case 'i':
  158. strncpy(ts->ident, optarg, sizeof(ts->ident) - 1);
  159. ts->ident[sizeof(ts->ident) - 1] = 0;
  160. break;
  161. case 'd':
  162. strncpy(ts->pidfile, optarg, sizeof(ts->pidfile) - 1);
  163. ts->pidfile[sizeof(ts->pidfile) - 1] = 0;
  164. ts->daemonize = 1;
  165. break;
  166. case 'l':
  167. strncpy(ts->syslog_host, optarg, sizeof(ts->syslog_host) - 1);
  168. ts->syslog_host[sizeof(ts->syslog_host) - 1] = 0;
  169. ts->syslog_active = 1;
  170. break;
  171. case 'L':
  172. ts->syslog_port = atoi(optarg);
  173. break;
  174. case 'I':
  175. input_addr_err = parse_io_param(&ts->input, optarg, O_RDONLY, 0);
  176. break;
  177. case 'R':
  178. ts->rtp_input = !ts->rtp_input;
  179. break;
  180. case 'z':
  181. ts->ts_discont = !ts->ts_discont;
  182. break;
  183. case 'O':
  184. output_addr_err = parse_io_param(&ts->output, optarg,
  185. O_CREAT | O_WRONLY | O_TRUNC,
  186. S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  187. break;
  188. case 'o':
  189. if (inet_aton(optarg, &ts->output.intf) == 0)
  190. output_intf_err = 1;
  191. break;
  192. case 't':
  193. ts->output.ttl = atoi(optarg);
  194. break;
  195. case 'p':
  196. ts->pid_filter = !ts->pid_filter;
  197. break;
  198. case 'c':
  199. if (strcasecmp("IRDETO", optarg) == 0)
  200. ts->req_CA_sys = CA_IRDETO;
  201. else if (strcasecmp("CONNAX", optarg) == 0 || strcasecmp("CONAX", optarg) == 0)
  202. ts->req_CA_sys = CA_CONAX;
  203. else if (strcasecmp("CRYPTOWORKS", optarg) == 0)
  204. ts->req_CA_sys = CA_CRYPTOWORKS;
  205. else if (strcasecmp("SECA", optarg) == 0 || strcasecmp("MEDIAGUARD", optarg) == 0)
  206. ts->req_CA_sys = CA_SECA;
  207. else if (strcasecmp("VIACCESS", optarg) == 0)
  208. ts->req_CA_sys = CA_VIACCESS;
  209. else if (strcasecmp("VIDEOGUARD", optarg) == 0 || strcasecmp("NDS", optarg) == 0)
  210. ts->req_CA_sys = CA_VIDEOGUARD;
  211. else if (strcasecmp("NAGRA", optarg) == 0)
  212. ts->req_CA_sys = CA_NAGRA;
  213. else if (strcasecmp("DRE-CRYPT", optarg) == 0 || strcasecmp("DRECRYPT", optarg) == 0)
  214. ts->req_CA_sys = CA_DRECRYPT;
  215. else
  216. ca_err = 1;
  217. break;
  218. case 's':
  219. p = strrchr(optarg, ':');
  220. if (p) {
  221. *p = 0x00;
  222. ts->camd35.server_port = atoi(p + 1);
  223. }
  224. if (inet_aton(optarg, &ts->camd35.server_addr) == 0)
  225. server_err = 1;
  226. else
  227. server_err = 0;
  228. break;
  229. case 'U':
  230. strncpy(ts->camd35.user, optarg, sizeof(ts->camd35.user) - 1);
  231. ts->camd35.user[sizeof(ts->camd35.user) - 1] = 0;
  232. break;
  233. case 'P':
  234. strncpy(ts->camd35.pass, optarg, sizeof(ts->camd35.pass) - 1);
  235. ts->camd35.pass[sizeof(ts->camd35.pass) - 1] = 0;
  236. break;
  237. case 'y':
  238. ts->packet_delay = atoi(optarg);
  239. if (ts->packet_delay < 0 || ts->packet_delay > 1000000)
  240. ts->packet_delay = 0;
  241. break;
  242. case 'e':
  243. ts->emm_send = !ts->emm_send;
  244. break;
  245. case 'Z':
  246. ts->forced_emm_pid = strtoul(optarg, NULL, 0) & 0x1fff;
  247. break;
  248. case 'E':
  249. ts->emm_only = 1;
  250. ts->emm_send = 1;
  251. break;
  252. case 'f':
  253. ts->camd35.emm_count_report_interval = atoi(optarg);
  254. if (ts->camd35.emm_count_report_interval < 0)
  255. ts->camd35.emm_count_report_interval = 0;
  256. if (ts->camd35.emm_count_report_interval > 86400)
  257. ts->camd35.emm_count_report_interval = 86400;
  258. break;
  259. case 'X':
  260. ts->forced_ecm_pid = strtoul(optarg, NULL, 0) & 0x1fff;
  261. break;
  262. case 'G':
  263. ts->irdeto_ecm = atoi(optarg);
  264. break;
  265. case 'D':
  266. ts->debug_level = atoi(optarg);
  267. break;
  268. case 'h':
  269. show_help(ts);
  270. exit(0);
  271. }
  272. }
  273. if (ts->syslog_active && !ts->ident[0])
  274. ident_err = 1;
  275. if (ident_err || ca_err || server_err || input_addr_err || output_addr_err || ts->input.type == WTF_IO || ts->output.type == WTF_IO) {
  276. show_help(ts);
  277. if (ident_err)
  278. fprintf(stderr, "ERROR: Syslog is enabled but ident was not set.\n");
  279. if (ca_err)
  280. fprintf(stderr, "ERROR: Requested CA system is unsupported.\n");
  281. if (server_err)
  282. fprintf(stderr, "ERROR: CAMD server IP address is not set or it is invalid.\n");
  283. if (input_addr_err)
  284. fprintf(stderr, "ERROR: Input IP address is invalid.\n");
  285. if (output_addr_err)
  286. fprintf(stderr, "ERROR: Output IP address is invalid.\n");
  287. if (output_intf_err)
  288. fprintf(stderr, "ERROR: Output interface address is invalid.\n");
  289. exit(1);
  290. }
  291. if (ts->ident[0])
  292. ts_LOGf("Ident : %s\n", ts->ident);
  293. else
  294. ts_LOGf("Ident : *NOT SET*\n");
  295. if (ts->pidfile[0])
  296. ts_LOGf("Daemonize : %s pid file.\n", ts->pidfile);
  297. else
  298. ts_LOGf("Daemonize : no daemon\n");
  299. if (ts->syslog_active)
  300. ts_LOGf("Syslog : %s:%d\n", ts->syslog_host, ts->syslog_port);
  301. else
  302. ts_LOGf("Syslog : disabled\n");
  303. ts_LOGf("CA System : %s\n", ts_get_CA_sys_txt(ts->req_CA_sys));
  304. if (ts->input.type == NET_IO) {
  305. ts_LOGf("Input addr : %s://%s:%u/\n",
  306. ts->rtp_input ? "rtp" : "udp",
  307. inet_ntoa(ts->input.addr), ts->input.port);
  308. } else if (ts->input.type == FILE_IO) {
  309. ts_LOGf("Input file : %s\n", ts->input.fd == 0 ? "STDIN" : ts->input.fname);
  310. }
  311. if (ts->req_CA_sys == CA_IRDETO)
  312. ts_LOGf("Irdeto ECM : %d\n", ts->irdeto_ecm);
  313. if (ts->forced_emm_pid)
  314. ts_LOGf("EMM pid : 0x%04x (%d)\n", ts->forced_emm_pid, ts->forced_emm_pid);
  315. if (ts->forced_ecm_pid)
  316. ts_LOGf("ECM pid : 0x%04x (%d)\n", ts->forced_ecm_pid, ts->forced_ecm_pid);
  317. if (!ts->emm_only)
  318. {
  319. if (ts->output.type == NET_IO) {
  320. ts_LOGf("Output addr: udp://%s:%u/\n", inet_ntoa(ts->output.addr), ts->output.port);
  321. ts_LOGf("Output intf: %s\n", inet_ntoa(ts->output.intf));
  322. ts_LOGf("Output ttl : %d\n", ts->output.ttl);
  323. } else if (ts->output.type == FILE_IO) {
  324. ts_LOGf("Output file: %s\n", ts->output.fd == 1 ? "STDOUT" : ts->output.fname);
  325. }
  326. ts_LOGf("PID filter : %s\n", ts->pid_filter ? "enabled" : "disabled");
  327. }
  328. ts_LOGf("Server addr: tcp://%s:%u/\n", inet_ntoa(ts->camd35.server_addr), ts->camd35.server_port);
  329. ts_LOGf("Server user: %s\n", ts->camd35.user);
  330. ts_LOGf("Server pass: %s\n", ts->camd35.pass);
  331. if (ts->packet_delay)
  332. ts_LOGf("Pkt sleep : %d us (%d ms)\n", ts->packet_delay, ts->packet_delay / 1000);
  333. ts_LOGf("TS discont : %s\n", ts->ts_discont ? "report" : "ignore");
  334. ts->threaded = !(ts->input.type == FILE_IO && ts->input.fd != 0);
  335. if (ts->emm_send && ts->camd35.emm_count_report_interval)
  336. ts_LOGf("EMM report : %d sec\n", ts->camd35.emm_count_report_interval);
  337. if (ts->emm_send && ts->camd35.emm_count_report_interval == 0)
  338. ts_LOGf("EMM report : disabled\n");
  339. if (ts->emm_only) {
  340. ts_LOGf("EMM only : %s\n", ts->emm_only ? "yes" : "no");
  341. } else {
  342. ts_LOGf("EMM send : %s\n", ts->emm_send ? "enabled" : "disabled");
  343. ts_LOGf("Decoding : %s\n", ts->threaded ? "threaded" : "single thread");
  344. }
  345. for (i=0; i<(int)sizeof(ts->ident); i++) {
  346. if (!ts->ident[i])
  347. break;
  348. if (ts->ident[i] == '/')
  349. ts->ident[i] = '-';
  350. }
  351. }
  352. void signal_quit(int sig) {
  353. if (!keep_running)
  354. raise(sig);
  355. keep_running = 0;
  356. ts_LOGf("Killed %s with signal %d\n", program_id, sig);
  357. signal(sig, SIG_DFL);
  358. }
  359. #define RTP_HDR_SZ 12
  360. int main(int argc, char **argv) {
  361. ssize_t readen;
  362. uint8_t ts_packet[FRAME_SIZE + RTP_HDR_SZ];
  363. uint8_t rtp_hdr[2][RTP_HDR_SZ];
  364. int rtp_hdr_pos = 0, num_packets = 0;
  365. struct ts ts;
  366. memset(rtp_hdr[0], 0, RTP_HDR_SZ);
  367. memset(rtp_hdr[1], 0, RTP_HDR_SZ);
  368. data_init(&ts);
  369. parse_options(&ts, argc, argv);
  370. if (ts.pidfile[0])
  371. daemonize(ts.pidfile);
  372. if (!ts.syslog_active) {
  373. ts_set_log_func(LOG_func);
  374. } else {
  375. ts_set_log_func(LOG);
  376. log_init(ts.ident, ts.syslog_active, ts.daemonize != 1, ts.syslog_host, ts.syslog_port);
  377. }
  378. ts_LOGf("Start %s\n", program_id);
  379. if (ts.input.type == NET_IO && udp_connect_input(&ts.input) < 1)
  380. goto EXIT;
  381. if (ts.output.type == NET_IO && udp_connect_output(&ts.output) < 1)
  382. goto EXIT;
  383. signal(SIGCHLD, SIG_IGN);
  384. signal(SIGPIPE, SIG_IGN);
  385. signal(SIGINT , signal_quit);
  386. signal(SIGTERM, signal_quit);
  387. if (&ts.threaded) {
  388. pthread_create(&ts.decode_thread, NULL, &decode_thread, &ts);
  389. pthread_create(&ts.write_thread, NULL , &write_thread , &ts);
  390. }
  391. camd_start(&ts);
  392. do {
  393. if (ts.input.type == NET_IO) {
  394. if (!ts.rtp_input) {
  395. readen = fdread_ex(ts.input.fd, (char *)ts_packet, FRAME_SIZE, 250, 4, 1);
  396. } else {
  397. readen = fdread_ex(ts.input.fd, (char *)ts_packet, FRAME_SIZE + RTP_HDR_SZ, 250, 4, 1);
  398. if (readen > RTP_HDR_SZ) {
  399. memcpy(rtp_hdr[rtp_hdr_pos], ts_packet, RTP_HDR_SZ);
  400. memmove(ts_packet, ts_packet + RTP_HDR_SZ, FRAME_SIZE);
  401. readen -= RTP_HDR_SZ;
  402. uint16_t ssrc = (rtp_hdr[rtp_hdr_pos][2] << 8) | rtp_hdr[rtp_hdr_pos][3];
  403. uint16_t pssrc = (rtp_hdr[!rtp_hdr_pos][2] << 8) | rtp_hdr[!rtp_hdr_pos][3];
  404. rtp_hdr_pos = !rtp_hdr_pos;
  405. if (pssrc + 1 != ssrc && (ssrc != 0 && pssrc != 0xffff) && num_packets > 2)
  406. if (ts.ts_discont)
  407. ts_LOGf("--- | RTP discontinuity last_ssrc %5d, curr_ssrc %5d, lost %d packet\n",
  408. pssrc, ssrc, ((ssrc - pssrc)-1) & 0xffff);
  409. num_packets++;
  410. }
  411. }
  412. } else {
  413. readen = read(ts.input.fd, ts_packet, FRAME_SIZE);
  414. }
  415. if (readen > 0)
  416. process_packets(&ts, ts_packet, readen);
  417. if (!keep_running)
  418. break;
  419. } while (readen > 0);
  420. EXIT:
  421. camd_stop(&ts);
  422. if (ts.threaded) {
  423. ts.decode_stop = 1;
  424. ts.write_stop = 1;
  425. pthread_join(ts.decode_thread, NULL);
  426. pthread_join(ts.write_thread, NULL);
  427. }
  428. data_free(&ts);
  429. ts_LOGf("Stop %s\n", program_id);
  430. if (ts.syslog_active)
  431. log_close();
  432. if (ts.daemonize)
  433. unlink(ts.pidfile);
  434. exit(0);
  435. }