X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=nwhod.c;h=05e73a91a23eece788753f5cd1d5696bfbcb2bef;hb=f15fc7443aaaffb32b4805b164f6035c1ab3d1f5;hp=f432d00d67f418f21ee83a0d0d88285fe4e1a33c;hpb=df2c6855e32660fbe8a09aa86f64c8fcb9142c76;p=nwho.git diff --git a/nwhod.c b/nwhod.c index f432d00..05e73a9 100644 --- a/nwhod.c +++ b/nwhod.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include "net.h" @@ -59,7 +58,7 @@ net_init(char *name) if (name) { if (! (h = gethostbyname(name))) - die("%s: %m", name); + die("Failed to resolve %s", name); } else h = NULL; @@ -199,16 +198,16 @@ is_valid(u32 ipa) static void receive(void) { - int r, al; + int r; struct nwho_pkt pkt; struct sockaddr_in sa; + socklen_t al = sizeof(sa); int n = sizeof(struct nwho_pkt) - MAX_USERS * sizeof(struct userinfo); struct hostrec *e; struct hostent *h; char *c; alarm(DEFAULT_PRUNE_TIME); - al = sizeof(sa); r = recvfrom(sock, &pkt, sizeof(pkt), 0, (struct sockaddr *) &sa, &al); alarm(0); now = time(NULL); @@ -311,6 +310,12 @@ do_tick(void) static void daemonize(void) { + pid_t pid = fork(); + if (pid < 0) + die("Fork failed: %m"); + if (pid) + exit(0); + close(0); close(1); close(2); @@ -367,24 +372,14 @@ client(char *serv) int main(int argc, char **argv) { - int pid; - - if (argc != 1 && argc != 2) - { - fprintf(stderr, "Usage: nwhod []\n"); - return 1; - } - pid = fork(); - if (pid < 0) - { - perror("fork"); - return 1; - } - if (pid) - return 0; if (argc == 2) client(argv[1]); else if (argc == 1) server(); - return 1; + else + { + fprintf(stderr, "Usage: nwhod []\n"); + return 1; + } + return 0; }