Deleted Added
sdiff udiff text old ( 201135 ) new ( 201252 )
full compact
1/*
2 * Copyright (c) 1999 Martin Blapp
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/usr.sbin/rpc.umntall/mounttab.c 201252 2009-12-30 06:36:42Z ed $");
30
31#include <sys/syslog.h>
32
33#include <rpc/rpc.h>
34#include <rpcsvc/mount.h>
35
36#include <err.h>
37#include <errno.h>

--- 9 unchanged lines hidden (view full) ---

47
48static void badline(const char *field, const char *bad);
49
50/*
51 * Add an entry to PATH_MOUNTTAB for each mounted NFS filesystem,
52 * so the client can notify the NFS server even after reboot.
53 */
54int
55add_mtab(char *hostp, char *dirp)
56{
57 FILE *mtabfile;
58
59 if ((mtabfile = fopen(PATH_MOUNTTAB, "a")) == NULL)
60 return (0);
61 else {
62 fprintf(mtabfile, "%ld\t%s\t%s\n",
63 (long)time(NULL), hostp, dirp);
64 fclose(mtabfile);
65 return (1);
66 }
67}
68
69/*
70 * Read mounttab line for line and return struct mtablist.
71 */
72int
73read_mtab(void)
74{
75 struct mtablist **mtabpp, *mtabp;
76 char *hostp, *dirp, *cp;
77 char str[STRSIZ];
78 char *timep, *endp;
79 time_t actiontime;
80 u_long ultmp;
81 FILE *mtabfile;
82

--- 51 unchanged lines hidden (view full) ---

134 return (1);
135}
136
137/*
138 * Rewrite PATH_MOUNTTAB from scratch and skip bad entries.
139 * Unlink PATH_MOUNTAB if no entry is left.
140 */
141int
142write_mtab(int verbose)
143{
144 struct mtablist *mtabp, *mp;
145 FILE *mtabfile;
146 int line;
147
148 if ((mtabfile = fopen(PATH_MOUNTTAB, "w")) == NULL) {
149 syslog(LOG_ERR, "can't write to %s", PATH_MOUNTTAB);
150 return (0);
151 }

--- 26 unchanged lines hidden (view full) ---

178 }
179 return (1);
180}
181
182/*
183 * Mark the entries as clean where RPC calls have been done successfully.
184 */
185void
186clean_mtab(char *hostp, char *dirp, int verbose)
187{
188 struct mtablist *mtabp;
189 char *host;
190
191 /* Copy hostp in case it points to an entry that we are zeroing out. */
192 host = strdup(hostp);
193 for (mtabp = mtabhead; mtabp != NULL; mtabp = mtabp->mtab_next) {
194 if (strcmp(mtabp->mtab_host, host) != 0)
195 continue;

--- 8 unchanged lines hidden (view full) ---

204 }
205 free(host);
206}
207
208/*
209 * Free struct mtablist mtab.
210 */
211void
212free_mtab(void)
213{
214 struct mtablist *mtabp;
215
216 while ((mtabp = mtabhead) != NULL) {
217 mtabhead = mtabhead->mtab_next;
218 free(mtabp);
219 }
220}
221
222/*
223 * Print bad lines to syslog.
224 */
225static void
226badline(const char *field, const char *bad)
227{
228 syslog(LOG_ERR, "bad mounttab %s field '%s'", field,
229 (bad == NULL) ? "<null>" : bad);
230}