Skip to content

Commit

Permalink
use mkstemp instead of mktemp
Browse files Browse the repository at this point in the history
x
  • Loading branch information
remicollet authored and nikic committed Feb 12, 2019
1 parent 03bf936 commit 998157a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 26 deletions.
4 changes: 2 additions & 2 deletions apc_lock.c
Expand Up @@ -281,8 +281,8 @@ PHP_APCU_API void apc_lock_cleanup() {

PHP_APCU_API zend_bool apc_lock_create(apc_lock_t *lock) {
char lock_path[] = "/tmp/.apc.XXXXXX";
mktemp(lock_path);
*lock = open(lock_path, O_RDWR|O_CREAT, 0666);

*lock = mkstemp(lock_path);
if (*lock > 0) {
unlink(lock_path);
return 1;
Expand Down
24 changes: 0 additions & 24 deletions apc_mmap.c
Expand Up @@ -80,30 +80,6 @@ apc_segment_t apc_mmap(char *file_mask, size_t size)
#ifdef APC_MEMPROTECT
remap = 0; /* cannot remap */
#endif
} else if(strstr(file_mask,".shm")) {
/*
* If the filemask contains .shm we try to do a POSIX-compliant shared memory
* backed mmap which should avoid synchs on some platforms. At least on
* FreeBSD this implies MAP_NOSYNC and on Linux it is equivalent of mmap'ing
* a file in a mounted shmfs. For this to work on Linux you need to make sure
* you actually have shmfs mounted. Also on Linux, make sure the file_mask you
* pass in has a leading / and no other /'s. eg. /apc.shm.XXXXXX
* On FreeBSD these are mapped onto the regular filesystem so you can put whatever
* path you want here.
*/
if(!mktemp(file_mask)) {
zend_error_noreturn(E_CORE_ERROR, "apc_mmap: mktemp on %s failed", file_mask);
}
fd = shm_open(file_mask, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR);
if(fd == -1) {
zend_error_noreturn(E_CORE_ERROR, "apc_mmap: shm_open on %s failed", file_mask);
}
if (ftruncate(fd, size) < 0) {
close(fd);
shm_unlink(file_mask);
zend_error_noreturn(E_CORE_ERROR, "apc_mmap: ftruncate failed");
}
shm_unlink(file_mask);
} else {
/*
* Otherwise we do a normal filesystem mmap
Expand Down

0 comments on commit 998157a

Please sign in to comment.