aboutsummaryrefslogtreecommitdiff
path: root/src/progman.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-01-07 14:31:58 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2013-01-07 14:31:58 +0200
commit5d2eff82abf052d5edb8f201559cb6e17bbf158f (patch)
tree7151f3fc984021039be9549fc0017ce3fe30bb5c /src/progman.c
parent720f035564cbec85af84d1d9daff48d4068a4f3e (diff)
downloadpies-5d2eff82abf052d5edb8f201559cb6e17bbf158f.tar.gz
pies-5d2eff82abf052d5edb8f201559cb6e17bbf158f.tar.bz2
Fix sysvinit execution environment, simplify boot state system.
* src/pies.c (_cb_runlevels): Bugfix. (set_console_dev): Move to sysvinit.c * src/pies.h (progman_sysvinit_enable): Remove proto. (console_open, telinit): New protos. (sysvinit_environ_hint): New extern. * src/prog.h (prog_stop): New proto. * src/progman.c (env_concat): Bugfix. (env_concat): In sysvinit mode, apply sysvinit_environ_hint to the environment. (console_open, console_stty): Move to sysvinit.c * src/sysvinit.c (boot_state): Simplify state set. (getinitdefault, askrunlevel): New functions. (sysvinit_runlevel_setup): New function. (enablecomp): Change signature to match progman_foreach API. (sysvinit_begin): Prepare console, become a session leader, prepare environment. (inittrans): Call sysvinit_runlevel_setup * src/socket.c (calc_fd_max): Fix return type. * src/acl.c (acl_copy): Remove unused variable.
Diffstat (limited to 'src/progman.c')
-rw-r--r--src/progman.c118
1 files changed, 18 insertions, 100 deletions
diff --git a/src/progman.c b/src/progman.c
index 1895152..0463366 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -15,7 +15,6 @@
along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. */
#include "pies.h"
-#include <termios.h>
#include "prog.h"
#define IS_COMPONENT(p) ((p)->type == TYPE_COMPONENT)
@@ -27,41 +26,28 @@ static int recompute_alarm;
static struct grecs_symtab *conn_tab;
void
-progman_iterate_comp (int (*fun) (struct component *, void *), void *data)
+progman_foreach (int (*filter) (struct prog *, void *data), void *data)
{
struct prog *prog;
-
for (prog = proghead; prog; prog = prog->next)
- if (IS_COMPONENT (prog)
- && !(prog->v.p.comp->mode == pies_comp_inetd
- && prog->v.p.listener)
- && fun (prog->v.p.comp, data))
+ if (IS_COMPONENT (prog) && filter (prog, data))
break;
}
+/* FIXME: Rewrite this using progman_foreach */
void
-progman_sysvinit_enable (int (*fun) (struct component *, int, void *),
- void *data)
+progman_iterate_comp (int (*fun) (struct component *, void *), void *data)
{
struct prog *prog;
for (prog = proghead; prog; prog = prog->next)
- if (IS_COMPONENT (prog) && is_sysvinit (prog->v.p.comp))
- {
- int rc = fun (prog->v.p.comp, prog->v.p.status == status_finished,
- data);
- if (rc < 0)
- continue;
- if (rc)
- prog->v.p.status = status_enabled;
- else
- prog->v.p.status = status_disabled;
- debug (1, ("%s: %s", prog->tag,
- prog->v.p.status == status_enabled ?
- "enabled" : "disabled"));
- }
+ if (IS_COMPONENT (prog)
+ && !(prog->v.p.comp->mode == pies_comp_inetd
+ && prog->v.p.listener)
+ && fun (prog->v.p.comp, data))
+ break;
}
-
+
static struct prog *
prog_lookup_by_pid (pid_t pid)
{
@@ -368,10 +354,7 @@ progman_running_p ()
{
if (IS_COMPONENT (prog) && is_comp_wait (prog->v.p.comp) &&
prog->pid > 0)
- {
- debug (1, ("COMP %s still running", prog->tag));
- return 1;
- }
+ return 1;
}
return 0;
}
@@ -759,6 +742,7 @@ env_concat (const char *name, size_t namelen, const char *a, const char *b)
{
if (c_ispunct (b[0]))
b++;
+ len = strlen (b);
res = xmalloc (namelen + 1 + len + 1);
strcpy (res + namelen + 1, b);
}
@@ -1015,6 +999,8 @@ prog_start_prologue (struct prog *prog)
environ_setup (prog->v.p.comp->env ?
prog->v.p.comp->env :
((prog->v.p.comp->flags & CF_SOCKENV) ? sockenv_hint : NULL));
+ if (init_process)
+ environ_setup (sysvinit_environ_hint);
DEBUG_ENVIRON (4);
pies_priv_setup (&prog->v.p.comp->privs);
@@ -1072,68 +1058,6 @@ progman_run_comp (struct component *comp, int fd,
prog_execute (prog);
}
-int
-console_open (int mode)
-{
- int i, fd;
-
- for (i = 0; i < 5; i++)
- {
- fd = open (console_device, mode | O_NONBLOCK);
- if (fd >= 0)
- {
- fcntl (fd, F_SETFL, mode);
- return fd;
- }
- }
- return -1;
-}
-
-static void
-console_stty ()
-{
- struct termios tty;
- int fd;
-
- if ((fd = console_open (O_RDWR|O_NOCTTY)) < 0)
- {
- logmsg (LOG_CRIT, "can't open %s", console_device);
- return;
- }
-
- tcgetattr (fd, &tty);
-
- tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
- tty.c_cflag |= HUPCL|CLOCAL|CREAD;
-
- tty.c_cc[VINTR] = 3; /* ctrl('c') */
- tty.c_cc[VQUIT] = 28; /* ctrl('\\') */
- tty.c_cc[VERASE] = 127;
- tty.c_cc[VKILL] = 24; /* ctrl('x') */
- tty.c_cc[VEOF] = 4; /* ctrl('d') */
- tty.c_cc[VTIME] = 0;
- tty.c_cc[VMIN] = 1;
- tty.c_cc[VSTART] = 17; /* ctrl('q') */
- tty.c_cc[VSTOP] = 19; /* ctrl('s') */
- tty.c_cc[VSUSP] = 26; /* ctrl('z') */
-
- /*
- * Set pre and post processing
- */
- tty.c_iflag = IGNPAR|ICRNL|IXON|IXANY;
- tty.c_oflag = OPOST|ONLCR;
- tty.c_lflag = ISIG|ICANON|ECHO|ECHOCTL|ECHOPRT|ECHOKE;
-
- /*
- * Now set the terminal line.
- * We don't care about non-transmitted output data
- * and non-read input data.
- */
- tcsetattr (fd, TCSANOW, &tty);
- tcflush(fd, TCIOFLUSH);
- close (fd);
-}
-
static void
prog_start (struct prog *prog)
{
@@ -1200,6 +1124,9 @@ prog_start (struct prog *prog)
/* Wait until an incoming connection is requested */
if (prog->v.p.socket == -1)
return;
+
+ default:
+ break;
}
debug (1, (_("starting %s"), prog->tag));
@@ -1251,7 +1178,7 @@ prog_start (struct prog *prog)
{
logmsg (LOG_CRIT, "open(%s): %s",
console_device, strerror (errno));
- fd = open("/dev/null", O_RDWR);
+ fd = open ("/dev/null", O_RDWR);
}
if (fd != 0)
dup2 (fd, 0);
@@ -2472,15 +2399,6 @@ progman_cleanup (int expect_term)
}
void
-progman_foreach (int (*filter) (struct prog *, void *data), void *data)
-{
- struct prog *prog;
- for (prog = proghead; prog; prog = prog->next)
- if (IS_COMPONENT (prog) && filter (prog, data))
- break;
-}
-
-void
progman_stop_component (const char *name)
{
struct prog *prog;

Return to:

Send suggestions and report system problems to the System administrator.