Deleted Added
full compact
pututxline.c (226846) pututxline.c (241046)
1/*-
2 * Copyright (c) 2010 Ed Schouten <ed@FreeBSD.org>
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

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

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
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#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2010 Ed Schouten <ed@FreeBSD.org>
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

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

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
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#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/lib/libc/gen/pututxline.c 226846 2011-10-27 17:05:18Z ed $");
28__FBSDID("$FreeBSD: head/lib/libc/gen/pututxline.c 241046 2012-09-29 11:54:34Z jilles $");
29
30#include "namespace.h"
31#include <sys/endian.h>
32#include <sys/stat.h>
33#include <sys/uio.h>
34#include <errno.h>
35#include <fcntl.h>
36#include <stdio.h>

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

42
43static FILE *
44futx_open(const char *file)
45{
46 FILE *fp;
47 struct stat sb;
48 int fd;
49
29
30#include "namespace.h"
31#include <sys/endian.h>
32#include <sys/stat.h>
33#include <sys/uio.h>
34#include <errno.h>
35#include <fcntl.h>
36#include <stdio.h>

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

42
43static FILE *
44futx_open(const char *file)
45{
46 FILE *fp;
47 struct stat sb;
48 int fd;
49
50 fd = _open(file, O_CREAT|O_RDWR|O_EXLOCK, 0644);
50 fd = _open(file, O_CREAT|O_RDWR|O_EXLOCK|O_CLOEXEC, 0644);
51 if (fd < 0)
52 return (NULL);
53
54 /* Safety check: never use broken files. */
55 if (_fstat(fd, &sb) != -1 && sb.st_size % sizeof(struct futx) != 0) {
56 _close(fd);
57 errno = EFTYPE;
58 return (NULL);

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

230}
231
232static void
233utx_lastlogin_upgrade(void)
234{
235 struct stat sb;
236 int fd;
237
51 if (fd < 0)
52 return (NULL);
53
54 /* Safety check: never use broken files. */
55 if (_fstat(fd, &sb) != -1 && sb.st_size % sizeof(struct futx) != 0) {
56 _close(fd);
57 errno = EFTYPE;
58 return (NULL);

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

230}
231
232static void
233utx_lastlogin_upgrade(void)
234{
235 struct stat sb;
236 int fd;
237
238 fd = _open(_PATH_UTX_LASTLOGIN, O_RDWR, 0644);
238 fd = _open(_PATH_UTX_LASTLOGIN, O_RDWR|O_CLOEXEC, 0644);
239 if (fd < 0)
240 return;
241
242 /*
243 * Truncate broken lastlogin files. In the future we should
244 * check for older versions of the file format here and try to
245 * upgrade it.
246 */

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

264 */
265 for (l = sizeof(*fu); l > 0 && ((const char *)fu)[l - 1] == '\0'; l--) ;
266 vec[0].iov_base = &l;
267 vec[0].iov_len = sizeof(l);
268 vec[1].iov_base = __DECONST(void *, fu);
269 vec[1].iov_len = l;
270 l = htobe16(l);
271
239 if (fd < 0)
240 return;
241
242 /*
243 * Truncate broken lastlogin files. In the future we should
244 * check for older versions of the file format here and try to
245 * upgrade it.
246 */

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

264 */
265 for (l = sizeof(*fu); l > 0 && ((const char *)fu)[l - 1] == '\0'; l--) ;
266 vec[0].iov_base = &l;
267 vec[0].iov_len = sizeof(l);
268 vec[1].iov_base = __DECONST(void *, fu);
269 vec[1].iov_len = l;
270 l = htobe16(l);
271
272 fd = _open(_PATH_UTX_LOG, O_CREAT|O_WRONLY|O_APPEND, 0644);
272 fd = _open(_PATH_UTX_LOG, O_CREAT|O_WRONLY|O_APPEND|O_CLOEXEC, 0644);
273 if (fd < 0)
274 return (-1);
275 if (_writev(fd, vec, 2) == -1)
276 error = errno;
277 else
278 error = 0;
279 _close(fd);
280 errno = error;

--- 51 unchanged lines hidden ---
273 if (fd < 0)
274 return (-1);
275 if (_writev(fd, vec, 2) == -1)
276 error = errno;
277 else
278 error = 0;
279 _close(fd);
280 errno = error;

--- 51 unchanged lines hidden ---