List of commits:
Subject Hash Author Date (UTC)
ulinux dir_parse pattern 63cc7acc186efc291a76255e97d86e80901174e5 Sylvain BERTRAND 2011-12-26 02:24:55
ulinux improvements and more patterns a458c52301d3a34e8b51794fea7c1cb06c1c34f8 Sylvain BERTRAND 2011-12-22 22:09:06
ulinux patterns:network server 60c167bcd530f95d0a57189035620c3bc80f1e34 Sylvain BERTRAND 2011-12-20 00:39:56
ulinux cleanup and samples 92c893f28ef42f11943c0bf80a037a5b5f34ebef Sylvain BERTRAND 2011-12-16 01:51:22
uevent listener 55657699f291575139858aec466340e7624cd66a Sylvain BERTRAND 2011-12-15 18:01:06
uevent monitor e241bd4db4af8510902a5c606eee0e1e2dbdecda Sylvain BERTRAND 2011-12-13 00:37:45
block signals 91772917669645b5634563d0c06e361c87cf3e84 Sylvain BERTRAND 2011-12-09 17:04:34
initial commit 5310fde2d021e3505f8f1d5d9091726c236967ec Sylvain BERTRAND 2011-12-07 11:29:18
Commit 63cc7acc186efc291a76255e97d86e80901174e5 - ulinux dir_parse pattern
Author: Sylvain BERTRAND
Author date (UTC): 2011-12-26 02:24
Committer name: Sylvain BERTRAND
Committer date (UTC): 2011-12-26 02:24
Parent(s): a458c52301d3a34e8b51794fea7c1cb06c1c34f8
Signer:
Signing key:
Signing status: N
Tree: eb79ddaff26355a3e7d48c6594ce7df64b8d11c2
File Lines added Lines deleted
conf.mk 1 1
globals.h 0 1
init.c 39 4
uevent.c 3 33
uevent.h 2 1
uevent_monitor.c 16 0
ulinux/archs/x86_64/mmap.h 1 1
ulinux/dirent.h 8 5
ulinux/fs.h 10 0
ulinux/patterns/args/args.c 0 1
ulinux/patterns/dir_parse/dir_parse.c 107 0
ulinux/patterns/dir_parse/makefile 7 7
ulinux/patterns/network_server/pre-fork_socket_unix_tcp/README 0 1
ulinux/utils/ascii/string/vsprintf.c 1 1
File conf.mk changed (mode: 100644) (index aabc61b..bd3e578)
... ... CFLAGS+= -DDEBUG
23 23 endif endif
24 24
25 25 #customized your module list (scsi_wait is dealed with) #customized your module list (scsi_wait is dealed with)
26 MODULES?=ext4 ahci sd_mod sg
26 MODULES?=firmware_class ext4 ahci sd_mod sg
27 27 SCSI_WAIT?=1 SCSI_WAIT?=1
28 28 ifdef SCSI_WAIT ifdef SCSI_WAIT
29 29 MODULES+= scsi_wait_scan MODULES+= scsi_wait_scan
File globals.h changed (mode: 100644) (index 8bbc0d3..e33a5e2)
... ... extern k_u8 *g_dprintf_buf;
12 12 #define DPRINTF_BUF_SZ 1024 #define DPRINTF_BUF_SZ 1024
13 13 #define OUT(f,...) u_a_dprintf(g_console,g_dprintf_buf,DPRINTF_BUF_SZ,(k_u8*)f,\ #define OUT(f,...) u_a_dprintf(g_console,g_dprintf_buf,DPRINTF_BUF_SZ,(k_u8*)f,\
14 14 __VA_ARGS__) __VA_ARGS__)
15 //FIXME: deal with -K_EINTR and -K_EAGAIN
16 15 #define OUTC(s) sysc(write,3,g_console,s,sizeof(s)) #define OUTC(s) sysc(write,3,g_console,s,sizeof(s))
17 16 #else #else
18 17 #define PRE #define PRE
File init.c changed (mode: 100644) (index bf22a45..d5de9ab)
7 7 #include <ulinux/sysc.h> #include <ulinux/sysc.h>
8 8 #include <ulinux/types.h> #include <ulinux/types.h>
9 9 #include <ulinux/error.h> #include <ulinux/error.h>
10 #include <ulinux/fs.h>
10 11 #include <ulinux/socket/socket.h> #include <ulinux/socket/socket.h>
11 12 #include <ulinux/socket/netlink.h> #include <ulinux/socket/netlink.h>
12 13 #ifdef DEBUG #ifdef DEBUG
 
... ... static void sigs_setup(void)
40 41 OUTC("done\n"); OUTC("done\n");
41 42 } }
42 43
44 static void proc_mount(void)
45 {
46 OUTC(PRE "mounting proc...");
47 k_l r=sysc(mount,5,"proc","/proc","proc",K_MS_NOSUID|K_MS_NODEV|K_MS_NOEXEC,
48 0);
49 if(K_ISERR(r)){
50 OUT("ERROR:%ld\n",r);
51 sysc(exit_group,1,-1);
52 }
53 OUTC("done\n");
54 }
55
56 static void root_remount_rw(void)
57 {
58 OUTC(PRE "remounting / as RW...");
59 k_l r=sysc(mount,5,0,"/",0,K_MS_REMOUNT,0);
60 if(K_ISERR(r)){
61 OUT("ERROR:%ld\n",r);
62 sysc(exit_group,1,-1);
63 }
64 OUTC("done\n");
65 }
66
67 static void sysfs_mount(void)
68 {
69 OUTC(PRE "mounting sysfs...");
70 k_l r=sysc(mount,5,"sysfs","/sys","sysfs",K_MS_NOSUID|K_MS_NODEV|K_MS_NOEXEC,
71 0);
72 if(K_ISERR(r)){
73 OUT("ERROR:%ld\n",r);
74 sysc(exit_group,1,-1);
75 }
76 OUTC("done\n");
77 }
78
43 79 void _start(void) void _start(void)
44 80 { {
45 81 # ifdef DEBUG # ifdef DEBUG
 
... ... void _start(void)
52 88 # endif # endif
53 89 sigs_setup(); sigs_setup();
54 90 proc_mount(); proc_mount();
55 sys_mount();
56 sigs_setup();
91 root_remount_rw();
92 sysfs_mount();
57 93 uevent_setup(); uevent_setup();
58 uevent_recv_thread_start();
59 94 modules_load(); modules_load();
60 while(1);
95 uevent_recv();
61 96 sysc(exit_group,1,0); sysc(exit_group,1,0);
62 97 } }
File uevent.c changed (mode: 100644) (index ef452f3..4306e6f)
... ... void uevent_setup(void)
79 79 OUTC("done\n"); OUTC("done\n");
80 80 } }
81 81
82 static void uevent_rcv(k_i s)
82 static void uevent_msg(k_i s)
83 83 { {
84 84 k_u8 buf[8192]; k_u8 buf[8192];
85 85 u_memset(buf,0,sizeof(buf)); u_memset(buf,0,sizeof(buf));
 
... ... static void uevent_rcv(k_i s)
116 116 OUTC("\n"); OUTC("\n");
117 117 } }
118 118
119 static void uevent_recv(void)
119 void uevent_recv(void)
120 120 { {
121 121 OUTC(PRE "receiving uevent...\n"); OUTC(PRE "receiving uevent...\n");
122 122 while(1){ while(1){
 
... ... static void uevent_recv(void)
134 134 while(i<r){ while(i<r){
135 135 if(evts[i].data.fd==s){ if(evts[i].data.fd==s){
136 136 if(evts[i].events&K_EPOLLIN){ if(evts[i].events&K_EPOLLIN){
137 uevent_rcv(s);
137 uevent_msg(s);
138 138 }else{ }else{
139 139 OUT(PRE "ERROR:unmanaged epolling event on uevent netlink socket" OUT(PRE "ERROR:unmanaged epolling event on uevent netlink socket"
140 140 " n=%ld events=%u\n", i,evts[i].events); " n=%ld events=%u\n", i,evts[i].events);
 
... ... static void uevent_recv(void)
145 145 } }
146 146 } }
147 147 } }
148
149 void uevent_recv_thread_start(void)
150 {
151 k_l r=sysc(clone,5,K_,0,NULL,NULL,NULL);
152 if(K_ISERR(r)){
153 PERR("FATAL:error precloning process slot %d with error %ld\n",slot,r);
154 return -1;
155 }
156 if(r==0) goto preclone_entry_setup;
157
158 _preclones[slot].s=s[1];
159 sysc(close,1,s[0]);
160 _preclones[slot].pid=(k_i)r;
161 return 0;
162
163 preclone_entry_setup:
164 _slot=slot;
165 sysc(close,1,s[1]);//close parent unix socket
166 _parent_sock=s[0];
167
168 sysc(close,1,0);//for the connexion socket
169 sysc(close,1,1);//for the connexion socket
170 //keep stderr
171
172 sysc(close,1,_sigs_fd);//don't care of parent signal
173 sysc(close,1,_epfd);//don't use parent epoll
174
175 _preclone_entry();
176 return -1;
177 }
File uevent.h changed (mode: 100644) (index 10522cc..ddd67fe)
6 6 //* <digital.ragnarok AT gmail dot com> //* <digital.ragnarok AT gmail dot com>
7 7 //****************************************************************************** //******************************************************************************
8 8 void uevent_setup(void); void uevent_setup(void);
9 void uevent_recv_thread_start(void);
9 void uevent_recv(void);
10 //void uevent_recv_thread_start(void);
10 11 #endif #endif
File uevent_monitor.c changed (mode: 100644) (index 75cce0f..18603bc)
10 10 #include <ulinux/file.h> #include <ulinux/file.h>
11 11 #include <ulinux/stat.h> #include <ulinux/stat.h>
12 12 #include <ulinux/mmap.h> #include <ulinux/mmap.h>
13 #include <ulinux/time.h>
13 14 #include <ulinux/signal/signal.h> #include <ulinux/signal/signal.h>
14 15 #include <ulinux/socket/socket.h> #include <ulinux/socket/socket.h>
15 16 #include <ulinux/socket/msg.h> #include <ulinux/socket/msg.h>
 
... ... void _start(void)
113 114 sysc(exit_group,1,-1); sysc(exit_group,1,-1);
114 115 } }
115 116
117 //----------------------------------------------------------------------------
118
119 struct timespec wanted={20,0};
120 struct timespec rem={0,0};
121 ERRC("Sleeping 20 sec (buffering)...\n");
122 r=sysc(nanosleep,2,&wanted,&rem);
123 if(r==-K_EINTR){
124 ERR("WARNING:sleep was interruped. Remainder %ld sec/%ld nsec\n",rem.sec,
125 rem.nsec);
126 }else if(K_ISERR(r)){
127 ERR("ERROR:sleeping:%ld\n",r);
128 sysc(exit_group,1,-1);
129 }
130 ERRC("done\n");
131
116 132 //---------------------------------------------------------------------------- //----------------------------------------------------------------------------
117 133
118 134 struct k_epoll_event ep_evt; struct k_epoll_event ep_evt;
File ulinux/archs/x86_64/mmap.h changed (mode: 100644) (index 91da1a8..7c44088)
5 5 //*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> //*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com>
6 6 //* <digital.ragnarok AT gmail dot com> //* <digital.ragnarok AT gmail dot com>
7 7 //****************************************************************************** //******************************************************************************
8 #define K_PAGE_SIZE 4096
8 #define K_PAGE_SZ 4096
9 9 #endif #endif
File ulinux/dirent.h copied from file ulinux/time.h (similarity 71%) (mode: 100644) (index 37b6383..1fdb28f)
1 #ifndef ULINUX_TIME_H
2 #define ULINUX_TIME_H
1 #ifndef ULINUX_DIRENT_H
2 #define ULINUX_DIRENT_H
3 3 //****************************************************************************** //******************************************************************************
4 4 //*this code is protected by the GNU affero GPLv3 //*this code is protected by the GNU affero GPLv3
5 5 //*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> //*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com>
6 6 //* <digital.ragnarok AT gmail dot com> //* <digital.ragnarok AT gmail dot com>
7 7 //****************************************************************************** //******************************************************************************
8 struct timespec{
9 long sec;//seconds
10 long nsec;//nanoseconds
8 struct k_dirent64{
9 k_u64 ino;
10 k_s64 off;
11 k_us rec_len;
12 k_u8 type;
13 k_u8 name[0];
11 14 }; };
12 15 #endif #endif
File ulinux/fs.h changed (mode: 100644) (index 5125790..5d56edb)
33 33 #define K_MS_BORN (1<<29) #define K_MS_BORN (1<<29)
34 34 #define K_MS_ACTIVE (1<<30) #define K_MS_ACTIVE (1<<30)
35 35 #define K_MS_NOUSER (1<<31) #define K_MS_NOUSER (1<<31)
36
37 #define K_DT_UNKNOWN 0
38 #define K_DT_FIFO 1
39 #define K_DT_CHR 2
40 #define K_DT_DIR 4
41 #define K_DT_BLK 6
42 #define K_DT_REG 8
43 #define K_DT_LNK 10
44 #define K_DT_SOCK 12
45 #define K_DT_WHT 14
36 46 #endif #endif
File ulinux/patterns/args/args.c changed (mode: 100644) (index 69aa1eb..b55f85f)
4 4 #include <ulinux/types.h> #include <ulinux/types.h>
5 5 #include <ulinux/args.h> #include <ulinux/args.h>
6 6
7 #include <ulinux/utils/ascii/string/string.h>
8 7 #include <ulinux/utils/ascii/string/vsprintf.h> #include <ulinux/utils/ascii/string/vsprintf.h>
9 8
10 9 void start(k_i argc,k_u8 **argv) void start(k_i argc,k_u8 **argv)
File ulinux/patterns/dir_parse/dir_parse.c added (mode: 100644) (index 0000000..1b22dfd)
1 #include <stdarg.h>
2 #include <ulinux/compiler_types.h>
3 #include <ulinux/sysc.h>
4 #include <ulinux/types.h>
5 #include <ulinux/error.h>
6 #include <ulinux/args.h>
7 #include <ulinux/file.h>
8 #include <ulinux/fs.h>
9 #include <ulinux/dirent.h>
10
11 #include <ulinux/utils/ascii/string/vsprintf.h>
12
13 #define DPRINTF_BUF_SZ 1024
14 static k_u8 *dprintf_buf;
15
16 #define PERRC(s) {k_l rl;do{rl=sysc(write,3,2,s,sizeof(s));}\
17 while(rl==-K_EINTR||rl==-K_EAGAIN);}
18 #define PERR(f,...) u_a_dprintf(2,dprintf_buf,DPRINTF_BUF_SZ,(k_u8*)f,\
19 ##__VA_ARGS__)
20 #define POUT(f,...) u_a_dprintf(1,dprintf_buf,DPRINTF_BUF_SZ,(k_u8*)f,\
21 __VA_ARGS__)
22 #define POUTC(s) {k_l rl;do{rl=sysc(write,3,1,s,sizeof(s));}\
23 while(rl==-K_EINTR||rl==-K_EAGAIN);}
24
25 static k_ut is_current(k_u8 *n)
26 {
27 if(n[0]=='.'&&n[1]==0) return 1;
28 return 0;
29 }
30
31 static k_ut is_parent(k_u8 *n)
32 {
33 if(n[0]=='.'&&n[1]=='.'&&n[2]==0) return 1;
34 return 0;
35 }
36
37 static k_u depth=-1;
38
39 static void dout(struct k_dirent64 *d)
40 {
41 POUT("%20lu %20ld %2u ",d->ino,d->off,d->type,d->name);
42 k_u i=depth;
43 while(i--) POUTC(" ");
44 POUT("%s\n",d->name);//XXX:ugly-->we already have the string size
45 }
46
47 #define DIRENTS_BUF_SZ 8192
48 //XXX:carefull, the dentry type is not supported by all fs
49 static void dir_parse(k_i parent_fd)
50 {
51 ++depth;
52 k_u8 dirents[DIRENTS_BUF_SZ];
53 while(1){
54 k_l r=sysc(getdents64,3,parent_fd,dirents,DIRENTS_BUF_SZ);
55 if(K_ISERR(r)){
56 PERR("ERROR(%ld):getdents error\n",r);
57 sysc(exit_group,1,-1);
58 }
59 if(!r) break;
60 k_l i=0;
61 while(i<r){
62 struct k_dirent64 *d=(struct k_dirent64*)(dirents+i);
63
64 dout(d);
65
66 if(d->type==K_DT_DIR&&!is_current(d->name)&&!is_parent(d->name)){
67 k_i dir_fd;
68 do
69 dir_fd=(k_i)sysc(openat,4,parent_fd,d->name,K_O_RDONLY|K_O_NONBLOCK,
70 0);
71 while(dir_fd==-K_EINTR);
72 if(K_ISERR(dir_fd))
73 PERR("ERROR(%d):unable to open subdir:%s\n",dir_fd,d->name);
74 else{
75 dir_parse(dir_fd);
76 sysc(close,1,dir_fd);
77 }
78 }
79 i+=d->rec_len;
80 }
81 }
82 depth--;
83 }
84
85 void start(k_i argc,k_u8 **argv)
86 {
87 k_u8 _dprintf_buf[DPRINTF_BUF_SZ];
88 dprintf_buf=&_dprintf_buf[0];
89
90 if(argc!=2){
91 PERR("ERROR:wrong number of command arguments(%d)\n",argc);
92 sysc(exit_group,1,-1);
93 }
94
95 //root fd
96 k_i root_fd;
97 do
98 root_fd=(k_i)sysc(open,3,argv[1],K_O_RDONLY|K_O_NONBLOCK,0);
99 while(root_fd==-K_EINTR);
100 if(K_ISERR(root_fd)){
101 PERR("ERROR(%d):unable to open root dir:%s\n",root_fd,argv[1]);
102 sysc(exit_group,1,-1);
103 }
104
105 dir_parse(root_fd);
106 sysc(exit_group,1,0);
107 }
File ulinux/patterns/dir_parse/makefile copied from file ulinux/patterns/args/makefile (similarity 72%) (mode: 100644) (index 09250c7..4210853)
2 2
3 3 ARCH?=$(shell uname -m | sed -e s/i.86/i386/ -e s/parisc64/parisc/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ -e s/sh.*/sh/) ARCH?=$(shell uname -m | sed -e s/i.86/i386/ -e s/parisc64/parisc/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ -e s/sh.*/sh/)
4 4
5 args:args.c ../../../ulinux/arch
5 dir_parse:dir_parse.c ../../../ulinux/arch
6 6 gcc -Wall -Wextra -std=gnu99 -O3 -march=native -fverbose-asm -I../../.. -S \ gcc -Wall -Wextra -std=gnu99 -O3 -march=native -fverbose-asm -I../../.. -S \
7 7 ../../arch/utils/mem.c -o mem.s ../../arch/utils/mem.c -o mem.s
8 8 as mem.s -o mem.o as mem.s -o mem.o
 
