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

Comparing libeio/eio.c (file contents):
Revision 1.141 by root, Tue Feb 23 19:47:44 2016 UTC vs.
Revision 1.144 by root, Tue Dec 27 09:58:44 2016 UTC

42#endif 42#endif
43 43
44#include "eio.h" 44#include "eio.h"
45#include "ecb.h" 45#include "ecb.h"
46 46
47#ifdef EIO_STACKSIZE
48# define X_STACKSIZE EIO_STACKSIZE
49#endif
50#include "xthread.h"
51
52#include <errno.h> 47#include <errno.h>
53#include <stddef.h> 48#include <stddef.h>
54#include <stdlib.h> 49#include <stdlib.h>
55#include <string.h> 50#include <string.h>
56#include <errno.h> 51#include <errno.h>
206 /* we could even stat and see if it exists */ 201 /* we could even stat and see if it exists */
207 static int 202 static int
208 symlink (const char *old, const char *neu) 203 symlink (const char *old, const char *neu)
209 { 204 {
210 #if WINVER >= 0x0600 205 #if WINVER >= 0x0600
206 int flags;
207
208 /* This tries out all combinations of SYMBOLIC_LINK_FLAG_DIRECTORY
209 * and SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE,
210 * with directory first.
211 */
212 for (flags = 3; flags >= 0; --flags)
211 if (CreateSymbolicLink (neu, old, 1)) 213 if (CreateSymbolicLink (neu, old, flags))
212 return 0; 214 return 0;
213
214 if (CreateSymbolicLink (neu, old, 0))
215 return 0;
216 #endif 215 #endif
217 216
218 return EIO_ERRNO (ENOENT, -1); 217 return EIO_ERRNO (ENOENT, -1);
219 } 218 }
220 219
283# include <utime.h> 282# include <utime.h>
284#endif 283#endif
285 284
286#if HAVE_SYS_SYSCALL_H 285#if HAVE_SYS_SYSCALL_H
287# include <sys/syscall.h> 286# include <sys/syscall.h>
288#endif
289
290#if HAVE_SYS_PRCTL_H
291# include <sys/prctl.h>
292#endif 287#endif
293 288
294#if HAVE_SENDFILE 289#if HAVE_SENDFILE
295# if __linux 290# if __linux
296# include <sys/sendfile.h> 291# include <sys/sendfile.h>
321# define NAME_MAX 4096 316# define NAME_MAX 4096
322#endif 317#endif
323 318
324/* used for readlink etc. */ 319/* used for readlink etc. */
325#ifndef PATH_MAX 320#ifndef PATH_MAX
326# define PATH_MAX 4096 321# define PATH_MAX 0
327#endif 322#endif
323
324#ifndef EIO_PATH_MIN
325# define EIO_PATH_MIN 8160
326#endif
327
328#define EIO_PATH_MAX (PATH_MAX <= EIO_PATH_MIN ? EIO_PATH_MIN : PATH_MAX)
328 329
329/* buffer size for various temporary buffers */ 330/* buffer size for various temporary buffers */
330#define EIO_BUFSIZE 65536 331#define EIO_BUFSIZE 65536
331 332
332#define dBUF \ 333#define dBUF \
979 980
980 errno = ENOENT; 981 errno = ENOENT;
981 if (!*rel) 982 if (!*rel)
982 return -1; 983 return -1;
983 984
984 res = etp_tmpbuf_get (tmpbuf, PATH_MAX * 3); 985 res = etp_tmpbuf_get (tmpbuf, EIO_PATH_MAX * 3);
985#ifdef _WIN32 986#ifdef _WIN32
986 if (_access (rel, 4) != 0) 987 if (_access (rel, 4) != 0)
987 return -1; 988 return -1;
988 989
989 symlinks = GetFullPathName (rel, PATH_MAX * 3, res, 0); 990 symlinks = GetFullPathName (rel, EIO_PATH_MAX * 3, res, 0);
990 991
991 errno = ENAMETOOLONG; 992 errno = ENAMETOOLONG;
992 if (symlinks >= PATH_MAX * 3) 993 if (symlinks >= EIO_PATH_MAX * 3)
993 return -1; 994 return -1;
994 995
995 errno = EIO; 996 errno = EIO;
996 if (symlinks <= 0) 997 if (symlinks <= 0)
997 return -1; 998 return -1;
998 999
999 return symlinks; 1000 return symlinks;
1000 1001
1001#else 1002#else
1002 tmp1 = res + PATH_MAX; 1003 tmp1 = res + EIO_PATH_MAX;
1003 tmp2 = tmp1 + PATH_MAX; 1004 tmp2 = tmp1 + EIO_PATH_MAX;
1004 1005
1005#if 0 /* disabled, the musl way to do things is just too racy */ 1006#if 0 /* disabled, the musl way to do things is just too racy */
1006#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME) 1007#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME)
1007 /* on linux we may be able to ask the kernel */ 1008 /* on linux we may be able to ask the kernel */
1008 { 1009 {
1009 int fd = open (rel, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOATIME); 1010 int fd = open (rel, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOATIME);
1010 1011
1011 if (fd >= 0) 1012 if (fd >= 0)
1012 { 1013 {
1013 sprintf (tmp1, "/proc/self/fd/%d", fd); 1014 sprintf (tmp1, "/proc/self/fd/%d", fd);
1014 req->result = readlink (tmp1, res, PATH_MAX); 1015 req->result = readlink (tmp1, res, EIO_PATH_MAX);
1015 /* here we should probably stat the open file and the disk file, to make sure they still match */ 1016 /* here we should probably stat the open file and the disk file, to make sure they still match */
1016 close (fd); 1017 close (fd);
1017 1018
1018 if (req->result > 0) 1019 if (req->result > 0)
1019 goto done; 1020 goto done;
1032 if (wd == EIO_INVALID_WD) 1033 if (wd == EIO_INVALID_WD)
1033 return -1; 1034 return -1;
1034 1035
1035 if (wd == EIO_CWD) 1036 if (wd == EIO_CWD)
1036 { 1037 {
1037 if (!getcwd (res, PATH_MAX)) 1038 if (!getcwd (res, EIO_PATH_MAX))
1038 return -1; 1039 return -1;
1039 1040
1040 len = strlen (res); 1041 len = strlen (res);
1041 } 1042 }
1042 else 1043 else
1089 1090
1090 /* zero-terminate, for readlink */ 1091 /* zero-terminate, for readlink */
1091 res [len + 1] = 0; 1092 res [len + 1] = 0;
1092 1093
1093 /* now check if it's a symlink */ 1094 /* now check if it's a symlink */
1094 linklen = readlink (tmpbuf->ptr, tmp1, PATH_MAX); 1095 linklen = readlink (tmpbuf->ptr, tmp1, EIO_PATH_MAX);
1095 1096
1096 if (linklen < 0) 1097 if (linklen < 0)
1097 { 1098 {
1098 if (errno != EINVAL) 1099 if (errno != EINVAL)
1099 return -1; 1100 return -1;
1105 { 1106 {
1106 /* yay, it was a symlink - build new path in tmp2 */ 1107 /* yay, it was a symlink - build new path in tmp2 */
1107 int rellen = strlen (rel); 1108 int rellen = strlen (rel);
1108 1109
1109 errno = ENAMETOOLONG; 1110 errno = ENAMETOOLONG;
1110 if (linklen + 1 + rellen >= PATH_MAX) 1111 if (linklen + 1 + rellen >= EIO_PATH_MAX) /* also catch linklen >= EIO_PATH_MAX */
1111 return -1; 1112 return -1;
1112 1113
1113 errno = ELOOP; 1114 errno = ELOOP;
1114 if (!--symlinks) 1115 if (!--symlinks)
1115 return -1; 1116 return -1;
1848 ? rename (req->wd->str, req->ptr2) 1849 ? rename (req->wd->str, req->ptr2)
1849 : renameat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2); break; 1850 : renameat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2); break;
1850 case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2, 0); break; 1851 case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2, 0); break;
1851 case EIO_SYMLINK: req->result = symlinkat (req->ptr1, dirfd, req->ptr2); break; 1852 case EIO_SYMLINK: req->result = symlinkat (req->ptr1, dirfd, req->ptr2); break;
1852 case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; 1853 case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break;
1853 case EIO_READLINK: ALLOC (PATH_MAX);
1854 req->result = readlinkat (dirfd, req->ptr1, req->ptr2, PATH_MAX); break;
1855 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); 1854 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
1856 req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; 1855 req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break;
1856 case EIO_READLINK: ALLOC (EIO_PATH_MAX);
1857 req->result = readlinkat (dirfd, req->ptr1, req->ptr2, EIO_PATH_MAX);
1858 if (req->result == EIO_PATH_MAX)
1859 {
1860 req->result = -1;
1861 errno = ENAMETOOLONG;
1862 }
1863 break;
1857 case EIO_UTIME: 1864 case EIO_UTIME:
1858 case EIO_FUTIME: 1865 case EIO_FUTIME:
1859 { 1866 {
1860 struct timespec ts[2]; 1867 struct timespec ts[2];
1861 struct timespec *times; 1868 struct timespec *times;
1894 case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break; 1901 case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break;
1895 case EIO_RENAME: req->result = rename (path , req->ptr2); break; 1902 case EIO_RENAME: req->result = rename (path , req->ptr2); break;
1896 case EIO_LINK: req->result = link (path , req->ptr2); break; 1903 case EIO_LINK: req->result = link (path , req->ptr2); break;
1897 case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break; 1904 case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break;
1898 case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break; 1905 case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break;
1899 case EIO_READLINK: ALLOC (PATH_MAX);
1900 req->result = readlink (path, req->ptr2, PATH_MAX); break;
1901 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); 1906 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
1902 req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break; 1907 req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break;
1908 case EIO_READLINK: ALLOC (EIO_PATH_MAX);
1909 req->result = readlink (path, req->ptr2, EIO_PATH_MAX);
1910 if (req->result == EIO_PATH_MAX)
1911 {
1912 req->result = -1;
1913 errno = ENAMETOOLONG;
1914 }
1915 break;
1903 1916
1904 case EIO_UTIME: 1917 case EIO_UTIME:
1905 case EIO_FUTIME: 1918 case EIO_FUTIME:
1906 { 1919 {
1907 struct timeval tv[2]; 1920 struct timeval tv[2];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines