From 1342d280808b2fb2b1e8a7192986c041f9824c69 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 22 Mar 2002 21:16:15 +0000 Subject: [PATCH] Finished the package. Added proper daemonization code. --- ChangeLog | 4 ++++ debian/changelog | 30 +++++++++++++++--------------- debian/control | 5 +---- debian/rules | 8 ++++---- net.h | 1 + nwhod.c | 29 ++++++++++++++++------------- 6 files changed, 41 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8d272a6..d12890a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2002-03-22 Martin Mares + + * nwhod.c: Use a hard-coded port number instead of pondering on /etc/services. + 2002-03-22 Martin Mares * Split ywho and nwho. diff --git a/debian/changelog b/debian/changelog index 257223a..bdb4c1d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Fri, 22 Mar 2002 21:18:30 +0100 + -- root 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 Wed, 7 Feb 2001 17:55:55 +0100 + -- root 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 Tue, 6 Feb 2001 21:33:21 +0100 + -- root 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 Tue, 6 Feb 2001 21:21:35 +0100 + -- Martin Mares 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 Sun, 8 Jan 1999 14:44:21 +0100 + -- Martin Mares Fri, 22 Mar 2002 21:18:30 +0100 Local variables: mode: debian-changelog diff --git a/debian/control b/debian/control index e858262..b5d3027 100644 --- a/debian/control +++ b/debian/control @@ -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. diff --git a/debian/rules b/debian/rules index 5267064..098bd2b 100755 --- a/debian/rules +++ b/debian/rules @@ -1,6 +1,6 @@ #!/usr/bin/make -f -# Rules for building of ywho Debian/UCW Package -# (c) 1999 Martin Mares +# Rules for building of nwho Debian/UCW Package +# (c) 2002 Martin Mares # 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 54a0959..4b6b713 100644 --- 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 23accf6..d706fbf 100644 --- 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); -- 2.39.2