Added proper daemonization code.
+2002-03-22 Martin Mares <mj@ucw.cz>
+
+ * nwhod.c: Use a hard-coded port number instead of pondering on /etc/services.
+
2002-03-22 Martin Mares <mj@ucw.cz>
* Split ywho and nwho.
-ywho (1.9-4) unstable; urgency=low
+nwho (1.9-8) unstable; urgency=low
- * Split ywho and nwho.
+ * Fixed daemonization code.
- -- Martin Mares <mj@kam.mff.cuni.cz> Fri, 22 Mar 2002 21:18:30 +0100
+ -- root <root@kam.mff.cuni.cz> Fri, 22 Mar 2002 22:08:44 +0100
-ywho (1.9-3) unstable; urgency=low
+nwho (1.9-7) unstable; urgency=low
- * Minor bugfix of console formatting.
+ * Remember to call setsid.
- -- Martin Mares <mj@atrey.karlin.mff.cuni.cz> Wed, 7 Feb 2001 17:55:55 +0100
+ -- root <root@kam.mff.cuni.cz> Fri, 22 Mar 2002 22:01:16 +0100
-ywho (1.9-2) unstable; urgency=low
+nwho (1.9-6) unstable; urgency=low
- * Synced with master CVS.
+ * Remember to clean the state directory when restarting the daemon.
- -- Martin Mares <mj@atrey.karlin.mff.cuni.cz> Tue, 6 Feb 2001 21:33:21 +0100
+ -- root <root@kam.mff.cuni.cz> Fri, 22 Mar 2002 21:50:06 +0100
-ywho (1.9-1) unstable; urgency=low
+nwho (1.9-5) unstable; urgency=low
- * New upstream release
+ * Use hard-coded port number instead of that in /etc/services.
- -- Martin Mares <mj@atrey.karlin.mff.cuni.cz> Tue, 6 Feb 2001 21:21:35 +0100
+ -- Martin Mares <mj@kam.mff.cuni.cz> Fri, 22 Mar 2002 21:40:27 +0100
-ywho (1.0) unstable; urgency=low
+nwho (1.9-4) unstable; urgency=low
- * First released version.
+ * Split nwho and nwho.
- -- Martin Mares <mj@ucw.cz> Sun, 8 Jan 1999 14:44:21 +0100
+ -- Martin Mares <mj@kam.mff.cuni.cz> Fri, 22 Mar 2002 21:18:30 +0100
Local variables:
mode: debian-changelog
Architecture: any
Depends: ${shlibs:Depends}
Description: Extended who
- This is Yet Another Who Replacement utility with neat display of
- all logged in users together with important system status information
- like average load, current date and time, free memory and so on.
- Also includes nwho/nwhod, a replacement for rwho/rwhod.
+ This is Yet Another RWho Replacement utility.
#!/usr/bin/make -f
-# Rules for building of ywho Debian/UCW Package
-# (c) 1999 Martin Mares <mj@ucw.cz>
+# Rules for building of nwho Debian/UCW Package
+# (c) 2002 Martin Mares <mj@ucw.cz>
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
dh_testdir
dh_testroot
dh_clean -k
- dh_installdirs etc sbin var/state/nwho
+ dh_installdirs etc/init.d etc/default usr/bin usr/sbin var/state/nwho
$(MAKE) ROOT=`pwd`/debian/tmp install
# dh_installdocs
# dh_installexamples
# dh_installmenu
-# dh_installinit
+ dh_installinit
# dh_installcron
# dh_installmanpages
dh_undocumented nwho.1 nwhod.8
#define NWHO_SPOOL_DIR "/var/state/nwho"
#define NWHO_MAGIC 0x21913332
+#define NWHO_PORT 811
#define DEFAULT_SEND_TIME 30
#define DEFAULT_PRUNE_TIME 30
{
struct hostent *h;
struct sockaddr_in sa;
- struct servent *se;
- int one;
if (name)
{
else
h = NULL;
- if (! (se = getservbyname("nwho", "udp")))
- die("Unknown service `nwho/udp'");
-
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock < 0)
die("socket: %m");
- if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0)
- die("setsockopt: %m");
-
sa.sin_family = AF_INET;
- sa.sin_port = port = se->s_port;
+ sa.sin_port = port = NWHO_PORT;
sa.sin_addr.s_addr = INADDR_ANY;
if (bind(sock, (struct sockaddr *) &sa, sizeof(sa)) < 0)
die("bind: %m");
sprintf(h->con, "%.7s", u->ut_line);
sprintf(device, "/dev/%s", u->ut_line);
if (stat(device, &st) < 0)
- {
- fprintf(stderr, "stat(%s): %m", device);
- continue;
- }
+ continue;
h->mesg_y = !!(S_IWGRP & st.st_mode);
last = st.st_atime;
if (st.st_mtime > last)
}
}
+static void
+daemonize(void)
+{
+ close(0);
+ close(1);
+ close(2);
+ open("/dev/null", O_RDONLY);
+ dup(0);
+ dup(0);
+ setsid();
+}
+
static void
tick(int unused)
{
if (chdir(NWHO_SPOOL_DIR) < 0)
die("chdir(" NWHO_SPOOL_DIR "): %m");
cleanup();
+ daemonize();
bzero(&sigact, sizeof(sigact));
sigact.sa_handler = tick;
sigaction(SIGALRM, &sigact, NULL);
net_init(serv);
utmpname(UTMP_FILE);
+ daemonize();
for(;;)
{
now = time(NULL);