]> mj.ucw.cz Git - nwho.git/commitdiff
Finished the package.
authorMartin Mares <mj@ucw.cz>
Fri, 22 Mar 2002 21:16:15 +0000 (21:16 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 22 Mar 2002 21:16:15 +0000 (21:16 +0000)
Added proper daemonization code.

ChangeLog
debian/changelog
debian/control
debian/rules
net.h
nwhod.c

index 8d272a6dca205e488bc65cc0f986b6587832f7b7..d12890a4394883fefc0180597915ab14429d12c6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+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.
index 257223a22e59e0b278acd2d1aa00ef5f8764e56f..bdb4c1de742a4a1b5bd03ab696719fa5071a424b 100644 (file)
@@ -1,32 +1,32 @@
-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
index e8582629c6f2bd64f894fcef744f7ef60c3c7b90..b5d302779ce52136ea93302e29fe7e0b4045c989 100644 (file)
@@ -8,7 +8,4 @@ Package: nwho
 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.
index 52670648fc9dc27727365c566bb59ed3e7a7af2c..098bd2b2070f380065953c8b1f5580a9a44b9689 100755 (executable)
@@ -1,6 +1,6 @@
 #!/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
@@ -24,14 +24,14 @@ binary-arch: build
        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
diff --git a/net.h b/net.h
index 54a095957f2ccd0d4b2e57c05ab89182194b489a..4b6b7135cd2790c2464bc187da8af32b49851e2d 100644 (file)
--- a/net.h
+++ b/net.h
@@ -30,6 +30,7 @@ struct rywho_pkt {
 
 #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
diff --git a/nwhod.c b/nwhod.c
index 23accf6d3b61a78754708351ebd37363f8a04563..d706fbf257cbc3a78b22e2904e0c5ac9be94aee3 100644 (file)
--- a/nwhod.c
+++ b/nwhod.c
@@ -58,8 +58,6 @@ net_init(char *name)
 {
   struct hostent *h;
   struct sockaddr_in sa;
-  struct servent *se;
-  int one;
 
   if (name)
     {
@@ -69,18 +67,12 @@ net_init(char *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");
@@ -116,10 +108,7 @@ scan_utmp(struct rywho_pkt *p, time_t now)
        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)
@@ -322,6 +311,18 @@ do_tick(void)
       }
 }
 
+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)
 {
@@ -336,6 +337,7 @@ server(void)
   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);
@@ -354,6 +356,7 @@ client(char *serv)
 
   net_init(serv);
   utmpname(UTMP_FILE);
+  daemonize();
   for(;;)
     {
       now = time(NULL);