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

Comparing libeio/eio.c (file contents):
Revision 1.143 by root, Sat Dec 3 16:33:46 2016 UTC vs.
Revision 1.144 by root, Tue Dec 27 09:58:44 2016 UTC

316# define NAME_MAX 4096 316# define NAME_MAX 4096
317#endif 317#endif
318 318
319/* used for readlink etc. */ 319/* used for readlink etc. */
320#ifndef PATH_MAX 320#ifndef PATH_MAX
321# define PATH_MAX 4096 321# define PATH_MAX 0
322#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)
323 329
324/* buffer size for various temporary buffers */ 330/* buffer size for various temporary buffers */
325#define EIO_BUFSIZE 65536 331#define EIO_BUFSIZE 65536
326 332
327#define dBUF \ 333#define dBUF \
974 980
975 errno = ENOENT; 981 errno = ENOENT;
976 if (!*rel) 982 if (!*rel)
977 return -1; 983 return -1;
978 984
979 res = etp_tmpbuf_get (tmpbuf, PATH_MAX * 3); 985 res = etp_tmpbuf_get (tmpbuf, EIO_PATH_MAX * 3);
980#ifdef _WIN32 986#ifdef _WIN32
981 if (_access (rel, 4) != 0) 987 if (_access (rel, 4) != 0)
982 return -1; 988 return -1;
983 989
984 symlinks = GetFullPathName (rel, PATH_MAX * 3, res, 0); 990 symlinks = GetFullPathName (rel, EIO_PATH_MAX * 3, res, 0);
985 991
986 errno = ENAMETOOLONG; 992 errno = ENAMETOOLONG;
987 if (symlinks >= PATH_MAX * 3) 993 if (symlinks >= EIO_PATH_MAX * 3)
988 return -1; 994 return -1;
989 995
990 errno = EIO; 996 errno = EIO;
991 if (symlinks <= 0) 997 if (symlinks <= 0)
992 return -1; 998 return -1;
993 999
994 return symlinks; 1000 return symlinks;
995 1001
996#else 1002#else
997 tmp1 = res + PATH_MAX; 1003 tmp1 = res + EIO_PATH_MAX;
998 tmp2 = tmp1 + PATH_MAX; 1004 tmp2 = tmp1 + EIO_PATH_MAX;
999 1005
1000#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 */
1001#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME) 1007#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME)
1002 /* on linux we may be able to ask the kernel */ 1008 /* on linux we may be able to ask the kernel */
1003 { 1009 {
1004 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);
1005 1011
1006 if (fd >= 0) 1012 if (fd >= 0)
1007 { 1013 {
1008 sprintf (tmp1, "/proc/self/fd/%d", fd); 1014 sprintf (tmp1, "/proc/self/fd/%d", fd);
1009 req->result = readlink (tmp1, res, PATH_MAX); 1015 req->result = readlink (tmp1, res, EIO_PATH_MAX);
1010 /* 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 */
1011 close (fd); 1017 close (fd);
1012 1018
1013 if (req->result > 0) 1019 if (req->result > 0)
1014 goto done; 1020 goto done;
1027 if (wd == EIO_INVALID_WD) 1033 if (wd == EIO_INVALID_WD)
1028 return -1; 1034 return -1;
1029 1035
1030 if (wd == EIO_CWD) 1036 if (wd == EIO_CWD)
1031 { 1037 {
1032 if (!getcwd (res, PATH_MAX)) 1038 if (!getcwd (res, EIO_PATH_MAX))
1033 return -1; 1039 return -1;
1034 1040
1035 len = strlen (res); 1041 len = strlen (res);
1036 } 1042 }
1037 else 1043 else
1084 1090
1085 /* zero-terminate, for readlink */ 1091 /* zero-terminate, for readlink */
1086 res [len + 1] = 0; 1092 res [len + 1] = 0;
1087 1093
1088 /* now check if it's a symlink */ 1094 /* now check if it's a symlink */
1089 linklen = readlink (tmpbuf->ptr, tmp1, PATH_MAX); 1095 linklen = readlink (tmpbuf->ptr, tmp1, EIO_PATH_MAX);
1090 1096
1091 if (linklen < 0) 1097 if (linklen < 0)
1092 { 1098 {
1093 if (errno != EINVAL) 1099 if (errno != EINVAL)
1094 return -1; 1100 return -1;
1100 { 1106 {
1101 /* yay, it was a symlink - build new path in tmp2 */ 1107 /* yay, it was a symlink - build new path in tmp2 */
1102 int rellen = strlen (rel); 1108 int rellen = strlen (rel);
1103 1109
1104 errno = ENAMETOOLONG; 1110 errno = ENAMETOOLONG;
1105 if (linklen + 1 + rellen >= PATH_MAX) 1111 if (linklen + 1 + rellen >= EIO_PATH_MAX) /* also catch linklen >= EIO_PATH_MAX */
1106 return -1; 1112 return -1;
1107 1113
1108 errno = ELOOP; 1114 errno = ELOOP;
1109 if (!--symlinks) 1115 if (!--symlinks)
1110 return -1; 1116 return -1;
1843 ? rename (req->wd->str, req->ptr2) 1849 ? rename (req->wd->str, req->ptr2)
1844 : 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;
1845 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;
1846 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;
1847 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;
1848 case EIO_READLINK: ALLOC (PATH_MAX);
1849 req->result = readlinkat (dirfd, req->ptr1, req->ptr2, PATH_MAX); break;
1850 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); 1854 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
1851 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;
1852 case EIO_UTIME: 1864 case EIO_UTIME:
1853 case EIO_FUTIME: 1865 case EIO_FUTIME:
1854 { 1866 {
1855 struct timespec ts[2]; 1867 struct timespec ts[2];
1856 struct timespec *times; 1868 struct timespec *times;
1889 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;
1890 case EIO_RENAME: req->result = rename (path , req->ptr2); break; 1902 case EIO_RENAME: req->result = rename (path , req->ptr2); break;
1891 case EIO_LINK: req->result = link (path , req->ptr2); break; 1903 case EIO_LINK: req->result = link (path , req->ptr2); break;
1892 case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break; 1904 case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break;
1893 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;
1894 case EIO_READLINK: ALLOC (PATH_MAX);
1895 req->result = readlink (path, req->ptr2, PATH_MAX); break;
1896 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); 1906 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
1897 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;
1898 1916
1899 case EIO_UTIME: 1917 case EIO_UTIME:
1900 case EIO_FUTIME: 1918 case EIO_FUTIME:
1901 { 1919 {
1902 struct timeval tv[2]; 1920 struct timeval tv[2];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines