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