summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchatty1999-11-15 13:17:53 +0000
committerchatty1999-11-15 13:17:53 +0000
commitca2ba434712fd304b30051b43b694775235d3a20 (patch)
tree8657e652e52fb6975eb5d89dfea7e5e632899b72
parent71df94b03403aec0681f7d5566862bebc3d3299b (diff)
downloadivyd-ca2ba434712fd304b30051b43b694775235d3a20.zip
ivyd-ca2ba434712fd304b30051b43b694775235d3a20.tar.gz
ivyd-ca2ba434712fd304b30051b43b694775235d3a20.tar.bz2
ivyd-ca2ba434712fd304b30051b43b694775235d3a20.tar.xz
Cosmetic changes: name of temporary file and comments
-rw-r--r--src/inivyd.c50
-rw-r--r--src/ivyd.c9
2 files changed, 34 insertions, 25 deletions
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;
diff --git a/src/ivyd.c b/src/ivyd.c
index 6dfc27a..f53d6a3 100644
--- a/src/ivyd.c
+++ b/src/ivyd.c
@@ -49,8 +49,8 @@ Usage (const char* progname)
}
-/*
- * Envoie un numero de port au super-serveur de la machine locale
+/*
+ * Procedure to register with the super-daemon
*/
int
SendPort (int key, int port)
@@ -262,13 +262,14 @@ main (int argc, char **argv)
if (fork ())
exit (0);
- /* determine port in bus address */
+ /* determine port in bus address */
busport = ExtractPort (bus);
/* create server port */
sock = InitSocket (busport);
- signal (SIGTERM, exit); /* pour flinguer le serveur */
+ /* this allows users to stop us cleanly */
+ signal (SIGTERM, exit);
/* Ivy initialization and main loop */