File init.c changed (mode: 100644) (index 8651c40..1c397a0) |
1 |
|
/******************************************************************************* |
|
2 |
|
this code is protected by the GNU affero GPLv3 |
|
3 |
|
author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> |
|
4 |
|
*******************************************************************************/ |
|
|
1 |
|
/* |
|
2 |
|
* this code is protected by the GNU affero GPLv3 |
|
3 |
|
* author:Sylvain BERTRAND <sylvain.bertrand AT legeek DOT net> |
|
4 |
|
*/ |
5 |
5 |
#include <ulinux/compiler_misc.h> |
#include <ulinux/compiler_misc.h> |
6 |
6 |
#include <ulinux/compiler_types.h> |
#include <ulinux/compiler_types.h> |
7 |
7 |
#include <ulinux/sysc.h> |
#include <ulinux/sysc.h> |
|
... |
... |
author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> |
18 |
18 |
|
|
19 |
19 |
static void sigs_setup(void) |
static void sigs_setup(void) |
20 |
20 |
{ |
{ |
21 |
|
ul mask=(~0); |
|
22 |
|
l r; |
|
23 |
|
|
|
24 |
|
OUT(PRE "setting up signals...\n"); |
|
25 |
|
r=rt_sigprocmask(SIG_BLOCK,&mask,sizeof(mask)); |
|
26 |
|
if(ISERR(r)){ |
|
27 |
|
OUT("ERROR:unable to block all signals (except KILL and STOP)\n"); |
|
28 |
|
exit_group(-1); |
|
29 |
|
} |
|
30 |
|
OUT("done\n"); |
|
|
21 |
|
ul mask; |
|
22 |
|
l r; |
|
23 |
|
|
|
24 |
|
mask = ~0; |
|
25 |
|
|
|
26 |
|
OUT(PRE "setting up signals...\n"); |
|
27 |
|
r = rt_sigprocmask(SIG_BLOCK, &mask, sizeof(mask)); |
|
28 |
|
if (ISERR(r)) { |
|
29 |
|
OUT("ERROR:unable to block all signals (except KILL and STOP)\n"); |
|
30 |
|
exit_group(-1); |
|
31 |
|
} |
|
32 |
|
OUT("done\n"); |
31 |
33 |
} |
} |
32 |
34 |
|
|
33 |
35 |
static i sysstart_clone(void) |
static i sysstart_clone(void) |
34 |
36 |
{ |
{ |
35 |
|
l r; |
|
36 |
|
ul mask; |
|
37 |
|
|
|
38 |
|
OUT(PRE "clone and execve /bin/sysstart...\n"); |
|
39 |
|
r=clone(SIGCHLD); |
|
40 |
|
if(ISERR(r)){ |
|
41 |
|
OUT("ERROR(%ld):unable to clone sysinit for /bin/sysstart\n",r); |
|
42 |
|
exit_group(-1); |
|
43 |
|
} |
|
44 |
|
|
|
45 |
|
if(r) return (i)r; |
|
46 |
|
|
|
47 |
|
mask=(~0); |
|
48 |
|
r=rt_sigprocmask(SIG_UNBLOCK,&mask,sizeof(mask)); |
|
49 |
|
if(ISERR(r)){ |
|
50 |
|
OUT("ERROR(%ld):unable to unblock all signals for /bin/sysstart\n",r); |
|
51 |
|
exit_group(-1); |
|
52 |
|
} |
|
53 |
|
|
|
54 |
|
r=execve("/bin/sysstart",0); |
|
55 |
|
if(ISERR(r)) {OUT("ERROR(%ld):unable to execve /bin/sysstart\n",r);} |
|
56 |
|
exit_group(-1); |
|
57 |
|
#ifdef __GNUC__ |
|
58 |
|
return 0;/*unreachable not detected at the end of function*/ |
|
59 |
|
#endif |
|
|
37 |
|
l r; |
|
38 |
|
ul mask; |
|
39 |
|
|
|
40 |
|
OUT(PRE "clone and execve /bin/sysstart...\n"); |
|
41 |
|
r = clone(SIGCHLD); |
|
42 |
|
if (ISERR(r)) { |
|
43 |
|
OUT("ERROR(%ld):unable to clone sysinit for /bin/sysstart\n", r); |
|
44 |
|
exit_group(-1); |
|
45 |
|
} |
|
46 |
|
|
|
47 |
|
if (r) |
|
48 |
|
return (i)r; |
|
49 |
|
|
|
50 |
|
mask = ~0; |
|
51 |
|
r = rt_sigprocmask(SIG_UNBLOCK, &mask, sizeof(mask)); |
|
52 |
|
if (ISERR(r)) { |
|
53 |
|
OUT("ERROR(%ld):unable to unblock all signals for /bin/sysstart\n", r); |
|
54 |
|
exit_group(-1); |
|
55 |
|
} |
|
56 |
|
|
|
57 |
|
r = execve("/bin/sysstart", 0); |
|
58 |
|
if(ISERR(r)) { |
|
59 |
|
OUT("ERROR(%ld):unable to execve /bin/sysstart\n", r); |
|
60 |
|
} |
|
61 |
|
exit_group(-1); |
60 |
62 |
} |
} |
61 |
63 |
|
|
62 |
64 |
#ifndef NO_TTY |
#ifndef NO_TTY |
63 |
65 |
static i getty_spawn(void *tty) |
static i getty_spawn(void *tty) |
64 |
66 |
{ |
{ |
65 |
|
l r; |
|
66 |
|
ul mask; |
|
67 |
|
void *argv[]={"/bin/agetty",tty,0};/*0 for envp is not "portable"*/ |
|
68 |
|
|
|
69 |
|
OUT(PRE "getty %s...\n",tty); |
|
70 |
|
|
|
71 |
|
r=clone(SIGCHLD); |
|
72 |
|
if(ISERR(r)){ |
|
73 |
|
OUT("ERROR(%ld):unable to clone for getty(%s)\n",r,tty); |
|
74 |
|
exit_group(-1); |
|
75 |
|
} |
|
76 |
|
|
|
77 |
|
if(r) return r;/*return the child process id*/ |
|
78 |
|
|
|
79 |
|
mask=(~0); |
|
80 |
|
r=rt_sigprocmask(SIG_UNBLOCK,&mask,sizeof(mask)); |
|
81 |
|
if(ISERR(r)){ |
|
82 |
|
OUT("ERROR(%ld):unable to unblock all signals for getty(%s)\n",r,tty); |
|
83 |
|
exit_group(-1); |
|
84 |
|
} |
|
85 |
|
|
|
86 |
|
r=setsid(); |
|
87 |
|
if(ISERR(r)){ |
|
88 |
|
OUT("ERROR(%ld):unable to setsid the getty(%s) clone\n",r,tty); |
|
89 |
|
exit_group(-1); |
|
90 |
|
} |
|
91 |
|
|
|
92 |
|
r=execve("/bin/agetty",argv); |
|
93 |
|
if(ISERR(r)) {OUT("ERROR(%ld):unable to run /bin/agetty(%s)\n",r,tty);} |
|
94 |
|
exit_group(-1); |
|
95 |
|
#ifdef __GNUC__ |
|
96 |
|
return 0;/*unreachable not detected at the end of function*/ |
|
97 |
|
#endif |
|
|
67 |
|
l r; |
|
68 |
|
ul mask; |
|
69 |
|
void *argv[3]; |
|
70 |
|
|
|
71 |
|
argv[0] = "bin/agetty"; |
|
72 |
|
argv[1] = tty; |
|
73 |
|
argv[2] = 0; |
|
74 |
|
|
|
75 |
|
OUT(PRE "getty %s...\n", tty); |
|
76 |
|
|
|
77 |
|
r = clone(SIGCHLD); |
|
78 |
|
if (ISERR(r)) { |
|
79 |
|
OUT("ERROR(%ld):unable to clone for getty(%s)\n", r, tty); |
|
80 |
|
exit_group(-1); |
|
81 |
|
} |
|
82 |
|
|
|
83 |
|
if (r) |
|
84 |
|
return r;/* return the child process id */ |
|
85 |
|
|
|
86 |
|
mask = ~0; |
|
87 |
|
r = rt_sigprocmask(SIG_UNBLOCK, &mask, sizeof(mask)); |
|
88 |
|
if (ISERR(r)) { |
|
89 |
|
OUT("ERROR(%ld):unable to unblock all signals for getty(%s)\n", r, tty); |
|
90 |
|
exit_group(-1); |
|
91 |
|
} |
|
92 |
|
|
|
93 |
|
r = setsid(); |
|
94 |
|
if (ISERR(r)) { |
|
95 |
|
OUT("ERROR(%ld):unable to setsid the getty(%s) clone\n", r, tty); |
|
96 |
|
exit_group(-1); |
|
97 |
|
} |
|
98 |
|
|
|
99 |
|
r = execve("/bin/agetty", argv); |
|
100 |
|
if (ISERR(r)) { |
|
101 |
|
OUT("ERROR(%ld):unable to run /bin/agetty(%s)\n", r, tty); |
|
102 |
|
} |
|
103 |
|
exit_group(-1); |
98 |
104 |
} |
} |
99 |
105 |
#endif |
#endif |
100 |
106 |
|
|
101 |
107 |
static void sysstart(void) |
static void sysstart(void) |
102 |
108 |
{ |
{ |
103 |
|
i pid=sysstart_clone(); |
|
104 |
|
l r=waitid(P_PID,pid,0,WEXITED); |
|
105 |
|
if(ISERR(r)){ |
|
106 |
|
OUT("ERROR(%ld):unable to wait for /bin/sysstart to exit\n",r); |
|
107 |
|
exit_group(-1); |
|
108 |
|
} |
|
|
109 |
|
i pid; |
|
110 |
|
l r; |
|
111 |
|
|
|
112 |
|
pid = sysstart_clone(); |
|
113 |
|
r = waitid(P_PID, pid, 0, WEXITED); |
|
114 |
|
if (ISERR(r)) { |
|
115 |
|
OUT("ERROR(%ld):unable to wait for /bin/sysstart to exit\n", r); |
|
116 |
|
exit_group(-1); |
|
117 |
|
} |
109 |
118 |
} |
} |
110 |
119 |
|
|
111 |
120 |
#ifdef NO_TTY |
#ifdef NO_TTY |
112 |
|
/*minimal, we don't even have ttys to restart*/ |
|
|
121 |
|
/* minimal, we don't even have ttys to restart */ |
113 |
122 |
static void main_loop(void) |
static void main_loop(void) |
114 |
123 |
{ |
{ |
115 |
|
loop{ |
|
116 |
|
l r=waitid(P_ALL,0,0,WEXITED); |
|
117 |
|
if(ISERR(r)){ |
|
118 |
|
OUT("ERROR(%ld):unable to wait on orphan process terminations\n",r); |
|
119 |
|
} |
|
120 |
|
} |
|
121 |
|
unreachable(); |
|
|
124 |
|
loop { |
|
125 |
|
l r; |
|
126 |
|
|
|
127 |
|
r = waitid(P_ALL, 0, 0, WEXITED); |
|
128 |
|
if (ISERR(r)) { |
|
129 |
|
OUT("ERROR(%ld):unable to wait on orphan process terminations\n", r); |
|
130 |
|
} |
|
131 |
|
} |
122 |
132 |
} |
} |
123 |
133 |
#else |
#else |
124 |
|
/*we allow ourself 2 ttys to restart*/ |
|
|
134 |
|
/* we allow ourself 2 ttys to restart */ |
125 |
135 |
static void main_loop(void) |
static void main_loop(void) |
126 |
136 |
{ |
{ |
127 |
|
i tty1=getty_spawn("tty1"); |
|
128 |
|
i tty2=getty_spawn("tty2"); |
|
129 |
|
|
|
130 |
|
loop{ |
|
131 |
|
struct siginfo siginfo; |
|
132 |
|
l r=waitid(P_ALL,0,&siginfo,WEXITED); |
|
133 |
|
if(ISERR(r)){ |
|
134 |
|
OUT("ERROR(%ld):unable to wait on /bin/agetty clone and orphan process terminations\n",r); |
|
135 |
|
exit_group(-1); |
|
136 |
|
} |
|
137 |
|
if(siginfo.fields.sigchld.pid==tty1) tty1=getty_spawn("tty1"); |
|
138 |
|
else if(siginfo.fields.sigchld.pid==tty2) tty2=getty_spawn("tty2"); |
|
139 |
|
/*ignore the other children*/ |
|
140 |
|
} |
|
141 |
|
unreachable(); |
|
|
137 |
|
i tty1; |
|
138 |
|
i tty2; |
|
139 |
|
|
|
140 |
|
tty1 = getty_spawn("tty1"); |
|
141 |
|
tty2 = getty_spawn("tty2"); |
|
142 |
|
|
|
143 |
|
loop { |
|
144 |
|
struct siginfo siginfo; |
|
145 |
|
l r; |
|
146 |
|
|
|
147 |
|
r = waitid(P_ALL, 0, &siginfo, WEXITED); |
|
148 |
|
if(ISERR(r)) { |
|
149 |
|
OUT("ERROR(%ld):unable to wait on /bin/agetty clone and orphan process terminations\n", r); |
|
150 |
|
exit_group(-1); |
|
151 |
|
} |
|
152 |
|
if (siginfo.fields.sigchld.pid == tty1) |
|
153 |
|
tty1 = getty_spawn("tty1"); |
|
154 |
|
else if (siginfo.fields.sigchld.pid == tty2) |
|
155 |
|
tty2 = getty_spawn("tty2"); |
|
156 |
|
} |
142 |
157 |
} |
} |
143 |
158 |
#endif |
#endif |
144 |
|
|
|
145 |
159 |
void _start(void) |
void _start(void) |
146 |
160 |
{ |
{ |
147 |
|
#ifndef QUIET |
|
148 |
|
static u8 dprintf_buf[DPRINTF_BUF_SZ]; |
|
149 |
|
g_dprintf_buf=dprintf_buf; |
|
150 |
|
#endif |
|
151 |
|
|
|
152 |
|
sigs_setup(); |
|
153 |
|
sysstart(); |
|
154 |
|
main_loop(); |
|
155 |
|
unreachable(); |
|
|
161 |
|
sigs_setup(); |
|
162 |
|
sysstart(); |
|
163 |
|
main_loop(); |
156 |
164 |
} |
} |
|
165 |
|
/* vim: set ts=4 sw=0 noexpandtab: */ |
File make changed (mode: 100755) (index ff8d1d6..293e6df) |
1 |
1 |
#!/bin/sh |
#!/bin/sh |
2 |
2 |
|
|
3 |
|
#this script is brutal and verbose, has no tricks and is quite linear, then |
|
4 |
|
#quite easy to deal with |
|
5 |
|
#for the moment, it's hardcoded for a gcc toolchain... BAD! Since now |
|
6 |
|
#gcc is a c++ piece of shit |
|
|
3 |
|
# this script is brutal and verbose, has no tricks and is quite linear, then |
|
4 |
|
# quite easy to deal with |
|
5 |
|
# for the moment, it's hardcoded for a gcc toolchain... BAD! Since now |
|
6 |
|
# gcc is c++ diareha |
7 |
7 |
|
|
8 |
|
# stolen from ffmpeg configure like a pig |
|
|
8 |
|
# stolen from ffmpeg configure |
9 |
9 |
set -e |
set -e |
10 |
10 |
|
|
11 |
|
# Prevent locale nonsense from breaking basic text processing. |
|
|
11 |
|
# prevent locale nonsense from breaking basic text processing |
12 |
12 |
LC_ALL=C |
LC_ALL=C |
13 |
13 |
export LC_ALL |
export LC_ALL |
14 |
14 |
|
|
15 |
15 |
init_file_name=init |
init_file_name=init |
16 |
16 |
|
|
17 |
17 |
#------------------------------------------------------------------------------- |
#------------------------------------------------------------------------------- |
18 |
|
#default source files in the binary |
|
19 |
|
init_ulinux_src_files=' |
|
20 |
|
ulinux/utils/mem.c |
|
21 |
|
ulinux/utils/ascii/string/vsprintf.c |
|
22 |
|
' |
|
|
18 |
|
# default source files in the binary |
|
19 |
|
init_ulinux_src_files="\ |
|
20 |
|
ulinux/utils/mem.c \ |
|
21 |
|
ulinux/utils/ascii/string/vsprintf.c" |
23 |
22 |
init_src_files=init.c |
init_src_files=init.c |
24 |
23 |
#------------------------------------------------------------------------------- |
#------------------------------------------------------------------------------- |
25 |
|
|
|
26 |
|
clean_do() |
|
27 |
|
{ |
|
28 |
|
all_init_src_files="$init_src_files $init_ulinux_src_files" |
|
29 |
|
|
|
30 |
|
rm -f $init_file_name |
|
31 |
|
for init_src_file in $all_init_src_files |
|
32 |
|
do |
|
33 |
|
init_pp_file=${init_src_file%.c} |
|
34 |
|
init_pp_file=${init_pp_file}.pp.c |
|
35 |
|
rm -f ${init_pp_file} |
|
36 |
|
init_o_file=${init_src_file%.c} |
|
37 |
|
init_o_file=${init_o_file}.o |
|
38 |
|
rm -f ${init_o_file} |
|
39 |
|
#clean directories, but keep root of build tree |
|
40 |
|
tgt_dir=$(dirname $init_src_file) |
|
41 |
|
if test -d $tgt_dir -a "$tgt_dir" != "."; then |
|
42 |
|
rmdir --ignore-fail-on-non-empty -p $tgt_dir |
|
43 |
|
fi |
|
44 |
|
done |
|
45 |
|
exit 0 |
|
46 |
|
} |
|
47 |
|
|
|
48 |
24 |
sep_start() |
sep_start() |
49 |
25 |
{ |
{ |
50 |
|
printf '###############################################################################\n' |
|
|
26 |
|
printf "\ |
|
27 |
|
################################################################################\ |
|
28 |
|
\n" |
51 |
29 |
} |
} |
52 |
30 |
|
|
53 |
31 |
sep_end() |
sep_end() |
54 |
32 |
{ |
{ |
55 |
|
printf '###############################################################################\n\n' |
|
|
33 |
|
printf "\ |
|
34 |
|
################################################################################\ |
|
35 |
|
\n\n" |
56 |
36 |
} |
} |
57 |
37 |
|
|
58 |
38 |
subsep_start() |
subsep_start() |
59 |
39 |
{ |
{ |
60 |
|
printf '*******************************************************************************\n' |
|
|
40 |
|
printf "\ |
|
41 |
|
********************************************************************************\ |
|
42 |
|
\n" |
61 |
43 |
} |
} |
62 |
44 |
|
|
63 |
45 |
subsep_end() |
subsep_end() |
64 |
46 |
{ |
{ |
65 |
|
printf '*******************************************************************************\n' |
|
|
47 |
|
printf "\ |
|
48 |
|
********************************************************************************\ |
|
49 |
|
\n" |
66 |
50 |
} |
} |
67 |
51 |
|
|
68 |
52 |
################################################################################ |
################################################################################ |
69 |
53 |
|
|
70 |
|
is_in(){ |
|
71 |
|
value=$1 |
|
72 |
|
shift |
|
73 |
|
for var in $*; do |
|
74 |
|
[ $var = $value ] && return 0 |
|
75 |
|
done |
|
76 |
|
return 1 |
|
77 |
|
} |
|
78 |
|
|
|
79 |
|
die_unknown(){ |
|
80 |
|
echo "Unknown option \"$1\"." |
|
81 |
|
echo "See $0 --help for available options." |
|
82 |
|
exit 1 |
|
|
54 |
|
is_in() |
|
55 |
|
{ |
|
56 |
|
value=$1 |
|
57 |
|
shift |
|
58 |
|
for var in $*; do |
|
59 |
|
[ $var = $value ] && return 0 |
|
60 |
|
done |
|
61 |
|
return 1 |
83 |
62 |
} |
} |
84 |
63 |
|
|
85 |
|
set_default(){ |
|
86 |
|
for opt; do |
|
87 |
|
eval : \${$opt:=\$${opt}_default} |
|
88 |
|
done |
|
|
64 |
|
set_default() |
|
65 |
|
{ |
|
66 |
|
for opt; do |
|
67 |
|
eval : \${$opt:=\$${opt}_default} #1 level of indirection |
|
68 |
|
done |
89 |
69 |
} |
} |
90 |
70 |
|
|
91 |
71 |
CMDLINE_SET=' |
CMDLINE_SET=' |
92 |
|
init_cpp |
|
93 |
|
init_cc |
|
94 |
|
init_ld |
|
95 |
|
init_ulinux_arch |
|
|
72 |
|
init_cpp |
|
73 |
|
init_cc |
|
74 |
|
init_ld |
|
75 |
|
init_ulinux_arch |
96 |
76 |
' |
' |
97 |
77 |
|
|
98 |
78 |
################################################################################ |
################################################################################ |
99 |
79 |
|
|
100 |
|
#command line set defaults |
|
|
80 |
|
# command line set defaults |
101 |
81 |
#------------------------------------------------------------------------------- |
#------------------------------------------------------------------------------- |
102 |
|
#This defaults are for gcc, tested with version 4.7.3. You will need to |
|
103 |
|
#override those for you compiler (tinycc/open64/pcc...). Additionnally, source |
|
104 |
|
#support for different toolchains is not done. |
|
105 |
|
#The right way to do it is to have a toolchain abstraction layer since there are |
|
106 |
|
#no accurate enough standards |
|
107 |
82 |
init_cpp_default='gcc -E -Wall -Wextra' |
init_cpp_default='gcc -E -Wall -Wextra' |
108 |
83 |
init_cc_default='gcc -nostdinc -Wall -Wextra -std=gnu99 -O0 -c' |
init_cc_default='gcc -nostdinc -Wall -Wextra -std=gnu99 -O0 -c' |
109 |
84 |
init_ld_default='ld -nostdlib -O10 -s' |
init_ld_default='ld -nostdlib -O10 -s' |
|
... |
... |
set_default $CMDLINE_SET |
114 |
89 |
|
|
115 |
90 |
################################################################################ |
################################################################################ |
116 |
91 |
|
|
117 |
|
show_help(){ |
|
118 |
|
cat <<EOF |
|
119 |
|
Usage: make [options] [operations] |
|
120 |
|
|
|
121 |
|
Operations: [default is to build the the init process binary]: |
|
122 |
|
clean clean build products |
|
123 |
|
|
|
124 |
|
Options: [defaults in brackets after descriptions] |
|
|
92 |
|
show_help() |
|
93 |
|
{ |
|
94 |
|
cat <<EOF |
|
95 |
|
Usage: make [options] |
125 |
96 |
|
|
126 |
97 |
Help options: |
Help options: |
127 |
98 |
--help print this message |
--help print this message |
|
... |
... |
Standard options: |
131 |
102 |
--no-tty init won't respawn login processes on ttys |
--no-tty init won't respawn login processes on ttys |
132 |
103 |
|
|
133 |
104 |
Advanced options: |
Advanced options: |
134 |
|
--init-cpp=CPP use CPP compiler command line CPP for target init process [$init_cpp_default] |
|
135 |
|
--init-cc=CC use C compiler command line CC for target init process objects [$init_cc_default] |
|
136 |
|
--init-ld=LD use linker command line LD for target init process [$init_ld_default] |
|
|
105 |
|
--init-cpp=CPP use CPP compiler command line CPP for target init process [$init_cpp] |
|
106 |
|
--init-cc=CC use C compiler command line CC for target init process objects [$init_cc] |
|
107 |
|
--init-ld=LD use linker command line LD for target init process [$init_ld] |
137 |
108 |
--init-ulinux-arch=ARCH use ulinux ARCH for target init process [$init_ulinux_arch] |
--init-ulinux-arch=ARCH use ulinux ARCH for target init process [$init_ulinux_arch] |
138 |
109 |
EOF |
EOF |
139 |
|
exit 0 |
|
|
110 |
|
exit 0 |
140 |
111 |
} |
} |
141 |
112 |
|
|
142 |
113 |
################################################################################ |
################################################################################ |
143 |
114 |
|
|
144 |
|
for opt do |
|
145 |
|
optval="${opt#*=}" |
|
146 |
|
case "$opt" in |
|
147 |
|
clean) clean_do |
|
148 |
|
;; |
|
149 |
|
--help|-h) show_help |
|
150 |
|
;; |
|
151 |
|
--quiet) |
|
152 |
|
CPPFLAGS="$CPPFLAGS -DQUIET" |
|
153 |
|
init_ulinux_src_files="$init_ulinux_src_files/ulinux\/utils\/ascii\/string\/vsprintf.c/" |
|
154 |
|
init_ulinux_src_files="$init_ulinux_src_files/ulinux\/utils\/mem.c/" |
|
155 |
|
;; |
|
156 |
|
--no-tty) CPPFLAGS="$CPPFLAGS -DNO_TTY" |
|
157 |
|
;; |
|
158 |
|
*) |
|
159 |
|
optname=${opt%%=*} |
|
160 |
|
optname=${optname#--} |
|
161 |
|
optname=$(echo "$optname" | sed 's/-/_/g') |
|
162 |
|
if is_in $optname $CMDLINE_SET; then |
|
163 |
|
eval $optname='$optval' |
|
164 |
|
else |
|
165 |
|
die_unknown $opt |
|
166 |
|
fi |
|
167 |
|
;; |
|
168 |
|
esac |
|
169 |
|
done |
|
|
115 |
|
sep_start;printf 'paths:\n' |
|
116 |
|
src_path=$(readlink -f $(dirname "$0")) |
|
117 |
|
build_path=$(readlink -f .) |
|
118 |
|
printf "source path is $src_path\n" |
|
119 |
|
printf "build path is $build_path\n" |
|
120 |
|
sep_end |
170 |
121 |
|
|
171 |
122 |
################################################################################ |
################################################################################ |
172 |
123 |
|
|
173 |
|
sep_start;echo 'looking for source path:' |
|
174 |
|
if test -f make; then |
|
175 |
|
src_path=. |
|
176 |
|
else |
|
177 |
|
src_path=$(cd $(dirname "$0"); pwd) |
|
178 |
|
echo "$src_path" | grep -q '[[:blank:]]' && |
|
179 |
|
die "out of tree builds are impossible with whitespace in source path." |
|
180 |
|
test -e "$src_path/config.h" && |
|
181 |
|
die "out of tree builds are impossible with config.h in source dir." |
|
|
124 |
|
|
|
125 |
|
show_help_do= |
|
126 |
|
for opt do |
|
127 |
|
optval="${opt#*=}" |
|
128 |
|
case "$opt" in |
|
129 |
|
--help|-h) |
|
130 |
|
show_help_do=yes #defer until we have all our options |
|
131 |
|
;; |
|
132 |
|
--quiet) |
|
133 |
|
CPPFLAGS="$CPPFLAGS -DQUIET" |
|
134 |
|
init_ulinux_src_files= |
|
135 |
|
;; |
|
136 |
|
--no-tty) |
|
137 |
|
CPPFLAGS="$CPPFLAGS -DNO_TTY" |
|
138 |
|
;; |
|
139 |
|
*) |
|
140 |
|
optname=${opt%%=*} |
|
141 |
|
optname=${optname#--} |
|
142 |
|
optname=$(printf "$optname" | sed 's/-/_/g') |
|
143 |
|
if is_in $optname $CMDLINE_SET; then |
|
144 |
|
eval $optname='$optval' # 1 level indirection |
|
145 |
|
else |
|
146 |
|
printf "unknown option \"$opt\"\n" |
|
147 |
|
printf "see $0 --help for available options\n" |
|
148 |
|
exit 1 |
|
149 |
|
fi |
|
150 |
|
;; |
|
151 |
|
esac |
|
152 |
|
done |
|
153 |
|
if test $show_help_do; then |
|
154 |
|
show_help |
182 |
155 |
fi |
fi |
183 |
|
echo "source path is $src_path";sep_end |
|
184 |
156 |
|
|
185 |
157 |
################################################################################ |
################################################################################ |
186 |
158 |
|
|
187 |
|
sep_start;echo 'configure ulinux src tree for target arch:' |
|
188 |
|
rm -f $src_path/ulinux/arch |
|
189 |
|
ln -s archs/$init_ulinux_arch $src_path/ulinux/arch |
|
190 |
|
echo "init ulinux arch is $init_ulinux_arch" |
|
|
159 |
|
sep_start;printf 'configure ulinux src tree for target arch:\n' |
|
160 |
|
rm -f $build_path/ulinux/arch |
|
161 |
|
mkdir -p $build_path/ulinux |
|
162 |
|
ln -sTf $src_path/ulinux/archs/$init_ulinux_arch $build_path/ulinux/arch |
|
163 |
|
printf "init ulinux arch is $init_ulinux_arch\n" |
191 |
164 |
sep_end |
sep_end |
192 |
165 |
|
|
193 |
166 |
################################################################################ |
################################################################################ |
|
... |
... |
all_init_src_files="$init_src_files $init_ulinux_src_files" |
197 |
170 |
|
|
198 |
171 |
################################################################################ |
################################################################################ |
199 |
172 |
|
|
200 |
|
sep_start;echo 'C preprocess init src files:' |
|
|
173 |
|
sep_start;printf 'C preprocess init src files:\n' |
201 |
174 |
for init_src_file in $all_init_src_files |
for init_src_file in $all_init_src_files |
202 |
175 |
do |
do |
203 |
|
init_pp_c_file=${init_src_file%.c} |
|
204 |
|
init_pp_c_file=${init_pp_c_file}.pp.c |
|
205 |
|
echo "INIT_CPP $init_src_file->$init_pp_c_file" |
|
206 |
|
mkdir -p $(dirname $init_pp_c_file) |
|
207 |
|
$init_cpp $CPPFLAGS -I. -I$src_path -o $init_pp_c_file \ |
|
208 |
|
$src_path/$init_src_file |
|
209 |
|
init_pp_c_files="$init_pp_c_file $init_pp_c_files" |
|
|
176 |
|
init_pp_c_file=${init_src_file%.c}.pp.c |
|
177 |
|
printf "INIT_CPP $src_path/$init_src_file->$build_path/$init_pp_c_file\n" |
|
178 |
|
mkdir -p $(dirname $init_pp_c_file) |
|
179 |
|
$init_cpp $CPPFLAGS -I$build_path -I$src_path \ |
|
180 |
|
-o $build_path/$init_pp_c_file $src_path/$init_src_file |
|
181 |
|
init_pp_c_files="$init_pp_c_file $init_pp_c_files" |
210 |
182 |
done |
done |
211 |
183 |
sep_end |
sep_end |
212 |
184 |
|
|
213 |
185 |
################################################################################ |
################################################################################ |
214 |
186 |
|
|
215 |
|
sep_start;echo 'compile init preprocessed src files:' |
|
|
187 |
|
sep_start;printf 'compile init preprocessed src files:\n' |
216 |
188 |
for init_pp_c_file in $init_pp_c_files |
for init_pp_c_file in $init_pp_c_files |
217 |
189 |
do |
do |
218 |
|
init_obj_file=${init_pp_c_file%.pp.c} |
|
219 |
|
init_obj_file=${init_obj_file}.o |
|
220 |
|
echo "INIT_CC $init_pp_c_file-->$init_obj_file" |
|
221 |
|
$init_cc $CFLAGS -o $init_obj_file $init_pp_c_file |
|
222 |
|
init_obj_files="$init_obj_file $init_obj_files" |
|
|
190 |
|
init_obj_file=${init_pp_c_file%.pp.c}.o |
|
191 |
|
printf "INIT_CC $build_path/$init_pp_c_file-->$build_path/$init_obj_file\n" |
|
192 |
|
$init_cc $CFLAGS -o $build_path/$init_obj_file \ |
|
193 |
|
$build_path/$init_pp_c_file |
|
194 |
|
init_obj_files="$init_obj_file $init_obj_files" |
223 |
195 |
done |
done |
224 |
196 |
sep_end |
sep_end |
225 |
197 |
|
|
226 |
198 |
################################################################################ |
################################################################################ |
227 |
199 |
|
|
228 |
|
sep_start;echo 'link the init objects to produce the init binary:' |
|
229 |
|
echo "INIT_LD $init_file_name" |
|
230 |
|
echo $init_ld -o $init_file_name $init_obj_files |
|
231 |
|
$init_ld -o $init_file_name $init_obj_files |
|
|
200 |
|
sep_start;printf 'link the init objects to produce the init binary:\n' |
|
201 |
|
printf "INIT_LD $init_file_name\n" |
|
202 |
|
printf "$init_ld -o $build_path/$init_file_name $build_path/$init_obj_files\n" |
|
203 |
|
$init_ld -o $build_path/$init_file_name $build_path/$init_obj_files |
232 |
204 |
sep_end |
sep_end |
|
205 |
|
# vim: set ts=8 sw=0 noexpandtab: |
File script/sysstart deleted (index 26e3333..0000000) |
1 |
|
#!/bin/sh |
|
2 |
|
export PATH=/sbin:/bin:/usr/sbin:/usr/bin |
|
3 |
|
|
|
4 |
|
mount -o nosuid,nodev,noexec,relatime -t proc proc /proc |
|
5 |
|
#for mount utils |
|
6 |
|
ln -sf /proc/self/mounts /etc/mtab |
|
7 |
|
mount -o nosuid,nodev,noexec,relatime -t sysfs sysfs /sys |
|
8 |
|
|
|
9 |
|
#------------------------------------------------------------------------------- |
|
10 |
|
#mount /dev |
|
11 |
|
mount -o exec,nosuid,relatime,size=10M,mode=0755 -t devtmpfs udev /dev |
|
12 |
|
#syslog-ng is going amok, but still /dev/log is mandatory to many software |
|
13 |
|
ln -sf null /dev/log |
|
14 |
|
|
|
15 |
|
mkdir -m 0755 -p /dev/pts |
|
16 |
|
mount -o relatime,gid=5,mode=0620 -t devpts devpts /dev/pts |
|
17 |
|
|
|
18 |
|
mkdir -m 1777 -p /dev/shm |
|
19 |
|
mount -o nosuid,nodev,noexec,relatime -t tmpfs shm /dev/shm |
|
20 |
|
#------------------------------------------------------------------------------- |
|
21 |
|
|
|
22 |
|
mount -o nosuid,nodev,relatime,mode=0755 -t tmpfs tmpfs /run |
|
23 |
|
|
|
24 |
|
rm -Rf /tmp |
|
25 |
|
mkdir /tmp |
|
26 |
|
chmod 1777 /tmp |
|
27 |
|
#set the default hostname in linux compilation |
|
28 |
|
#hostname "amddev" |
|
29 |
|
|
|
30 |
|
#------------------------------------------------------------------------------- |
|
31 |
|
#mudev |
|
32 |
|
modprobe unix |
|
33 |
|
udevd --daemon |
|
34 |
|
|
|
35 |
|
udevadm trigger --type=subsystems --action=add |
|
36 |
|
udevadm trigger --type=devices --action=add |
|
37 |
|
|
|
38 |
|
#those modules need /dev nodes |
|
39 |
|
modprobe rtc-cmos |
|
40 |
|
|
|
41 |
|
udevadm settle |
|
42 |
|
#------------------------------------------------------------------------------- |
|
43 |
|
|
|
44 |
|
#------------------------------------------------------------------------------- |
|
45 |
|
#usb |
|
46 |
|
modprobe ehci-hcd |
|
47 |
|
modprobe ohci-hcd |
|
48 |
|
modprobe usbhid |
|
49 |
|
modprobe evdev |
|
50 |
|
#------------------------------------------------------------------------------- |
|
51 |
|
|
|
52 |
|
#------------------------------------------------------------------------------- |
|
53 |
|
#network, could be NetworkManager (KLUDGE!), or a simple dhcp client, or IPv6 |
|
54 |
|
#autoconfiguration... |
|
55 |
|
ip addr add 127.0.0.1/8 dev lo |
|
56 |
|
ip addr add 192.168.1.5/24 dev eth0 |
|
57 |
|
ip link set dev lo up |
|
58 |
|
ip link set dev eth0 up |
|
59 |
|
ip route add default via 192.168.1.1 dev eth0 |
|
60 |
|
#------------------------------------------------------------------------------- |
|
61 |
|
|
|
62 |
|
#------------------------------------------------------------------------------- |
|
63 |
|
#CPUs |
|
64 |
|
#BROKEN ON linux 3.15.3 |
|
65 |
|
#modprobe acpi-cpufreq |
|
66 |
|
#modprobe cpufreq_ondemand |
|
67 |
|
#cpufreq-set --cpu 0 --governor ondemand |
|
68 |
|
#cpufreq-set --cpu 1 --governor ondemand |
|
69 |
|
#------------------------------------------------------------------------------- |
|
70 |
|
|
|
71 |
|
hwclock --utc --hctosys |
|
72 |
|
|
|
73 |
|
#------------------------------------------------------------------------------- |
|
74 |
|
#block scheduler, for a SSD drive, cfq I/O scheduler is useless |
|
75 |
|
#modprobe cfq-iosched |
|
76 |
|
#echo "cfq" > /sys/block/sda/queue/scheduler |
|
77 |
|
#------------------------------------------------------------------------------- |
|
78 |
|
|
|
79 |
|
#------------------------------------------------------------------------------- |
|
80 |
|
##utmp/wtmp (I don't even use that stuff anymore, just for reference) |
|
81 |
|
#: >/var/run/utmp |
|
82 |
|
#chgrp utmp /var/run/utmp 2>/dev/null |
|
83 |
|
#chmod 0664 /var/run/utmp |
|
84 |
|
#if test ! -e /var/log/wtmp; then |
|
85 |
|
# : >/var/log/wtmp |
|
86 |
|
# chgrp utmp /var/log/wtmp 2>/dev/null |
|
87 |
|
# chmod 0664 /var/log/wtmp |
|
88 |
|
#fi |
|
89 |
|
#------------------------------------------------------------------------------- |
|
90 |
|
|
|
91 |
|
#------------------------------------------------------------------------------- |
|
92 |
|
#syslog-ng & |
|
93 |
|
chronyd & |
|
94 |
|
#/usr/libexec/fcron & |
|
95 |
|
#/usr/sbin/sshd & |
|
96 |
|
#------------------------------------------------------------------------------- |
|