{"id":356,"date":"2011-12-27T00:59:47","date_gmt":"2011-12-26T16:59:47","guid":{"rendered":"http:\/\/ykyi.net\/?p=356"},"modified":"2011-12-27T00:59:47","modified_gmt":"2011-12-26T16:59:47","slug":"unix%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b-%e7%ac%ac13%e7%ab%a0-daemon-processes-and-the-inetd-superserver-%e7%ac%94%e8%ae%b0","status":"publish","type":"post","link":"https:\/\/ykyi.net\/?p=356","title":{"rendered":"Unix\u7f51\u7edc\u7f16\u7a0b \u7b2c13\u7ae0 Daemon Processes and the inetd Superserver \u7b14\u8bb0"},"content":{"rendered":"<p># 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 ?&nbsp; 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.<\/p>\n<p># syslog\u51fd\u6570\u7684%m specification\u8868\u793a\u5f53\u524derrno\u5bf9\u5e94\u7684error message.<\/p>\n<p># syslog\u51fd\u6570\u7684level\u548cfacility\u662f\u4e3a\u4e86\u914d\u7f6e\u5982\u4f55\u5904\u7406\u5404\u79cdlog.\u914d\u7f6e\u6587\u4ef6\u662f\/etc\/syslog.conf.<\/p>\n<p># logger\u547d\u4ee4\u53ef\u4ee5\u4ea7\u751flog message\u3002\u4e8e\u662f\u53ef\u4ee5\u5728shell\u811a\u672c\u91cc\u4f7f\u7528logger.<\/p>\n<p># 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&#39;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.<\/p>\n<p># daemon\u901a\u5e38\u628a\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u8bbe\u4e3a \/ .\u5982\u679c\u4e0d\u8fd9\u6837\u7684\u8bdd\u5c31\u4f1a\u6709\u53ef\u80fd\u4f7f\u5f97\u4e0d\u80fdunmount\u67d0\u4e9b\u6587\u4ef6\u7cfb\u7edf\u3002 <a href=\"http:\/\/ykyi.net\">http:\/\/ykyi.net<\/a><\/p>\n<p># On linux, \/var\/log\/message is where the system send all LOG_USER messages after connecting from the same machine(e.g. localhost). Page370.<\/p>\n<p># \u65e9\u671f\u7684Unix\u7cfb\u7edf\uff0c\u65e9\u4e8e4.3BSD.\u6709\u5f88\u591a\u670d\u52a1\u50cfftp, telnet, rlogin, tftp\u7b49\u90fd\u662f\u4ee5daemon\u7684\u5f62\u5f0f\u8fd0\u884c\u3002\u6bcf\u4e00\u4e2a\u90fd\u8981\u5728\u8fdb\u7a0b\u8868\u91cc\u5360\u4e00\u4e2a\u4f4d\u7f6e(each one took a slot in the process table).\u4f46\u662f\u6bcf\u4e2adaemon\u5927\u591a\u6570\u65f6\u95f4\u90fd\u5728\u7761\u7720\u72b6\u6001\u3002\u4ece4.3BSD\u5f00\u59cb\u5f15\u5165\u4e86inetd.<\/p>\n<p># inetd\u7684\u914d\u7f6e\u5bf9\u4e8eUDP\u7684wait_flag\u5fc5\u987b\u662fwait.\u56e0\u4e3aUDP socket\u53ea\u6709\u4e00\u4e2a.\u5982\u679c\u4e0dwait\u8bdd\uff0cparent\u5b58\u5728\u53ef\u80fd\u6027\u5148\u4e8echild\u8fdb\u7a0b\u5f97\u5230CPU\u3002\u800cudp socket\u7f13\u51b2\u4e2d\u7684\u6570\u636e\u8fd8\u672a\u6765\u5f97\u53ca\u8bfb\u51fa\u3002\u8fd9\u6837\uff0cinetd\u7684select\u53c8\u8fd4\u56de\u8fd9\u4e2asocket\u53ef\u8bfb\u3002wait_flag\u7684wait\u7684\u610f\u601d\u5c31\u662f\u8981wait\u5230fork\u51fa\u7684\u5b50\u8fdb\u7a0b\u7ed3\u675f\u3002\u800ctcp socket\u4f1a\u5728accept\u8fd4\u56de\u7684\u65f6\u5019\u7ed9\u5b50\u8fdb\u7a0b\u4e00\u4e2aconnected socket.\u7236\u8fdb\u7a0b\u53ef\u4ee5\u7acb\u5373\u5f97\u5230CPU\u6267\u884cselect\u5224\u65adlistenning socket\u662f\u5426\u53ef\u8bfb\u3002&nbsp; <a href=\"http:\/\/ykyi.net\">http:\/\/ykyi.net<\/a><\/p>\n<p># xinetd\u7684\u914d\u7f6e\u91c7\u7528\u6bcf\u4e2a\u670d\u52a1\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6.\u800cinetd\u7528\u4e00\u4e2amonolithic configuration file.<\/p>\n<p># On a Berkely-derived kernel the timeout for a tcp connect is normally 75\u79d2.<\/p>\n","protected":false},"excerpt":{"rendered":"<p># 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 &hellip; <a href=\"https:\/\/ykyi.net\/?p=356\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Unix\u7f51\u7edc\u7f16\u7a0b \u7b2c13\u7ae0 Daemon Processes and the inetd Superserver \u7b14\u8bb0&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,6,7],"tags":[82,118],"class_list":["post-356","post","type-post","status-publish","format-standard","hentry","category-network","category-tech_articles","category-unix_linux","tag-unix-socket","tag-118"],"_links":{"self":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts\/356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=356"}],"version-history":[{"count":0,"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions"}],"wp:attachment":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}