summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsc2001-11-19 08:29:20 +0000
committersc2001-11-19 08:29:20 +0000
commit810cb310a3ee7594b06b25d150edc358210ca5ef (patch)
treefa27d33c226cfab57eeb6e8861b89f6fa0de1ba5
parent9cca9c1a117982ab7988548935693f6a9cfdd8ed (diff)
downloadivyd-810cb310a3ee7594b06b25d150edc358210ca5ef.zip
ivyd-810cb310a3ee7594b06b25d150edc358210ca5ef.tar.gz
ivyd-810cb310a3ee7594b06b25d150edc358210ca5ef.tar.bz2
ivyd-810cb310a3ee7594b06b25d150edc358210ca5ef.tar.xz
New option -n
-rw-r--r--doc/ivyd.19
-rw-r--r--src/ivyd.c72
2 files changed, 67 insertions, 14 deletions
diff --git a/doc/ivyd.1 b/doc/ivyd.1
index cf611d9..4b308c6 100644
--- a/doc/ivyd.1
+++ b/doc/ivyd.1
@@ -15,14 +15,14 @@
-.TH IVYD 1 "11 Nov 1999"
+.TH IVYD 1 "16 Nov 2001"
.ds )H CENA, France.
-.ds ]W V1.0
+.ds ]W V1.1
.UC 4
.SH NAME
ivyd - the Ivy daemon that relays messages to an Ivy bus.
.SH SYNOPSIS
-.B "ivyd [-d] [-b bus]"
+.B "ivyd [-d] [-b bus] [-n procname]"
.SH DESCRIPTION
.B ivyd
is an Ivy agent which binds to a socket and awaits requests from
@@ -59,6 +59,9 @@ and the default network is
.I 127,
ie. loopback on the
local host.
+.TP
+.B -n name
+Make the process appear as 'name' instead of 'ivyd'
.SH EXAMPLE
.LP
diff --git a/src/ivyd.c b/src/ivyd.c
index f53d6a3..67db9d3 100644
--- a/src/ivyd.c
+++ b/src/ivyd.c
@@ -1,7 +1,7 @@
/*
* IvyDaemon, an Ivy gateway for short-lived agents
*
- * Copyright (C) 1999
+ * Copyright (C) 1999-2001
* Centre d'Études de la Navigation Aérienne
*
* Main file for the server
@@ -31,20 +31,24 @@
#include <netdb.h>
#include "ivy.h"
+#include "ivyloop.h"
#include "ivyd.h"
const char* const servicename = "ivyd";
const char* const port_env_variable = "INIVYD_PORT";
const int default_port = DEFAULT_INIVYD_PORT;
+const char* appname = "IVYD";
int debug = 0;
+int frk = 1;
static void
Usage (const char* progname)
{
- fprintf (stderr, "Usage: %s [-b bus][-d]\n", progname);
- fprintf (stderr, " -d: does not fork so as to facilitate debugging\n");
+ fprintf (stderr, "Usage: %s [-b bus][-d][-n name]\n", progname);
+ fprintf (stderr, " -d: does not fork and print debugging messages\n");
fprintf (stderr, " -b bus: selects Ivy bus on which to relay messages\n");
+ fprintf (stderr, " -n name: process will appear as 'name'\n");
exit (1);
}
@@ -168,23 +172,29 @@ InitSocket (int key)
void
+#if 0
HandleRequests (void* ch, int fd, void* data)
+#else
+HandleRequests (Channel ch, HANDLE fd, void* data)
+#endif
{
request req;
char* p = (char*) &req;
int n = sizeof (request);
+#if 0
struct sockaddr_in addr;
int len = sizeof (addr);
+#endif
if (debug)
fprintf (stderr, "REQUEST on %d\n", fd);
/* retrieve request */
while (n > 0) {
-#if 1
- int l = read (fd, p, n);
-#else
+#if 0
int l = recvfrom (fd, p, n, 0, (struct sockaddr*) &addr, &len);
+#else
+ int l = read (fd, p, n);
#endif
if (l < 0) {
perror ("Error retrieving request from client");
@@ -212,7 +222,7 @@ HandleRequests (void* ch, int fd, void* data)
}
void
-HandleConnections (void* ch, int fd, void* data)
+HandleConnections (Channel ch, HANDLE fd, void* data)
{
static struct sockaddr sa;
static int acc;
@@ -234,31 +244,70 @@ ExtractPort (const char* bus)
}
void
-main (int argc, char **argv)
+setproctitle (char** argv, char* limit, char* title)
+{
+ int len = strlen (title);
+ int maxlen = limit - argv[0] - 2;
+ char* p = argv[0];
+ char* q = title;
+
+ if (len > maxlen) {
+ len = maxlen;
+ title [maxlen] = '\0';
+ }
+
+ while (*q) {
+ if (*q != '\n' && *q != '\r')
+ *p++ = *q;
+ ++q;
+ }
+ *p++ = '\0';
+ while (p < limit)
+ *p++ = ' ';
+}
+
+int
+main (int argc, char **argv, char** envp)
{
int sock;
char busbuf [128];
int busport;
const char* bus = 0;
+ char titlebuf [256];
+ char* title = 0;
int c;
+ char* limit;
/* handle args */
- while ((c = getopt (argc, argv, "b:d")) != EOF) {
+ while (*envp)
+ envp++;
+ limit = envp [-1] + strlen (envp [-1]);
+ while ((c = getopt (argc, argv, "b:n:d")) != EOF) {
switch (c) {
case 'b':
strcpy (busbuf, optarg) ;
bus = busbuf;
break;
case 'd':
+ frk = 0;
debug = 1;
break;
+ case 'n':
+ strncpy (titlebuf, optarg, 256) ;
+ titlebuf[255] = '\0';
+ title = titlebuf;
+ appname = titlebuf;
+ break;
default:
Usage (argv[0]);
}
}
+ if (title)
+ setproctitle (argv, limit, title);
+
/* detach from tty */
- if (! debug)
+ if (frk)
if (fork ())
exit (0);
@@ -273,9 +322,10 @@ main (int argc, char **argv)
/* Ivy initialization and main loop */
- IvyInit ("IVYD", 0, 0, 0, 0, 0);
+ IvyInit (appname, 0, 0, 0, 0, 0);
IvyChannelSetUp (sock, 0, 0, HandleConnections);
IvyStart (bus);
IvyMainLoop (0);
+ return 1;
}