Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unix Network Programming Chapter 13: Daemon processes and the inetd superserver 22.4.2005 Jani Peusaari.

Similar presentations


Presentation on theme: "Unix Network Programming Chapter 13: Daemon processes and the inetd superserver 22.4.2005 Jani Peusaari."— Presentation transcript:

1 Unix Network Programming Chapter 13: Daemon processes and the inetd superserver 22.4.2005 Jani Peusaari

2 Contents

3 Daemons Processes without a controlling terminal Generally started via startup scripts with superuser priviliges Perform administrative duties, networked or local services etc Output using syslog daemon, syslogd

4 Syslogd daemon Collects kernel, service and user specific log information to system specific files Used through UDP socket port 514 – Directly by sending a datagram – syslog function UDP disabled by default, DoS possibilities

5 syslog function #include void syslog(int priority, const char *message, …); Priority is ORred from level and facility Second argument is format (as in e.g. printf) with %m, error message (derived from errno) In addition, openlog and closelog functions

6 Syslog Levels Described in RFC 3164 Seven levels – 0 is the highest, LOG_EMERG – 7 lowest, LOG_DEBUG Level 5 (LOG_NOTICE) is the default man syslog

7 Facilities LOG_USER is the default LOG_AUTH for security, LOG_DAEMON for system daemons etc 8 local messages for user services (e.g. LOG_LOCAL0)

8 Why syslog Daemons detach themselves, even if started from the console – No stdin, stdout, stderr Different levels of output (Debug, notice, warning, emergency) Collect messages in an uniform way Portability, no need to know to which file to write messages to

9 Daemons SIGHUP

10 How to make a daemon Some systems have daemon() function 1. Fork -> Parent exits 2. Child becomes session leader 3. Ignore SIGHUP signal 4. Fork -> Child 1 exits 5. Change working directory (/), close file descriptors, std(in|out|err) to /dev/null

11 Inetd, xinetd Many inet services (ftp, rlogin, etc) are needed, but are not used often They all require similar functionality (daemonize, listen to sockets) Inetd listens to the sockets, forks the service on their behalf Only one process in the process list

12

13 Service types Multi-threaded – Inetd forks a daemon with a new socket to service the client – Inetd listens to the original socket Single-threaded – Inetd forks a daemon, and the daemon handles all incoming requests, old or new (Datagram services)

14 Benefits Saves system resources, only one process listening to several sockets Simplifies service creation, as inetd handles lots of common features on their behalf Centralized access control to all inetd based services (xinetd) Centralized logging (xinetd) User services that are not in /etc/services (xinetd)


Download ppt "Unix Network Programming Chapter 13: Daemon processes and the inetd superserver 22.4.2005 Jani Peusaari."

Similar presentations


Ads by Google