aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/acl.c2
-rw-r--r--src/pies.c28
-rw-r--r--src/pies.h6
-rw-r--r--src/prog.h1
-rw-r--r--src/progman.c118
-rw-r--r--src/socket.c2
-rw-r--r--src/sysvinit.c296
7 files changed, 290 insertions, 163 deletions
diff --git a/src/acl.c b/src/acl.c
index df53165..301f56f 100644
--- a/src/acl.c
+++ b/src/acl.c
@@ -640,8 +640,6 @@ acl_compare (void const *data1, void const *data2)
640static int 640static int
641acl_copy (void *a, void *b) 641acl_copy (void *a, void *b)
642{ 642{
643 const struct pies_acl *pb = b;
644
645 memcpy (a, b, sizeof (struct pies_acl)); 643 memcpy (a, b, sizeof (struct pies_acl));
646 memset (b, 0, sizeof (struct pies_acl)); 644 memset (b, 0, sizeof (struct pies_acl));
647 return 0; 645 return 0;
diff --git a/src/pies.c b/src/pies.c
index 36bd220..beab6fa 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -995,7 +995,7 @@ _cb_runlevels (enum grecs_callback_command cmd,
995 { 995 {
996 if (!is_valid_runlevel (*p)) 996 if (!is_valid_runlevel (*p))
997 { 997 {
998 grecs_error (locus, 0, _("not a valid runlevel: %c")); 998 grecs_error (locus, 0, _("not a valid runlevel: %c"), *p);
999 return 1; 999 return 1;
1000 } 1000 }
1001 } 1001 }
@@ -2115,31 +2115,6 @@ set_state_file_names (const char *base)
2115 qotdfile = mkfilename (statedir, base, ".qotd"); 2115 qotdfile = mkfilename (statedir, base, ".qotd");
2116} 2116}
2117 2117
2118static char *try_console[] = { NULL, "/dev/console", "/dev/tty0" };
2119char *console_device;
2120
2121static void
2122set_console_dev ()
2123{
2124 int i;
2125 for (i = 0; i < ARRAY_SIZE (try_console); i++)
2126 {
2127 if (try_console[i])
2128 {
2129 int fd = open (try_console[i], O_RDONLY|O_NONBLOCK);
2130
2131 if (fd >= 0)
2132 {
2133 close (fd);
2134 console_device = try_console[i];
2135 return;
2136 }
2137 }
2138 }
2139 /* provide default */
2140 console_device = "/dev/null";
2141}
2142
2143int 2118int
2144main (int argc, char **argv) 2119main (int argc, char **argv)
2145{ 2120{
@@ -2306,7 +2281,6 @@ main (int argc, char **argv)
2306 if (init_process) 2281 if (init_process)
2307 { 2282 {
2308 foreground = 1; 2283 foreground = 1;
2309 set_console_dev ();
2310 sysvinit_begin (); 2284 sysvinit_begin ();
2311 } 2285 }
2312 else 2286 else
diff --git a/src/pies.h b/src/pies.h
index 0da13e3..ca50a26 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -303,8 +303,6 @@ void progman_run_comp (struct component *comp, int fd,
303 303
304void progman_iterate_comp (int (*fun) (struct component *, void *), 304void progman_iterate_comp (int (*fun) (struct component *, void *),
305 void *data); 305 void *data);
306void progman_sysvinit_enable (int (*fun) (struct component *, int, void *),
307 void *data);
308 306
309void fd_report (int fd, const char *msg); 307void fd_report (int fd, const char *msg);
310 308
@@ -462,6 +460,10 @@ void sysvinit_begin (void);
462int inittrans (void); 460int inittrans (void);
463int is_comp_wait (struct component *comp); 461int is_comp_wait (struct component *comp);
464int is_valid_runlevel (int c); 462int is_valid_runlevel (int c);
463int console_open (int mode);
464int telinit (const char *arg);
465
466extern char *sysvinit_environ_hint[];
465 467
466#ifndef INIT_FIFO 468#ifndef INIT_FIFO
467# define INIT_FIFO "/dev/initctl" 469# define INIT_FIFO "/dev/initctl"
diff --git a/src/prog.h b/src/prog.h
index 5a5ad13..8fddf97 100644
--- a/src/prog.h
+++ b/src/prog.h
@@ -83,3 +83,4 @@ struct prog
83}; 83};
84 84
85void progman_foreach (int (*filter) (struct prog *, void *data), void *data); 85void progman_foreach (int (*filter) (struct prog *, void *data), void *data);
86void prog_stop (struct prog *prog, int sig);
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 @@
15 along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. */
16 16
17#include "pies.h" 17#include "pies.h"
18#include <termios.h>
19#include "prog.h" 18#include "prog.h"
20 19
21#define IS_COMPONENT(p) ((p)->type == TYPE_COMPONENT) 20#define IS_COMPONENT(p) ((p)->type == TYPE_COMPONENT)
@@ -27,41 +26,28 @@ static int recompute_alarm;
27static struct grecs_symtab *conn_tab; 26static struct grecs_symtab *conn_tab;
28 27
29void 28void
30progman_iterate_comp (int (*fun) (struct component *, void *), void *data) 29progman_foreach (int (*filter) (struct prog *, void *data), void *data)
31{ 30{
32 struct prog *prog; 31 struct prog *prog;
33
34 for (prog = proghead; prog; prog = prog->next) 32 for (prog = proghead; prog; prog = prog->next)
35 if (IS_COMPONENT (prog) 33 if (IS_COMPONENT (prog) && filter (prog, data))
36 && !(prog->v.p.comp->mode == pies_comp_inetd
37 && prog->v.p.listener)
38 && fun (prog->v.p.comp, data))
39 break; 34 break;
40} 35}
41 36
37/* FIXME: Rewrite this using progman_foreach */
42void 38void
43progman_sysvinit_enable (int (*fun) (struct component *, int, void *), 39progman_iterate_comp (int (*fun) (struct component *, void *), void *data)
44 void *data)
45{ 40{
46 struct prog *prog; 41 struct prog *prog;
47 42
48 for (prog = proghead; prog; prog = prog->next) 43 for (prog = proghead; prog; prog = prog->next)
49 if (IS_COMPONENT (prog) && is_sysvinit (prog->v.p.comp)) 44 if (IS_COMPONENT (prog)
50 { 45 && !(prog->v.p.comp->mode == pies_comp_inetd
51 int rc = fun (prog->v.p.comp, prog->v.p.status == status_finished, 46 && prog->v.p.listener)
52 data); 47 && fun (prog->v.p.comp, data))
53 if (rc < 0) 48 break;
54 continue;
55 if (rc)
56 prog->v.p.status = status_enabled;
57 else
58 prog->v.p.status = status_disabled;
59 debug (1, ("%s: %s", prog->tag,
60 prog->v.p.status == status_enabled ?
61 "enabled" : "disabled"));
62 }
63} 49}
64 50
65static struct prog * 51static struct prog *
66prog_lookup_by_pid (pid_t pid) 52prog_lookup_by_pid (pid_t pid)
67{ 53{
@@ -368,10 +354,7 @@ progman_running_p ()
368 { 354 {
369 if (IS_COMPONENT (prog) && is_comp_wait (prog->v.p.comp) && 355 if (IS_COMPONENT (prog) && is_comp_wait (prog->v.p.comp) &&
370 prog->pid > 0) 356 prog->pid > 0)
371 { 357 return 1;
372 debug (1, ("COMP %s still running", prog->tag));
373 return 1;
374 }
375 } 358 }
376 return 0; 359 return 0;
377} 360}
@@ -759,6 +742,7 @@ env_concat (const char *name, size_t namelen, const char *a, const char *b)
759 { 742 {
760 if (c_ispunct (b[0])) 743 if (c_ispunct (b[0]))
761 b++; 744 b++;
745 len = strlen (b);
762 res = xmalloc (namelen + 1 + len + 1); 746 res = xmalloc (namelen + 1 + len + 1);
763 strcpy (res + namelen + 1, b); 747 strcpy (res + namelen + 1, b);
764 } 748 }
@@ -1015,6 +999,8 @@ prog_start_prologue (struct prog *prog)
1015 environ_setup (prog->v.p.comp->env ? 999 environ_setup (prog->v.p.comp->env ?
1016 prog->v.p.comp->env : 1000 prog->v.p.comp->env :
1017 ((prog->v.p.comp->flags & CF_SOCKENV) ? sockenv_hint : NULL)); 1001 ((prog->v.p.comp->flags & CF_SOCKENV) ? sockenv_hint : NULL));
1002 if (init_process)
1003 environ_setup (sysvinit_environ_hint);
1018 DEBUG_ENVIRON (4); 1004 DEBUG_ENVIRON (4);
1019 1005
1020 pies_priv_setup (&prog->v.p.comp->privs); 1006 pies_priv_setup (&prog->v.p.comp->privs);
@@ -1072,68 +1058,6 @@ progman_run_comp (struct component *comp, int fd,
1072 prog_execute (prog); 1058 prog_execute (prog);
1073} 1059}
1074 1060
1075int
1076console_open (int mode)
1077{
1078 int i, fd;
1079
1080 for (i = 0; i < 5; i++)
1081 {
1082 fd = open (console_device, mode | O_NONBLOCK);
1083 if (fd >= 0)
1084 {
1085 fcntl (fd, F_SETFL, mode);
1086 return fd;
1087 }
1088 }
1089 return -1;
1090}
1091
1092static void
1093console_stty ()
1094{
1095 struct termios tty;