ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libeio/eio.c
(Generate patch)

Comparing libeio/eio.c (file contents):
Revision 1.150 by root, Fri Jun 15 02:57:36 2018 UTC vs.
Revision 1.155 by root, Fri Aug 17 17:31:43 2018 UTC

1/* 1/*
2 * libeio implementation 2 * libeio implementation
3 * 3 *
4 * Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2016,2017 Marc Alexander Lehmann <libeio@schmorp.de> 4 * Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2016,2017,2018 Marc Alexander Lehmann <libeio@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
329 329
330#ifndef O_CLOEXEC 330#ifndef O_CLOEXEC
331 #define O_CLOEXEC 0 331 #define O_CLOEXEC 0
332#endif 332#endif
333 333
334#ifndef O_NONBLOCK
335 #define O_NONBLOCK 0
336#endif
337
338#ifndef O_SEARCH
339 #define O_SEARCH O_RDONLY
340#endif
341
342#ifndef O_DIRECTORY
343 #define O_DIRECTORY 0
344#endif
345
334#ifndef EIO_PATH_MIN 346#ifndef EIO_PATH_MIN
335# define EIO_PATH_MIN 8160 347# define EIO_PATH_MIN 8160
336#endif 348#endif
337 349
338#define EIO_PATH_MAX (PATH_MAX <= EIO_PATH_MIN ? EIO_PATH_MIN : PATH_MAX) 350#define EIO_PATH_MAX (PATH_MAX <= EIO_PATH_MIN ? EIO_PATH_MIN : PATH_MAX)
354struct etp_tmpbuf; 366struct etp_tmpbuf;
355 367
356#if _POSIX_VERSION >= 200809L 368#if _POSIX_VERSION >= 200809L
357 #define HAVE_AT 1 369 #define HAVE_AT 1
358 #define WD2FD(wd) ((wd) ? (wd)->fd : AT_FDCWD) 370 #define WD2FD(wd) ((wd) ? (wd)->fd : AT_FDCWD)
359 #ifndef O_SEARCH
360 #define O_SEARCH O_RDONLY
361 #endif
362#else 371#else
363 #define HAVE_AT 0 372 #define HAVE_AT 0
364 static const char *wd_expand (struct etp_tmpbuf *tmpbuf, eio_wd wd, const char *path); 373 static const char *wd_expand (struct etp_tmpbuf *tmpbuf, eio_wd wd, const char *path);
365#endif 374#endif
366 375
1395 return; 1404 return;
1396 } 1405 }
1397 } 1406 }
1398#else 1407#else
1399 #if HAVE_AT 1408 #if HAVE_AT
1400 if (req->wd)
1401 { 1409 {
1402 int fd = openat (WD2FD (req->wd), req->ptr1, O_CLOEXEC | O_SEARCH | O_DIRECTORY); 1410 int fd = openat (WD2FD (req->wd), req->ptr1, O_CLOEXEC | O_SEARCH | O_DIRECTORY | O_NONBLOCK);
1403 1411
1404 if (fd < 0) 1412 if (fd < 0)
1413 return;
1414
1415 dirp = fdopendir (fd);
1416
1417 if (!dirp)
1418 {
1419 silent_close (fd);
1405 return; 1420 return;
1406
1407 dirp = fdopendir (fd);
1408
1409 if (!dirp)
1410 silent_close (fd);
1411 } 1421 }
1412 else 1422 }
1413 dirp = opendir (req->ptr1);
1414 #else 1423 #else
1415 dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1)); 1424 dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1));
1425
1426 if (!dirp)
1427 return;
1416 #endif 1428 #endif
1417
1418 if (!dirp)
1419 return;
1420#endif 1429#endif
1421 1430
1422 if (req->flags & EIO_FLAG_PTR1_FREE) 1431 if (req->flags & EIO_FLAG_PTR1_FREE)
1423 free (req->ptr1); 1432 free (req->ptr1);
1424 1433
1659 1668
1660 if (len < 0) 1669 if (len < 0)
1661 return EIO_INVALID_WD; 1670 return EIO_INVALID_WD;
1662 1671
1663#if HAVE_AT 1672#if HAVE_AT
1664 fd = openat (WD2FD (wd), path, O_CLOEXEC | O_SEARCH | O_DIRECTORY); 1673 fd = openat (WD2FD (wd), path, O_CLOEXEC | O_SEARCH | O_DIRECTORY | O_NONBLOCK);
1665 1674
1666 if (fd < 0) 1675 if (fd < 0)
1667 return EIO_INVALID_WD; 1676 return EIO_INVALID_WD;
1668#endif 1677#endif
1669 1678
1681} 1690}
1682 1691
1683eio_wd 1692eio_wd
1684eio_wd_open_sync (eio_wd wd, const char *path) 1693eio_wd_open_sync (eio_wd wd, const char *path)
1685{ 1694{
1686 struct etp_tmpbuf tmpbuf = { }; 1695 struct etp_tmpbuf tmpbuf = { 0 };
1687 wd = eio__wd_open_sync (&tmpbuf, wd, path); 1696 wd = eio__wd_open_sync (&tmpbuf, wd, path);
1688 free (tmpbuf.ptr); 1697 free (tmpbuf.ptr);
1689 1698
1690 return wd; 1699 return wd;
1691} 1700}
1720/* they forgot these */ 1729/* they forgot these */
1721 1730
1722static int 1731static int
1723eio__truncateat (int dirfd, const char *path, off_t length) 1732eio__truncateat (int dirfd, const char *path, off_t length)
1724{ 1733{
1725 int fd = openat (dirfd, path, O_WRONLY | O_CLOEXEC); 1734 int fd = openat (dirfd, path, O_WRONLY | O_CLOEXEC | O_NONBLOCK);
1726 int res; 1735 int res;
1727 1736
1728 if (fd < 0) 1737 if (fd < 0)
1729 return fd; 1738 return fd;
1730 1739
1734} 1743}
1735 1744
1736static int 1745static int
1737eio__statvfsat (int dirfd, const char *path, struct statvfs *buf) 1746eio__statvfsat (int dirfd, const char *path, struct statvfs *buf)
1738{ 1747{
1739 int fd = openat (dirfd, path, O_SEARCH | O_CLOEXEC); 1748 int fd = openat (dirfd, path, O_SEARCH | O_CLOEXEC | O_NONBLOCK);
1740 int res; 1749 int res;
1741 1750
1742 if (fd < 0) 1751 if (fd < 0)
1743 return fd; 1752 return fd;
1744 1753

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines