From ca2ba434712fd304b30051b43b694775235d3a20 Mon Sep 17 00:00:00 2001 From: chatty Date: Mon, 15 Nov 1999 13:17:53 +0000 Subject: Cosmetic changes: name of temporary file and comments --- src/inivyd.c | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'src/inivyd.c') diff --git a/src/inivyd.c b/src/inivyd.c index 7f4a06f..72e6ff0 100644 --- a/src/inivyd.c +++ b/src/inivyd.c @@ -17,19 +17,20 @@ */ /* - * Le super-demon wixd. + * The super-demon (in.ivyd): * - * Il est normalement lance par inetd, avec la chaussette SOCK_DGRAM - * sur le descripteur 0, ou alors, si le symbole FROMBOOT est defini, il est - * lance depuis /etc/rc.local. + * It is either launched by inetd with the socket SOCK_DGRAM on file descriptor 0, + * or at boot time with the -boot flag. * - * Le serveur wixd: - * Il envoie un paquet connmsg de type MSG_SERVER contenant le numero - * de port sur lequel il a connecte sa chaussette. + * The daemon (ivyd): + * + * It sends the super-daemon a message connmsg of type MSG_SERVER that contains + * the port number of the socket it connected to. * - * Les clients wix (wx, wxcat, etc ...): - * Ils envoient un paquet connmsg de type MSG_CLIENT ou ils demandent - * le port. + * The clients (ivyecho, ...): + * + * They send the super-daemon a message connmsg of type MSG_CLIENT + * to ask for the port number * * L'identification de l'emetteur du paquet est le numero d'utilisateur. */ @@ -50,22 +51,22 @@ #include "ivyd.h" -const char* const dumpfilename = "/usr/tmp/wixd.db"; +const char* const dumpfilename = "/tmp/in.ivyd.db"; const int dumpfilemode = 0644; const char* const servicename = "ivyd"; const char* const port_env_variable = "INIVYD_PORT"; const int default_port = 3006; /* - * Definition de la table geree par le super-demon + * The association table managed by the super-daemon */ typedef struct { - short s_port; /* le port sur lequel le client communique avec son serveur */ - short s_key; /* le numero de processus du serveur wixd */ + short s_port; /* port number */ + short s_key; /* server id */ } serverinfo; -#define TABSIZ 64 /* 64 connections simultanees, ca devrait aller */ +#define TABSIZ 64 /* 64 simultaneous servers are allowed */ serverinfo si_table [TABSIZ]; serverinfo* @@ -156,19 +157,23 @@ main (int argc, const char **argv) ++argv; --argc; } - + + /* special case when launched at boot time (ie. not from inetd) */ + if (boot) { + /* in normal mode, we behave as a daemon with no terminal */ if (!debug) { int s; + /* first let's fork... */ if (fork ()) exit (0); - /* on ferme tous les descripteurs */ + /* ...then let's close all descriptors... */ for (s = getdtablesize (); --s >= 0;) close (s); - /* et on se debarrasse du terminal de controle */ + /* ... and get rid of our control terminal */ if (-1 != open ("/dev/tty", 2)) { (void) ioctl (0, TIOCNOTTY, 0); close (0); @@ -176,9 +181,7 @@ main (int argc, const char **argv) } else close (0); - /* - * Ouvre la chaussette et l'attache a bon port - */ + /* Now it's time to open the socket for requests */ if (-1 == socket (AF_INET, SOCK_DGRAM, 0)) exit (1); memset (&from, 0, sizeof from); @@ -189,6 +192,7 @@ main (int argc, const char **argv) exit (1); } + /* now we can handle messages and requests */ for (;;) { fromlen = sizeof from; if (recvfrom (0, (char *)&msg, sizeof msg, 0, (struct sockaddr *)&from, &fromlen) <= 0) { @@ -196,13 +200,17 @@ main (int argc, const char **argv) continue; exit (1); } + si = GetInfo (msg.msg_key); switch (msg.msg_type) { + + /* message from server: we store the information */ case MSG_SERVER: si->s_port = msg.msg_port; si->s_key = msg.msg_key; break; + /* message from a client: we retrieve and send the information */ case MSG_CLIENT: msg.msg_port = si->s_port; msg.msg_type = MSG_REPLY; -- cgit v1.1