]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/statd/misc.c
Define and use HIAVE_IFADDRS_H
[nfs-utils.git] / utils / statd / misc.c
1 /* 
2  * Copyright (C) 1995-1999 Jeffrey A. Uphoff
3  * Modified by Olaf Kirch, 1996.
4  * Modified by H.J. Lu, 1998.
5  *
6  * NSM for Linux.
7  */
8
9 #ifdef HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12
13 #include <errno.h>
14 #include <limits.h>
15 #include <string.h>
16 #include <unistd.h>
17 #include "statd.h"
18 #include "notlist.h"
19
20 /*
21  * Error-checking malloc() wrapper.
22  */
23 void *
24 xmalloc (size_t size)
25 {
26   void *ptr;
27
28   if (size == 0)
29     return ((void *)NULL);
30
31   if (!(ptr = malloc (size)))
32     /* SHIT!  SHIT!  SHIT! */
33     die ("malloc failed");
34
35   return (ptr);
36 }
37
38
39 /* 
40  * Error-checking strdup() wrapper.
41  */
42 char *
43 xstrdup (const char *string)
44 {
45   char *result;
46
47   /* Will only fail if underlying malloc() fails (ENOMEM). */
48   if (!(result = strdup (string)))
49     die ("strdup failed");
50
51   return (result);
52 }
53
54
55 /*
56  * Call with check=1 to verify that this host is not still on the rtnl
57  * before unlinking file.
58  */
59 void
60 xunlink (char *path, char *host, short int check)
61 {
62   char *tozap;
63
64   tozap=alloca (strlen(path)+strlen(host)+2);
65   sprintf (tozap, "%s/%s", path, host);
66
67   if (!check || !nlist_gethost(rtnl, host, 0)) {
68     if (unlink (tozap) == -1)
69       note (N_ERROR, "unlink (%s): %s", tozap, strerror (errno));
70     else
71       dprintf (N_DEBUG, "Unlinked %s", tozap);
72   }
73   else
74     dprintf (N_DEBUG, "Not unlinking %s--host still monitored.", tozap);
75 }