aboutsummaryrefslogtreecommitdiff
path: root/src/progman.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/progman.c')
-rw-r--r--src/progman.c557
1 files changed, 296 insertions, 261 deletions
diff --git a/src/progman.c b/src/progman.c
index 9383aae..cee6775 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -1,18 +1,18 @@
1/* This file is part of Mailfromd. 1/* This file is part of Pies.
2 Copyright (C) 2007, 2008, 2009 Sergey Poznyakoff 2 Copyright (C) 2007, 2008, 2009 Sergey Poznyakoff
3 3
4 This program is free software; you can redistribute it and/or modify it 4 Pies is free software; you can redistribute it and/or modify
5 under the terms of the GNU General Public License as published by the 5 it under the terms of the GNU General Public License as published by
6 Free Software Foundation; either version 3 of the License, or (at your 6 the Free Software Foundation; either version 3, or (at your option)
7 option) any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 Pies is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License along 14 You should have received a copy of the GNU General Public License
15 with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 along with Pies. If not, see <http://www.gnu.org/licenses/>. */
16 16
17#include "pies.h" 17#include "pies.h"
18 18
@@ -172,13 +172,11 @@ static char *
172redir_tag (struct prog *master, int type) 172redir_tag (struct prog *master, int type)
173{ 173{
174 static char *redirstr[2] = { "stdout", "stderr" }; 174 static char *redirstr[2] = { "stdout", "stderr" };
175 char *str = NULL; 175 char *str;
176 if (type < MU_ARRAY_SIZE(redirstr)) 176 if (type < ARRAY_SIZE(redirstr))
177 asprintf (&str, "%s/%s", master->tag, redirstr[type]); 177 str = xasprintf ("%s/%s", master->tag, redirstr[type]);
178 else 178 else
179 asprintf (&str, "%s/%d", master->tag, type); 179 str = xasprintf ("%s/%d", master->tag, type);
180 if (!str)
181 xalloc_die ();
182 return str; 180 return str;
183} 181}
184 182
@@ -261,11 +259,10 @@ prog_rebuild_prerequisites (struct prog *prog)
261 259
262 if (comp->prereq) 260 if (comp->prereq)
263 { 261 {
264 mu_list_count (comp->prereq, &depc); 262 depc = gl_list_size (comp->prereq);
265 if (depc == 1) 263 if (depc == 1)
266 { 264 {
267 char *item; 265 const char *item = gl_list_get_at (comp->prereq, 0);
268 mu_list_get (comp->prereq, 0, (void**)&item);
269 if (strcmp (item, "all") == 0) 266 if (strcmp (item, "all") == 0)
270 { 267 {
271 dep_all = 1; 268 dep_all = 1;
@@ -274,7 +271,10 @@ prog_rebuild_prerequisites (struct prog *prog)
274 depc++; 271 depc++;
275 } 272 }
276 else if (strcmp (item, "none") == 0) 273 else if (strcmp (item, "none") == 0)
277 mu_list_destroy (&comp->prereq); 274 {
275 gl_list_free (comp->prereq);
276 comp->prereq = NULL;
277 }
278 } 278 }
279 } 279 }
280 280
@@ -294,16 +294,13 @@ prog_rebuild_prerequisites (struct prog *prog)
294 } 294 }
295 else 295 else
296 { 296 {
297 mu_iterator_t itr = NULL; 297 const void *p;
298 mu_list_get_iterator (comp->prereq, &itr); 298 gl_list_iterator_t itr = gl_list_iterator (comp->prereq);
299 for (mu_iterator_first (itr), depc = 0; 299 while (gl_list_iterator_next (&itr, &p, NULL))
300 !mu_iterator_is_done (itr); mu_iterator_next (itr), depc++)
301 { 300 {
302 char *str; 301 prog->prereq[depc++] = (char*) p;
303 mu_iterator_current (itr, (void**)&str);
304 prog->prereq[depc] = str;
305 } 302 }
306 mu_iterator_destroy (&itr); 303 gl_list_iterator_free (&itr);
307 } 304 }
308 } 305 }
309 prog->prereq[depc] = NULL; 306 prog->prereq[depc] = NULL;
@@ -341,9 +338,9 @@ redirect_to_file (struct prog *master, int stream)
341 0644 & ~master->v.p.comp->umask); 338 0644 & ~master->v.p.comp->umask);
342 if (fd == -1) 339 if (fd == -1)
343 { 340 {
344 mu_error (_("cannot open output file %s: %s"), 341 logmsg (LOG_ERR, _("cannot open output file %s: %s"),
345 master->v.p.comp->redir[stream].v.file, 342 master->v.p.comp->redir[stream].v.file,
346 mu_strerror (errno)); 343 strerror (errno));
347 return -1; 344 return -1;
348 } 345 }
349 /* Fix file ownership */ 346 /* Fix file ownership */
@@ -405,9 +402,9 @@ open_redirector (struct prog *master, int stream)
405 _exit (0); 402 _exit (0);
406 403
407 case -1: 404 case -1:
408 mu_diag_output (MU_DIAG_CRIT, 405 logmsg (LOG_CRIT,
409 _("cannot run redirector `%s': fork failed: %s"), 406 _("cannot run redirector `%s': fork failed: %s"),
410 master->tag, mu_strerror (errno)); 407 master->tag, strerror (errno));
411 return -1; 408 return -1;
412 409
413 default: 410 default:
@@ -592,7 +589,7 @@ prog_start (struct prog *prog)
592 589
593 if (prog->v.p.count > MAXSPAWN) 590 if (prog->v.p.count > MAXSPAWN)
594 { 591 {
595 mu_error (ngettext ( 592 logmsg (LOG_NOTICE, ngettext (
596 "%s is respawning too fast, disabled for %d minute", 593 "%s is respawning too fast, disabled for %d minute",
597 "%s is respawning too fast, disabled for %d minutes", 594 "%s is respawning too fast, disabled for %d minutes",
598 SLEEPTIME / 60), 595 SLEEPTIME / 60),
@@ -609,12 +606,12 @@ prog_start (struct prog *prog)
609 break; 606 break;
610 607
611 case pies_comp_pass_fd: 608 case pies_comp_pass_fd:
612 MU_DEBUG1 (pies_debug, MU_DEBUG_TRACE1, _("unlinking %s\n"), 609 debug (1, (_("unlinking %s"), prog->v.p.comp->pass_fd_socket));
613 prog->v.p.comp->pass_fd_socket);
614 if (unlink (prog->v.p.comp->pass_fd_socket) && errno != ENOENT) 610 if (unlink (prog->v.p.comp->pass_fd_socket) && errno != ENOENT)
615 { 611 {
616 mu_error (_("cannot unlink %s: %s"), prog->v.p.comp->pass_fd_socket, 612 logmsg (LOG_ERR, _("cannot unlink %s: %s"),
617 mu_strerror (errno)); 613 prog->v.p.comp->pass_fd_socket,
614 strerror (errno));
618 return; 615 return;
619 } 616 }
620 /* fall through */ 617 /* fall through */
@@ -630,7 +627,7 @@ prog_start (struct prog *prog)
630 } 627 }
631 if (listen (prog->v.p.socket, 8)) 628 if (listen (prog->v.p.socket, 8))
632 { 629 {
633 mu_error ("listen: %s", mu_strerror (errno)); 630 logmsg (LOG_ERR, "listen: %s", strerror (errno));
634 close (prog->v.p.socket); 631 close (prog->v.p.socket);
635 prog->v.p.socket = -1; 632 prog->v.p.socket = -1;
636 prog->v.p.status = status_disabled; 633 prog->v.p.status = status_disabled;
@@ -644,15 +641,14 @@ prog_start (struct prog *prog)
644 return; 641 return;
645 } 642 }
646 643
647 MU_DEBUG1 (pies_debug, MU_DEBUG_TRACE1, _("starting %s\n"), prog->tag); 644 debug (1, (_("starting %s"), prog->tag));
648 645
649 if (prog->v.p.comp->rmfile) 646 if (prog->v.p.comp->rmfile)
650 { 647 {
651 MU_DEBUG1 (pies_debug, MU_DEBUG_TRACE1, _("unlinking %s\n"), 648 debug (1, (_("unlinking %s"), prog->v.p.comp->rmfile));
652 prog->v.p.comp->rmfile);
653 if (unlink (prog->v.p.comp->rmfile) && errno != ENOENT) 649 if (unlink (prog->v.p.comp->rmfile) && errno != ENOENT)
654 mu_error (_("%s: cannot remove file `%s': %s"), 650 logmsg (LOG_ERR, _("%s: cannot remove file `%s': %s"),
655 prog->tag, prog->v.p.comp->rmfile, mu_strerror (errno)); 651 prog->tag, prog->v.p.comp->rmfile, strerror (errno));
656 } 652 }
657 653
658 redir[RETR_OUT] = open_redirector (prog, RETR_OUT); 654 redir[RETR_OUT] = open_redirector (prog, RETR_OUT);
@@ -665,22 +661,22 @@ prog_start (struct prog *prog)
665 signal_setup (SIG_DFL); 661 signal_setup (SIG_DFL);
666 if (prog->v.p.comp->dir) 662 if (prog->v.p.comp->dir)
667 { 663 {
668 MU_DEBUG1 (pies_debug, MU_DEBUG_TRACE1, _("chdir %s\n"), 664 debug (1, (_("chdir %s"), prog->v.p.comp->dir));
669 prog->v.p.comp->dir);
670 if (chdir (prog->v.p.comp->dir)) 665 if (chdir (prog->v.p.comp->dir))
671 mu_error (_("%s: cannot change to directory %s: %s"), 666 logmsg (LOG_ERR, _("%s: cannot change to directory %s: %s"),
672 prog->tag, prog->v.p.comp->dir, mu_strerror (errno)); 667 prog->tag, prog->v.p.comp->dir, strerror (errno));
673 } 668 }
674 669
675 environ = env_setup (prog->v.p.comp->env); 670 environ = env_setup (prog->v.p.comp->env);
676 if (mu_debug_check_level (pies_debug, MU_DEBUG_TRACE4)) 671 if (debug_level >= 4)
677 { 672 {
678 int i; 673 int i;
679 for (i = 0; environ[i]; i++) 674 for (i = 0; environ[i]; i++)
680 __MU_DEBUG1 (pies_debug, MU_DEBUG_TRACE4, "%s ", environ[i]); 675 logmsg_printf (LOG_DEBUG, "%s ", environ[i]);
681 mu_debug_printf (pies_debug, MU_DEBUG_TRACE4, "\n"); 676 logmsg_printf (LOG_DEBUG, "\n");
682 } 677 }
683 mf_priv_setup (&prog->v.p.comp->privs); 678
679 pies_priv_setup (&prog->v.p.comp->privs);
684 if (prog->v.p.comp->umask) 680 if (prog->v.p.comp->umask)
685 umask (prog->v.p.comp->umask); 681 umask (prog->v.p.comp->umask);
686 682
@@ -688,16 +684,16 @@ prog_start (struct prog *prog)
688 prog->v.p.comp->limits ? 684 prog->v.p.comp->limits ?
689 prog->v.p.comp->limits : pies_limits); 685 prog->v.p.comp->limits : pies_limits);
690