@@ -1004,23 +1004,55 @@ static char *zend_file_cache_get_bin_file_path(zend_string *script_path)
1004
1004
/**
1005
1005
* Helper function for zend_file_cache_script_store().
1006
1006
*
1007
- * @return true on success, false on error
1007
+ * @return true on success, false on error and errno is set to indicate the cause of the error
1008
1008
*/
1009
1009
static bool zend_file_cache_script_write (int fd , const zend_persistent_script * script , const zend_file_cache_metainfo * info , const void * buf , const zend_string * s )
1010
1010
{
1011
+ ssize_t written ;
1012
+
1011
1013
#ifdef HAVE_SYS_UIO_H
1012
1014
const struct iovec vec [] = {
1013
1015
{ .iov_base = (void * )info , .iov_len = sizeof (* info ) },
1014
1016
{ .iov_base = (void * )buf , .iov_len = script -> size },
1015
1017
{ .iov_base = (void * )ZSTR_VAL (s ), .iov_len = info -> str_size },
1016
1018
};
1017
1019
1018
- return writev (fd , vec , sizeof (vec ) / sizeof (vec [0 ])) == (ssize_t )(sizeof (* info ) + script -> size + info -> str_size );
1020
+ written = writev (fd , vec , sizeof (vec ) / sizeof (vec [0 ]));
1021
+ if (EXPECTED (written == (ssize_t )(sizeof (* info ) + script -> size + info -> str_size ))) {
1022
+ return true;
1023
+ }
1024
+
1025
+ errno = written == -1 ? errno : EAGAIN ;
1026
+ return false;
1019
1027
#else
1020
- return ZEND_LONG_MAX >= (zend_long )(sizeof (* info ) + script -> size + info -> str_size ) &&
1021
- write (fd , info , sizeof (* info )) == sizeof (* info ) &&
1022
- write (fd , buf , script -> size ) == script -> size &&
1023
- write (fd , ZSTR_VAL (s ), info -> str_size ) == info -> str_size ;
1028
+ if (UNEXPECTED (ZEND_LONG_MAX >= (zend_long )(sizeof (* info ) + script -> size + info -> str_size ))) {
1029
+ # ifdef EFBIG
1030
+ errno = EFBIG ;
1031
+ # else
1032
+ errno = ERANGE ;
1033
+ # endif
1034
+ return false;
1035
+ }
1036
+
1037
+ written = write (fd , info , sizeof (* info ));
1038
+ if (UNEXPECTED (written != sizeof (* info ))) {
1039
+ errno = written == -1 ? errno : EAGAIN ;
1040
+ return false;
1041
+ }
1042
+
1043
+ written = write (fd , buf , script -> size );
1044
+ if (UNEXPECTED (written != script -> size )) {
1045
+ errno = written == -1 ? errno : EAGAIN ;
1046
+ return false;
1047
+ }
1048
+
1049
+ written = write (fd , ZSTR_VAL (s ), info -> str_size );
1050
+ if (UNEXPECTED (writen != info -> str_size )) {
1051
+ errno = written == -1 ? errno : EAGAIN ;
1052
+ return false;
1053
+ }
1054
+
1055
+ return true;
1024
1056
#endif
1025
1057
}
1026
1058
@@ -1095,7 +1127,7 @@ int zend_file_cache_script_store(zend_persistent_script *script, bool in_shm)
1095
1127
#endif
1096
1128
1097
1129
if (!zend_file_cache_script_write (fd , script , & info , buf , s )) {
1098
- zend_accel_error (ACCEL_LOG_WARNING , "opcache cannot write to file '%s'\n" , filename );
1130
+ zend_accel_error (ACCEL_LOG_WARNING , "opcache cannot write to file '%s': %s \n" , filename , strerror ( errno ) );
1099
1131
zend_string_release_ex (s , 0 );
1100
1132
close (fd );
1101
1133
efree (mem );
@@ -1107,7 +1139,7 @@ int zend_file_cache_script_store(zend_persistent_script *script, bool in_shm)
1107
1139
zend_string_release_ex (s , 0 );
1108
1140
efree (mem );
1109
1141
if (zend_file_cache_flock (fd , LOCK_UN ) != 0 ) {
1110
- zend_accel_error (ACCEL_LOG_WARNING , "opcache cannot unlock file '%s'\n" , filename );
1142
+ zend_accel_error (ACCEL_LOG_WARNING , "opcache cannot unlock file '%s': %s \n" , filename , strerror ( errno ) );
1111
1143
}
1112
1144
close (fd );
1113
1145
efree (filename );
0 commit comments