File makefile changed (mode: 100644) (index 07787c4..438b68b) |
1 |
1 |
include conf.mk |
include conf.mk |
2 |
2 |
|
|
3 |
|
.PHONY:all dirs clean am_i_root help uevent_monitor |
|
|
3 |
|
.PHONY:all dirs clean am_i_root help |
4 |
4 |
|
|
5 |
5 |
DIRS=\ |
DIRS=\ |
6 |
6 |
$(S_DIR) \ |
$(S_DIR) \ |
|
... |
... |
$(CPIO_DIR)/sys |
14 |
14 |
OBJS=\ |
OBJS=\ |
15 |
15 |
$(OBJ_DIR)/init.o \ |
$(OBJ_DIR)/init.o \ |
16 |
16 |
$(OBJ_DIR)/modules.o \ |
$(OBJ_DIR)/modules.o \ |
17 |
|
$(OBJ_DIR)/uevent.o |
|
|
17 |
|
$(OBJ_DIR)/uevents.o |
18 |
18 |
|
|
19 |
19 |
ifdef DEBUG |
ifdef DEBUG |
20 |
20 |
ULINUX_DEBUG_OBJS=\ |
ULINUX_DEBUG_OBJS=\ |
|
... |
... |
OBJS+= $(ULINUX_DEBUG_OBJS) |
26 |
26 |
endif |
endif |
27 |
27 |
|
|
28 |
28 |
help: |
help: |
29 |
|
@echo "targets are 'all', 'help'(this output), 'clean', 'uevent_monitor'" |
|
|
29 |
|
@echo "targets are 'all', 'help'(this output), 'clean'" |
30 |
30 |
@echo -e "you can configure the build with the following variables:\\n\ |
@echo -e "you can configure the build with the following variables:\\n\ |
31 |
31 |
SYSROOT, KERNEL_VERSION, ARCH, MODULES, SCSI_WAIT, CC, LD, CFLAGS, LDFLAGS\\n\ |
SYSROOT, KERNEL_VERSION, ARCH, MODULES, SCSI_WAIT, CC, LD, CFLAGS, LDFLAGS\\n\ |
32 |
32 |
(you can tune the conf.mk file)" |
(you can tune the conf.mk file)" |
|
... |
... |
$(S_DIR)/modules.s:modules.c modules_list.h |
79 |
79 |
$(OBJ_DIR)/modules.o:$(S_DIR)/modules.s |
$(OBJ_DIR)/modules.o:$(S_DIR)/modules.s |
80 |
80 |
$(AS) $(ASFLAGS) $< -o $@ |
$(AS) $(ASFLAGS) $< -o $@ |
81 |
81 |
|
|
82 |
|
$(S_DIR)/uevent.s:uevent.c |
|
|
82 |
|
$(S_DIR)/uevents.s:uevents.c |
83 |
83 |
$(CC) $(CFLAGS) $< -o $@ |
$(CC) $(CFLAGS) $< -o $@ |
84 |
|
$(OBJ_DIR)/uevent.o:$(S_DIR)/uevent.s |
|
|
84 |
|
$(OBJ_DIR)/uevents.o:$(S_DIR)/uevents.s |
85 |
85 |
$(AS) $(ASFLAGS) $< -o $@ |
$(AS) $(ASFLAGS) $< -o $@ |
86 |
86 |
|
|
87 |
87 |
$(S_DIR)/init.s:init.c modules.h |
$(S_DIR)/init.s:init.c modules.h |
|
... |
... |
clean: |
99 |
99 |
-rm -f ulinux/arch |
-rm -f ulinux/arch |
100 |
100 |
-rm -Rf $(BUILD_DIR) |
-rm -Rf $(BUILD_DIR) |
101 |
101 |
-rm -f modules_list.h |
-rm -f modules_list.h |
102 |
|
|
|
103 |
|
#=============================================================================== |
|
104 |
|
$(BUILD_DIR)/uevent_monitor:uevent_monitor.c $(ULINUX_DEBUG_OBJS) |
|
105 |
|
$(CC) $(CFLAGS) -fverbose-asm -S $< -o $(S_DIR)/uevent_monitor.s |
|
106 |
|
$(AS) $(S_DIR)/uevent_monitor.s -o $(OBJ_DIR)/uevent_monitor.o |
|
107 |
|
$(LD) $(LDFLAGS) $(OBJ_DIR)/uevent_monitor.o $(ULINUX_DEBUG_OBJS) --output $@ |
|
108 |
|
|
|
109 |
|
uevent_monitor:dirs ulinux/arch $(BUILD_DIR)/uevent_monitor |
|
110 |
|
#=============================================================================== |
|
File uevents.c renamed from uevent.c (similarity 86%) (mode: 100644) (index 4306e6f..c7ab039) |
26 |
26 |
static k_i ep_fd=-1; |
static k_i ep_fd=-1; |
27 |
27 |
static k_i s=-1; |
static k_i s=-1; |
28 |
28 |
|
|
29 |
|
void uevent_setup(void) |
|
|
29 |
|
void uevents_setup(void) |
30 |
30 |
{ |
{ |
31 |
31 |
OUTC(PRE "setting up uevent..."); |
OUTC(PRE "setting up uevent..."); |
32 |
32 |
ep_fd=(k_i)sysc(epoll_create1,1,0); |
ep_fd=(k_i)sysc(epoll_create1,1,0); |
33 |
33 |
if(K_ISERR(ep_fd)){ |
if(K_ISERR(ep_fd)){ |
34 |
|
OUT("ERROR:unable to create epoll fd (%d)\n",ep_fd); |
|
|
34 |
|
OUT("ERROR(%d):unable to create epoll fd\n",ep_fd); |
35 |
35 |
sysc(exit_group,1,-1); |
sysc(exit_group,1,-1); |
36 |
36 |
} |
} |
37 |
37 |
|
|
|
... |
... |
void uevent_setup(void) |
40 |
40 |
s=(k_i)sysc(socket,3,K_PF_NETLINK,K_SOCK_RAW|K_SOCK_NONBLOCK, |
s=(k_i)sysc(socket,3,K_PF_NETLINK,K_SOCK_RAW|K_SOCK_NONBLOCK, |
41 |
41 |
K_NETLINK_KOBJECT_UEVENT); |
K_NETLINK_KOBJECT_UEVENT); |
42 |
42 |
if(K_ISERR(s)){ |
if(K_ISERR(s)){ |
43 |
|
OUT("ERROR:unable to create uevent netlink socket:%d\n",s); |
|
|
43 |
|
OUT("ERROR(%d):unable to create uevent netlink socket\n",s); |
44 |
44 |
sysc(exit_group,1,-1); |
sysc(exit_group,1,-1); |
45 |
45 |
} |
} |
46 |
46 |
|
|
47 |
47 |
//---------------------------------------------------------------------------- |
//---------------------------------------------------------------------------- |
48 |
48 |
|
|
49 |
|
k_i recv_buf_sz=128*1024*1024; |
|
|
49 |
|
k_i recv_buf_sz=128*1024;//128k for kernel buffering |
50 |
50 |
k_l r=sysc(setsockopt,5,s,K_SOL_SOCKET,K_SO_RCVBUFFORCE,&recv_buf_sz, |
k_l r=sysc(setsockopt,5,s,K_SOL_SOCKET,K_SO_RCVBUFFORCE,&recv_buf_sz, |
51 |
51 |
sizeof(recv_buf_sz)); |
sizeof(recv_buf_sz)); |
52 |
52 |
if(K_ISERR(r)){ |
if(K_ISERR(r)){ |
53 |
|
OUT("ERROR:unable to force the size of the socket buffer:%ld\n",r); |
|
|
53 |
|
OUT("ERROR(%ld):unable to force the size of the socket buffer\n",r); |
54 |
54 |
sysc(exit_group,1,-1); |
sysc(exit_group,1,-1); |
55 |
55 |
} |
} |
56 |
56 |
|
|
|
... |
... |
void uevent_setup(void) |
60 |
60 |
struct k_sockaddr_nl addr={K_AF_NETLINK,0,0,1}; |
struct k_sockaddr_nl addr={K_AF_NETLINK,0,0,1}; |
61 |
61 |
r=sysc(bind,3,s,&addr,sizeof(addr)); |
r=sysc(bind,3,s,&addr,sizeof(addr)); |
62 |
62 |
if(K_ISERR(r)){ |
if(K_ISERR(r)){ |
63 |
|
OUT("ERROR:unable to bind address to uevent netlink socket:%ld\n",r); |
|
|
63 |
|
OUT("ERROR(%ld):unable to bind address to uevent netlink socket\n",r); |
64 |
64 |
sysc(exit_group,1,-1); |
sysc(exit_group,1,-1); |
65 |
65 |
} |
} |
66 |
66 |
|
|
|
... |
... |
void uevent_setup(void) |
72 |
72 |
ep_evt.data.fd=s; |
ep_evt.data.fd=s; |
73 |
73 |
r=sysc(epoll_ctl,4,ep_fd,K_EPOLL_CTL_ADD,s,&ep_evt); |
r=sysc(epoll_ctl,4,ep_fd,K_EPOLL_CTL_ADD,s,&ep_evt); |
74 |
74 |
if(K_ISERR(r)){ |
if(K_ISERR(r)){ |
75 |
|
OUT("ERROR:unable to register uevent netlink socket to epoll (%ld)\n", |
|
76 |
|
r); |
|
|
75 |
|
OUT("ERROR(%ld):unable to register uevent netlink socket to epoll\n",r); |
77 |
76 |
sysc(exit_group,1,-1); |
sysc(exit_group,1,-1); |
78 |
77 |
} |
} |
79 |
78 |
OUTC("done\n"); |
OUTC("done\n"); |
|
... |
... |
static void uevent_msg(k_i s) |
98 |
97 |
r=sysc(recvmsg,3,s,&msg,0); |
r=sysc(recvmsg,3,s,&msg,0); |
99 |
98 |
}while(r==-K_EINTR); |
}while(r==-K_EINTR); |
100 |
99 |
if(K_ISERR(r)){ |
if(K_ISERR(r)){ |
101 |
|
OUT("ERROR:unable to receive the uevent(%ld)\n",r); |
|
|
100 |
|
OUT("ERROR(%ld):unable to receive the uevent\n",r); |
102 |
101 |
sysc(exit_group,1,-1); |
sysc(exit_group,1,-1); |
103 |
102 |
} |
} |
104 |
103 |
if(msg.flgs&K_MSG_TRUNC){ |
if(msg.flgs&K_MSG_TRUNC){ |
|
... |
... |
static void uevent_msg(k_i s) |
116 |
115 |
OUTC("\n"); |
OUTC("\n"); |
117 |
116 |
} |
} |
118 |
117 |
|
|
119 |
|
void uevent_recv(void) |
|
|
118 |
|
void uevents_process(void) |
120 |
119 |
{ |
{ |
121 |
|
OUTC(PRE "receiving uevent...\n"); |
|
|
120 |
|
OUTC(PRE "processing uevents...\n"); |
122 |
121 |
while(1){ |
while(1){ |
123 |
122 |
k_l r; |
k_l r; |
124 |
123 |
static struct k_epoll_event evts[1];//uevent netlink event |
static struct k_epoll_event evts[1];//uevent netlink event |
File ulinux/patterns/uevents_monitor/makefile copied from file ulinux/patterns/args/makefile (similarity 68%) (mode: 100644) (index 09250c7..dc6eeb9) |
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 |
|
uevents_monitor:uevents_monitor.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 |
|
16 |
15 |
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 |
|
|
16 |
|
uevents_monitor.c -o uevents_monitor.s |
|
17 |
|
as uevents_monitor.s -o uevents_monitor.o |
|
18 |
|
ld -O -nostdlib -Bstatic --strip-all uevents_monitor.o string.o mem.o vsprintf.o --output uevents_monitor |
20 |
19 |
|
|
21 |
20 |
../../../ulinux/arch: |
../../../ulinux/arch: |
22 |
21 |
ln -s archs/$(ARCH) ../../../ulinux/arch |
ln -s archs/$(ARCH) ../../../ulinux/arch |
23 |
22 |
|
|
24 |
23 |
clean: |
clean: |
25 |
|
-rm -f ../../../ulinux/arch args.s args.o args \ |
|
|
24 |
|
-rm -f ../../../ulinux/arch uevents_monitor.s uevents_monitor.o uevents_monitor \ |
26 |
25 |
mem.s mem.o \ |
mem.s mem.o \ |
27 |
26 |
string.s string.o \ |
string.s string.o \ |
28 |
|
vsprintf.s vsprintf.o \ |
|
29 |
|
arch_args.o |
|
|
27 |
|
vsprintf.s vsprintf.o |
File ulinux/patterns/uevents_monitor/uevents_monitor.c renamed from uevent_monitor.c (similarity 97%) (mode: 100644) (index 18603bc..ddd0ccd) |
3 |
3 |
//*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> |
//*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> |
4 |
4 |
//* <digital.ragnarok AT gmail dot com> |
//* <digital.ragnarok AT gmail dot com> |
5 |
5 |
//****************************************************************************** |
//****************************************************************************** |
|
6 |
|
#include <stdarg.h> |
6 |
7 |
#include <ulinux/compiler_types.h> |
#include <ulinux/compiler_types.h> |
7 |
8 |
#include <ulinux/sysc.h> |
#include <ulinux/sysc.h> |
8 |
9 |
#include <ulinux/types.h> |
#include <ulinux/types.h> |
|
16 |
17 |
#include <ulinux/socket/msg.h> |
#include <ulinux/socket/msg.h> |
17 |
18 |
#include <ulinux/socket/netlink.h> |
#include <ulinux/socket/netlink.h> |
18 |
19 |
#include <ulinux/epoll.h> |
#include <ulinux/epoll.h> |
19 |
|
#include <stdarg.h> |
|
20 |
20 |
#include <ulinux/utils/ascii/string/vsprintf.h> |
#include <ulinux/utils/ascii/string/vsprintf.h> |
21 |
21 |
#include <ulinux/utils/mem.h> |
#include <ulinux/utils/mem.h> |
22 |
22 |
|
|
23 |
23 |
//XXX:what udev does in extra |
//XXX:what udev does in extra |
24 |
|
// - it force overides the kernel socket buffer size to 128 MB (then 256 MB) |
|
25 |
24 |
// - it checks on socket credential |
// - it checks on socket credential |
26 |
25 |
// - it checks the netlink sender is 0 (kernel) |
// - it checks the netlink sender is 0 (kernel) |
27 |
26 |
// - it uses the socket filter |
// - it uses the socket filter |
|
... |
... |
void _start(void) |
95 |
94 |
|
|
96 |
95 |
//why that big (stolen from udev)? |
//why that big (stolen from udev)? |
97 |
96 |
//moreover it can be skipped most of the time |
//moreover it can be skipped most of the time |
98 |
|
//must be priviledge |
|
|
97 |
|
//must be priviledged |
99 |
98 |
k_i recv_buf_sz=128*1024*1024; |
k_i recv_buf_sz=128*1024*1024; |
100 |
99 |
k_l r=sysc(setsockopt,5,s,K_SOL_SOCKET,K_SO_RCVBUFFORCE,&recv_buf_sz, |
k_l r=sysc(setsockopt,5,s,K_SOL_SOCKET,K_SO_RCVBUFFORCE,&recv_buf_sz, |
101 |
100 |
sizeof(recv_buf_sz)); |
sizeof(recv_buf_sz)); |