... ... args:args.c ../../../ulinux/arch
12 12 gcc -Wall -Wextra -std=gnu99 -O3 -march=native -fverbose-asm -I../../.. -S \ gcc -Wall -Wextra -std=gnu99 -O3 -march=native -fverbose-asm -I../../.. -S \
13 13 ../../utils/ascii/string/string.c -o string.s ../../utils/ascii/string/string.c -o string.s
14 14 as string.s -o string.o as string.s -o string.o
15 as ../../arch/args.s -o arch_args.o
15 as ../../arch/args.s -o args.o
16 16 gcc -Wall -Wextra -std=gnu99 -O3 -march=native -fverbose-asm -I../../.. -S \ gcc -Wall -Wextra -std=gnu99 -O3 -march=native -fverbose-asm -I../../.. -S \
17 args.c -o args.s
18 as args.s -o args.o
19 ld -O -nostdlib -Bstatic --strip-all args.o arch_args.o string.o mem.o vsprintf.o --output args
17 dir_parse.c -o dir_parse.s
18 as dir_parse.s -o dir_parse.o
19 ld -O -nostdlib -Bstatic --strip-all dir_parse.o args.o string.o mem.o vsprintf.o --output dir_parse
20 20
21 21 ../../../ulinux/arch: ../../../ulinux/arch:
22 22 ln -s archs/$(ARCH) ../../../ulinux/arch ln -s archs/$(ARCH) ../../../ulinux/arch
23 23
24 24 clean: clean:
25 -rm -f ../../../ulinux/arch args.s args.o args \
25 -rm -f ../../../ulinux/arch dir_parse.s dir_parse.o dir_parse \
26 26 mem.s mem.o \ mem.s mem.o \
27 27 string.s string.o \ string.s string.o \
28 28 vsprintf.s vsprintf.o \ vsprintf.s vsprintf.o \
29 arch_args.o
29 args.o
File ulinux/patterns/network_server/pre-fork_socket_unix_tcp/README deleted (index 9712a81..0000000)
1 this is a TCP/IPv4 server distributing connexions to pre-clone processes or freshly created processes using unix socket
File ulinux/utils/ascii/string/vsprintf.c changed (mode: 100644) (index ca45280..84c5a66)
... ... static k_u8 *_number(k_u8 *buf,k_u8 *end,k_ull num,struct printf_spec spec)
272 272
273 273 static k_u8 *_string(k_u8 *buf,k_u8 *end,k_u8 *s,struct printf_spec spec) static k_u8 *_string(k_u8 *buf,k_u8 *end,k_u8 *s,struct printf_spec spec)
274 274 { {
275 if((k_ul)s<K_PAGE_SIZE) s=(k_u8*)"(null)";//XXX:why excluding first page *here*??
275 if((k_ul)s<K_PAGE_SZ) s=(k_u8*)"(null)";//XXX:why excluding first page *here*??
276 276
277 277 k_ul len; k_ul len;
278 278 if(!u_a_strnlen(&len,s,spec.precision)) len=spec.precision; if(!u_a_strnlen(&len,s,spec.precision)) len=spec.precision;
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/sylware/cinitramfs

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/sylware/cinitramfs

Clone this repository using git:
git clone git://git.rocketgit.com/user/sylware/cinitramfs

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main