file.c (21786) | file.c (30376) |
---|---|
1/* 2 * Copyright (c) 1995 3 * A.R. Gordon (andrew.gordon@net-tel.co.uk). 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 --- 17 unchanged lines hidden (view full) --- 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 */ 33 | 1/* 2 * Copyright (c) 1995 3 * A.R. Gordon (andrew.gordon@net-tel.co.uk). 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 --- 17 unchanged lines hidden (view full) --- 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 */ 33 |
34#include <stdio.h> 35#include <unistd.h> 36#include <fcntl.h> | 34#include <err.h> |
37#include <errno.h> | 35#include <errno.h> |
36#include <fcntl.h> 37#include <stdio.h> |
|
38#include <string.h> | 38#include <string.h> |
39#include <unistd.h> |
|
39#include <sys/types.h> 40#include <sys/mman.h> /* For mmap() */ 41#include <rpc/rpc.h> 42#include <syslog.h> 43 44#include "statd.h" 45 46FileLayout *status_info; /* Pointer to the mmap()ed status file */ --- 95 unchanged lines hidden (view full) --- 142 /* try to open existing file - if not present, create one */ 143 status_fd = open(filename, O_RDWR); 144 if ((status_fd < 0) && (errno == ENOENT)) 145 { 146 status_fd = open(filename, O_RDWR | O_CREAT, 0644); 147 new_file = TRUE; 148 } 149 if (status_fd < 0) | 40#include <sys/types.h> 41#include <sys/mman.h> /* For mmap() */ 42#include <rpc/rpc.h> 43#include <syslog.h> 44 45#include "statd.h" 46 47FileLayout *status_info; /* Pointer to the mmap()ed status file */ --- 95 unchanged lines hidden (view full) --- 143 /* try to open existing file - if not present, create one */ 144 status_fd = open(filename, O_RDWR); 145 if ((status_fd < 0) && (errno == ENOENT)) 146 { 147 status_fd = open(filename, O_RDWR | O_CREAT, 0644); 148 new_file = TRUE; 149 } 150 if (status_fd < 0) |
150 { 151 perror("rpc.statd"); 152 fprintf(stderr, "Unable to open status file %s\n", filename); 153 exit(1); 154 } | 151 errx(1, "unable to open status file %s", filename); |
155 156 /* File now open. mmap() it, with a generous size to allow for */ 157 /* later growth, where we will extend the file but not re-map it. */ 158 status_info = (FileLayout *) 159 mmap(NULL, 0x10000000, PROT_READ | PROT_WRITE, MAP_SHARED, status_fd, 0); 160 161 if (status_info == (FileLayout *) MAP_FAILED) | 152 153 /* File now open. mmap() it, with a generous size to allow for */ 154 /* later growth, where we will extend the file but not re-map it. */ 155 status_info = (FileLayout *) 156 mmap(NULL, 0x10000000, PROT_READ | PROT_WRITE, MAP_SHARED, status_fd, 0); 157 158 if (status_info == (FileLayout *) MAP_FAILED) |
162 { 163 perror("rpc.statd"); 164 fprintf(stderr, "Unable to mmap() status file\n"); 165 } | 159 warn("unable to mmap() status file"); |
166 167 status_file_len = lseek(status_fd, 0L, SEEK_END); 168 169 /* If the file was not newly created, validate the contents, and if */ 170 /* defective, re-create from scratch. */ 171 if (!new_file) 172 { 173 if ((status_file_len < HEADER_LEN) || (status_file_len 174 < (HEADER_LEN + sizeof(HostInfo) * status_info->noOfHosts)) ) 175 { | 160 161 status_file_len = lseek(status_fd, 0L, SEEK_END); 162 163 /* If the file was not newly created, validate the contents, and if */ 164 /* defective, re-create from scratch. */ 165 if (!new_file) 166 { 167 if ((status_file_len < HEADER_LEN) || (status_file_len 168 < (HEADER_LEN + sizeof(HostInfo) * status_info->noOfHosts)) ) 169 { |
176 fprintf(stderr, "rpc.statd: status file is corrupt\n"); | 170 warnx("status file is corrupt"); |
177 new_file = TRUE; 178 } 179 } 180 181 /* Initialisation of a new, empty file. */ 182 if (new_file) 183 { 184 memset(buf, 0, sizeof(buf)); --- 172 unchanged lines hidden --- | 171 new_file = TRUE; 172 } 173 } 174 175 /* Initialisation of a new, empty file. */ 176 if (new_file) 177 { 178 memset(buf, 0, sizeof(buf)); --- 172 unchanged lines hidden --- |