@@ -1004,23 +1004,56 @@ 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
+ const ssize_t total_size = (ssize_t )(sizeof (* info ) + script -> size + info -> str_size );
1013
+
1011
1014
#ifdef HAVE_SYS_UIO_H
1012
1015
const struct iovec vec [] = {
1013
1016
{ .iov_base = (void * )info , .iov_len = sizeof (* info ) },
1014
1017
{ .iov_base = (void * )buf , .iov_len = script -> size },
1015
1018
{ .iov_base = (void * )ZSTR_VAL (s ), .iov_len = info -> str_size },
1016
1019
};
1017
1020
1018
- return writev (fd , vec , sizeof (vec ) / sizeof (vec [0 ])) == (ssize_t )(sizeof (* info ) + script -> size + info -> str_size );
1021
+ written = writev (fd , vec , sizeof (vec ) / sizeof (vec [0 ]));
1022
+ if (EXPECTED (written == total_size )) {
1023
+ return true;
1024
+ }
1025
+
1026
+ errno = written == -1 ? errno : EAGAIN ;
1027
+ return false;
1019
1028
#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 ;
1029
+ if (UNEXPECTED (ZEND_LONG_MAX < (zend_long )total_size )) {
1030
+ # ifdef EFBIG
1031
+ errno = EFBIG ;
1032
+ # else
1033
+ errno = ERANGE ;
1034
+ # endif
1035
+ return false;
1036
+ }
1037
+
1038
+ written = write (fd , info , sizeof (* info ));
1039
+ if (UNEXPECTED (written != sizeof (* info ))) {
1040
+ errno = written == -1 ? errno : EAGAIN ;
1041
+ return false;
1042
+ }
1043
+
1044
+ written = write (fd , buf , script -> size );
1045
+ if (UNEXPECTED (written != script -> size )) {
1046
+ errno = written == -1 ? errno : EAGAIN ;
1047
+ return false;
1048
+ }
1049
+
1050
+ written = write (fd , ZSTR_VAL (s ), info -> str_size );
1051
+ if (UNEXPECTED (written != info -> str_size )) {
1052
+ errno = written == -1 ? errno : EAGAIN ;
1053
+ return false;
1054
+ }
1055
+
1056
+ return true;
1024
1057
#endif
1025
1058
}
1026
1059
@@ -1095,7 +1128,7 @@ int zend_file_cache_script_store(zend_persistent_script *script, bool in_shm)
1095
1128
#endif
1096
1129
1097
1130
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 );
1131
+ zend_accel_error (ACCEL_LOG_WARNING , "opcache cannot write to file '%s': %s \n" , filename , strerror ( errno ) );
1099
1132
zend_string_release_ex (s , 0 );
1100
1133
close (fd );
1101
1134
efree (mem );
@@ -1107,7 +1140,7 @@ int zend_file_cache_script_store(zend_persistent_script *script, bool in_shm)
1107
1140
zend_string_release_ex (s , 0 );
1108
1141
efree (mem );
1109
1142
if (zend_file_cache_flock (fd , LOCK_UN ) != 0 ) {
1110
- zend_accel_error (ACCEL_LOG_WARNING , "opcache cannot unlock file '%s'\n" , filename );
1143
+ zend_accel_error (ACCEL_LOG_WARNING , "opcache cannot unlock file '%s': %s \n" , filename , strerror ( errno ) );
1111
1144
}
1112
1145
close (fd );
1113
1146
efree (filename );
0 commit comments