mounttab.c (194880) | mounttab.c (201135) |
---|---|
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> | 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 194880 2009-06-24 18:42:21Z dfr $"); | 29__FBSDID("$FreeBSD: head/usr.sbin/rpc.umntall/mounttab.c 201135 2009-12-28 17:57:37Z delphij $"); |
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> 38#include <limits.h> 39#include <stdio.h> 40#include <stdlib.h> 41#include <string.h> 42#include <unistd.h> 43 44#include "mounttab.h" 45 46struct mtablist *mtabhead; 47 | 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> 38#include <limits.h> 39#include <stdio.h> 40#include <stdlib.h> 41#include <string.h> 42#include <unistd.h> 43 44#include "mounttab.h" 45 46struct mtablist *mtabhead; 47 |
48static void badline(char *field, char *bad); | 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 FILE *mtabfile; --- 7 unchanged lines hidden (view full) --- 64 return (1); 65 } 66} 67 68/* 69 * Read mounttab line for line and return struct mtablist. 70 */ 71int | 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 FILE *mtabfile; --- 7 unchanged lines hidden (view full) --- 64 return (1); 65 } 66} 67 68/* 69 * Read mounttab line for line and return struct mtablist. 70 */ 71int |
72read_mtab() { | 72read_mtab(void) { |
73 struct mtablist **mtabpp, *mtabp; 74 char *hostp, *dirp, *cp; 75 char str[STRSIZ]; 76 char *timep, *endp; | 73 struct mtablist **mtabpp, *mtabp; 74 char *hostp, *dirp, *cp; 75 char str[STRSIZ]; 76 char *timep, *endp; |
77 time_t time; | 77 time_t actiontime; |
78 u_long ultmp; 79 FILE *mtabfile; 80 81 if ((mtabfile = fopen(PATH_MOUNTTAB, "r")) == NULL) { 82 if (errno == ENOENT) 83 return (0); 84 else { 85 syslog(LOG_ERR, "can't open %s", PATH_MOUNTTAB); 86 return (0); 87 } 88 } | 78 u_long ultmp; 79 FILE *mtabfile; 80 81 if ((mtabfile = fopen(PATH_MOUNTTAB, "r")) == NULL) { 82 if (errno == ENOENT) 83 return (0); 84 else { 85 syslog(LOG_ERR, "can't open %s", PATH_MOUNTTAB); 86 return (0); 87 } 88 } |
89 time = 0; | 89 actiontime = 0; |
90 mtabpp = &mtabhead; 91 while (fgets(str, STRSIZ, mtabfile) != NULL) { 92 cp = str; 93 errno = 0; 94 if (*cp == '#' || *cp == ' ' || *cp == '\n') 95 continue; 96 timep = strsep(&cp, " \t\n"); 97 if (timep == NULL || *timep == '\0') { --- 10 unchanged lines hidden (view full) --- 108 badline("dir", dirp); 109 continue; 110 } 111 ultmp = strtoul(timep, &endp, 10); 112 if (ultmp == ULONG_MAX || *endp != '\0') { 113 badline("time", timep); 114 continue; 115 } | 90 mtabpp = &mtabhead; 91 while (fgets(str, STRSIZ, mtabfile) != NULL) { 92 cp = str; 93 errno = 0; 94 if (*cp == '#' || *cp == ' ' || *cp == '\n') 95 continue; 96 timep = strsep(&cp, " \t\n"); 97 if (timep == NULL || *timep == '\0') { --- 10 unchanged lines hidden (view full) --- 108 badline("dir", dirp); 109 continue; 110 } 111 ultmp = strtoul(timep, &endp, 10); 112 if (ultmp == ULONG_MAX || *endp != '\0') { 113 badline("time", timep); 114 continue; 115 } |
116 time = ultmp; | 116 actiontime = ultmp; |
117 if ((mtabp = malloc(sizeof (struct mtablist))) == NULL) { 118 syslog(LOG_ERR, "malloc"); 119 fclose(mtabfile); 120 return (0); 121 } | 117 if ((mtabp = malloc(sizeof (struct mtablist))) == NULL) { 118 syslog(LOG_ERR, "malloc"); 119 fclose(mtabfile); 120 return (0); 121 } |
122 mtabp->mtab_time = time; | 122 mtabp->mtab_time = actiontime; |
123 memmove(mtabp->mtab_host, hostp, MNTNAMLEN); 124 mtabp->mtab_host[MNTNAMLEN - 1] = '\0'; 125 memmove(mtabp->mtab_dirp, dirp, MNTPATHLEN); 126 mtabp->mtab_dirp[MNTPATHLEN - 1] = '\0'; 127 mtabp->mtab_next = (struct mtablist *)NULL; 128 *mtabpp = mtabp; 129 mtabpp = &mtabp->mtab_next; 130 } --- 82 unchanged lines hidden (view full) --- 213 free(mtabp); 214 } 215} 216 217/* 218 * Print bad lines to syslog. 219 */ 220static void | 123 memmove(mtabp->mtab_host, hostp, MNTNAMLEN); 124 mtabp->mtab_host[MNTNAMLEN - 1] = '\0'; 125 memmove(mtabp->mtab_dirp, dirp, MNTPATHLEN); 126 mtabp->mtab_dirp[MNTPATHLEN - 1] = '\0'; 127 mtabp->mtab_next = (struct mtablist *)NULL; 128 *mtabpp = mtabp; 129 mtabpp = &mtabp->mtab_next; 130 } --- 82 unchanged lines hidden (view full) --- 213 free(mtabp); 214 } 215} 216 217/* 218 * Print bad lines to syslog. 219 */ 220static void |
221badline(char *field, char *bad) { | 221badline(const char *field, const char *bad) { |
222 syslog(LOG_ERR, "bad mounttab %s field '%s'", field, 223 (bad == NULL) ? "<null>" : bad); 224} | 222 syslog(LOG_ERR, "bad mounttab %s field '%s'", field, 223 (bad == NULL) ? "<null>" : bad); 224} |