Lines Matching refs:data

74 static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, const char *key)  in ps_files_path_create()  argument
82 if (!data || key_len <= data->dirdepth || in ps_files_path_create()
83 buflen < (strlen(data->basedir) + 2 * data->dirdepth + key_len + 5 + sizeof(FILE_PREFIX))) { in ps_files_path_create()
88 memcpy(buf, data->basedir, data->basedir_len); in ps_files_path_create()
89 n = data->basedir_len; in ps_files_path_create()
91 for (i = 0; i < (int)data->dirdepth; i++) { in ps_files_path_create()
108 static void ps_files_close(ps_files *data) in ps_files_close() argument
110 if (data->fd != -1) { in ps_files_close()
114 flock(data->fd, LOCK_UN); in ps_files_close()
116 close(data->fd); in ps_files_close()
117 data->fd = -1; in ps_files_close()
121 static void ps_files_open(ps_files *data, const char *key TSRMLS_DC) in ps_files_open() argument
127 if (data->fd < 0 || !data->lastkey || strcmp(key, data->lastkey)) { in ps_files_open()
128 if (data->lastkey) { in ps_files_open()
129 efree(data->lastkey); in ps_files_open()
130 data->lastkey = NULL; in ps_files_open()
133 ps_files_close(data); in ps_files_open()
140 if (!ps_files_path_create(buf, sizeof(buf), data, key)) { in ps_files_open()
145 data->lastkey = estrdup(key); in ps_files_open()
149 data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY | O_NOFOLLOW, data->filemode); in ps_files_open()
156 data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY, data->filemode); in ps_files_open()
159 if (data->fd != -1) { in ps_files_open()
163 …if (fstat(data->fd, &sbuf) || (sbuf.st_uid != 0 && sbuf.st_uid != getuid() && sbuf.st_uid != geteu… in ps_files_open()
164 close(data->fd); in ps_files_open()
165 data->fd = -1; in ps_files_open()
171 ret = flock(data->fd, LOCK_EX); in ps_files_open()
178 if (fcntl(data->fd, F_SETFD, FD_CLOEXEC)) { in ps_files_open()
179 …L TSRMLS_CC, E_WARNING, "fcntl(%d, F_SETFD, FD_CLOEXEC) failed: %s (%d)", data->fd, strerror(errno… in ps_files_open()
241 static int ps_files_key_exists(ps_files *data, const char *key TSRMLS_DC) in ps_files_key_exists() argument
246 if (!key || !ps_files_path_create(buf, sizeof(buf), data, key)) { in ps_files_key_exists()
256 #define PS_FILES_DATA ps_files *data = PS_GET_MOD_DATA()
260 ps_files *data; in PS_OPEN_FUNC() local
306 data = ecalloc(1, sizeof(*data)); in PS_OPEN_FUNC()
308 data->fd = -1; in PS_OPEN_FUNC()
309 data->dirdepth = dirdepth; in PS_OPEN_FUNC()
310 data->filemode = filemode; in PS_OPEN_FUNC()
311 data->basedir_len = strlen(save_path); in PS_OPEN_FUNC()
312 data->basedir = estrndup(save_path, data->basedir_len); in PS_OPEN_FUNC()
317 PS_SET_MOD_DATA(data); in PS_OPEN_FUNC()
326 ps_files_close(data); in PS_CLOSE_FUNC()
328 if (data->lastkey) { in PS_CLOSE_FUNC()
329 efree(data->lastkey); in PS_CLOSE_FUNC()
330 data->lastkey = NULL; in PS_CLOSE_FUNC()
333 efree(data->basedir); in PS_CLOSE_FUNC()
334 efree(data); in PS_CLOSE_FUNC()
348 ps_files_key_exists(data, key TSRMLS_CC) == FAILURE) { in PS_READ_FUNC()
354 PS(id) = PS(mod)->s_create_sid((void **)&data, NULL TSRMLS_CC); in PS_READ_FUNC()
369 ps_files_open(data, PS(id) TSRMLS_CC); in PS_READ_FUNC()
370 if (data->fd < 0) { in PS_READ_FUNC()
374 if (fstat(data->fd, &sbuf)) { in PS_READ_FUNC()
378 data->st_size = *vallen = sbuf.st_size; in PS_READ_FUNC()
388 n = pread(data->fd, *val, sbuf.st_size, 0); in PS_READ_FUNC()
390 lseek(data->fd, 0, SEEK_SET); in PS_READ_FUNC()
391 n = read(data->fd, *val, sbuf.st_size); in PS_READ_FUNC()
412 ps_files_open(data, key TSRMLS_CC); in PS_WRITE_FUNC()
413 if (data->fd < 0) { in PS_WRITE_FUNC()
419 if (vallen < (int)data->st_size) { in PS_WRITE_FUNC()
420 php_ignore_value(ftruncate(data->fd, 0)); in PS_WRITE_FUNC()
424 n = pwrite(data->fd, val, vallen, 0); in PS_WRITE_FUNC()
426 lseek(data->fd, 0, SEEK_SET); in PS_WRITE_FUNC()
427 n = write(data->fd, val, vallen); in PS_WRITE_FUNC()
447 if (!ps_files_path_create(buf, sizeof(buf), data, key)) { in PS_DESTROY_FUNC()
451 if (data->fd != -1) { in PS_DESTROY_FUNC()
452 ps_files_close(data); in PS_DESTROY_FUNC()
474 if (data->dirdepth == 0) { in PS_GC_FUNC()
475 *nrdels = ps_files_cleanup_dir(data->basedir, maxlifetime TSRMLS_CC); in PS_GC_FUNC()
488 sid = php_session_create_id((void **)&data, newlen TSRMLS_CC); in PS_CREATE_SID_FUNC()
490 if (data && ps_files_key_exists(data, sid TSRMLS_CC) == SUCCESS) { in PS_CREATE_SID_FUNC()