Day55 - SCM_RIGHTS File Descriptor Passing¶
Goal¶
Learn:
- sendmsg()
- recvmsg()
- ancillary data
- SCM_RIGHTS
- epoll on received fd
Environment¶
- Raspberry Pi 5
- Linux kernel 6.x
/dev/mypolldriver available
Step 1 - Basic UNIX socketpair¶
Create socket pair:
Fork parent and child.
Verify simple communication using:
- sendmsg()
- recvmsg()
Step 2 - Implement SCM_RIGHTS¶
Create helper functions:
Use:
Attach fd using:
Step 3 - Verify Shared File Offset¶
Parent:
Child:
Verify read starts from shared offset.
Step 4 - Verify Open Mode¶
Parent:
Child:
Expected:
Step 5 - eventfd + epoll¶
Parent:
Child:
Verify EPOLLIN event.
Step 6 - /dev/mypoll Integration¶
Parent:
Trigger events:
Child:
Expected:
- timer events
- manual events
- socket disconnect handling
Expected Result¶
Example output:
[INFO] [CHILD] read mypoll: event=21, source=timer
[INFO] [CHILD] read mypoll: event=22, source=timer
[INFO] [CHILD] read mypoll: event=25, source=manual
[WARN] [CHILD] parent disconnected
Learning Outcome¶
Understand:
- Linux fd passing model
- ancillary data
- epoll integration
- daemon / worker architecture
- UNIX socket IPC design