Unix网络编程 第13章 Daemon Processes and the inetd Superserver 笔记

# The syslogd daemon runs in an infinite loop that calls select, waiting for any one of its three descriptors to be readable. it reads the log message and does what the configuration file says to do with that message. If the daemon receives the SIGHUP signal, it rereads its configuration file. So, what are the three descriptors that the select system call is waiting for ?  1. A unix domain socket is created and bound to the pathname /var/run/log (/dev/log on some systems). 2. A udp socket is created and bound to port 514(the syslog service). 3. The pathname /devklog is opened. Any error messages from within the kernel appears as input on this device. Newer implementation disable the creation of the UDP socket, unless specified by the administrator, as allowing anyone to send UDP datagrams to this port opens the system up to denial-of-service attacks, where some one could fill up the filesystem.

# syslog函数的%m specification表示当前errno对应的error message.

# syslog函数的level和facility是为了配置如何处理各种log.配置文件是/etc/syslog.conf.

# logger命令可以产生log message。于是可以在shell脚本里使用logger.

# The purpose of the second fork is to guarantee that the daemon cannot automatically acquire a controlling terminal should it open a terminal device in the future. When a session leader without a controlling terminal opens a terminal device(that is not currently some other session's controlling terminal), the termianl becomes the controlling terminal of the session leader. But by calling fork a second time, we guarantee that the second child is no longer a session leader, so it cfannot acquire a controlling terminal. We must ignore SIGHUP because when the session leader terminates(the first child), all processes in the session(our second child)receive the SIGHUP signal.

# daemon通常把当前工作目录设为 / .如果不这样的话就会有可能使得不能unmount某些文件系统。 http://ykyi.net

# On linux, /var/log/message is where the system send all LOG_USER messages after connecting from the same machine(e.g. localhost). Page370.

# 早期的Unix系统,早于4.3BSD.有很多服务像ftp, telnet, rlogin, tftp等都是以daemon的形式运行。每一个都要在进程表里占一个位置(each one took a slot in the process table).但是每个daemon大多数时间都在睡眠状态。从4.3BSD开始引入了inetd.

# inetd的配置对于UDP的wait_flag必须是wait.因为UDP socket只有一个.如果不wait话,parent存在可能性先于child进程得到CPU。而udp socket缓冲中的数据还未来得及读出。这样,inetd的select又返回这个socket可读。wait_flag的wait的意思就是要wait到fork出的子进程结束。而tcp socket会在accept返回的时候给子进程一个connected socket.父进程可以立即得到CPU执行select判断listenning socket是否可读。  http://ykyi.net

# xinetd的配置采用每个服务一个配置文件.而inetd用一个monolithic configuration file.

# On a Berkely-derived kernel the timeout for a tcp connect is normally 75秒.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.