mirror of https://github.com/nginx/nginx
parent
f924e6b694
commit
415b1ce1b9
@ -0,0 +1,53 @@ |
||||
|
||||
echo $ngx_n "checking for $ngx_feature ..." $ngx_c |
||||
echo >> $NGX_ERR |
||||
echo "checking for $ngx_feature" >> $NGX_ERR |
||||
|
||||
ngx_found=no |
||||
|
||||
feature=`echo $ngx_feature_name | tr '[a-z]' '[A-Z]'` |
||||
|
||||
cat << END > $NGX_AUTOTEST.c |
||||
|
||||
#include <sys/types.h> |
||||
$NGX_UNISTD_H |
||||
$ngx_feature_inc |
||||
|
||||
int main() { |
||||
$ngx_feature_test; |
||||
return 0; |
||||
} |
||||
|
||||
END |
||||
|
||||
test="$CC_WARN $CC_TEST_FLAGS -o $NGX_AUTOTEST $NGX_AUTOTEST.c \ |
||||
$ngx_feature_libs" |
||||
eval "$test >> $NGX_ERR 2>&1" |
||||
|
||||
if [ -x $NGX_AUTOTEST ]; then |
||||
|
||||
if [ $ngx_feature_run = yes ]; then |
||||
if $NGX_AUTOTEST 2>&1 > /dev/null; then |
||||
echo " found" |
||||
have=HAVE_$feature . auto/have |
||||
ngx_found=yes |
||||
else |
||||
echo " found but is not working" |
||||
fi |
||||
|
||||
else |
||||
echo " found" |
||||
have=HAVE_$feature . auto/have |
||||
ngx_found=yes |
||||
fi |
||||
|
||||
else |
||||
echo " not found" |
||||
echo "---------" >> $NGX_ERR |
||||
cat $NGX_AUTOTEST.c >> $NGX_ERR |
||||
echo "---------" >> $NGX_ERR |
||||
echo $test >> $NGX_ERR |
||||
echo "---------" >> $NGX_ERR |
||||
fi |
||||
|
||||
rm $NGX_AUTOTEST* |
||||
@ -0,0 +1,91 @@ |
||||
|
||||
#include <ngx_config.h> |
||||
#include <ngx_core.h> |
||||
|
||||
|
||||
#if (HAVE_MAP_ANON) |
||||
|
||||
void *ngx_create_shared_memory(size_t size, ngx_log_t *log) |
||||
{ |
||||
void *p; |
||||
|
||||
p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); |
||||
|
||||
if (p == MAP_FAILED) { |
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
||||
"mmap(MAP_ANON|MAP_SHARED, " SIZE_T_FMT ") failed", |
||||
size); |
||||
return NULL; |
||||
} |
||||
|
||||
return p; |
||||
} |
||||
|
||||
#elif (HAVE_MAP_DEVZERO) |
||||
|
||||
void *ngx_create_shared_memory(size_t size, ngx_log_t *log) |
||||
{ |
||||
void *p; |
||||
ngx_fd_t fd; |
||||
|
||||
fd = open("/dev/zero", O_RDWR); |
||||
|
||||
if (fd == -1) { |
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
||||
"open(/dev/zero) failed"); |
||||
return NULL; |
||||
} |
||||
|
||||
p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); |
||||
|
||||
if (p == MAP_FAILED) { |
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
||||
"mmap(/dev/zero, MAP_SHARED, " SIZE_T_FMT ") failed", |
||||
size); |
||||
p = NULL; |
||||
} |
||||
|
||||
if (close(fd) == -1) { |
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "close() failed"); |
||||
} |
||||
|
||||
return p; |
||||
} |
||||
|
||||
#elif (HAVE_SYSVSHM) |
||||
|
||||
#include <sys/ipc.h> |
||||
#include <sys/shm.h> |
||||
|
||||
|
||||
void *ngx_create_shared_memory(size_t size, ngx_log_t *log) |
||||
{ |
||||
int id; |
||||
void *p; |
||||
|
||||
id = shmget(IPC_PRIVATE, size, (SHM_R|SHM_W|IPC_CREAT)); |
||||
|
||||
if (id == -1) { |
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
||||
"shmget(" SIZE_T_FMT ") failed", size); |
||||
return NULL; |
||||
} |
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "shmget id: %d", id); |
||||
|
||||
p = shmat(id, NULL, 0); |
||||
|
||||
if (p == (void *) -1) { |
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "shmat() failed"); |
||||
p = NULL; |
||||
} |
||||
|
||||
if (shmctl(id, IPC_RMID, NULL) == -1) { |
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "shmctl(IPC_RMID) failed"); |
||||
p = NULL; |
||||
} |
||||
|
||||
return p; |
||||
} |
||||
|
||||
#endif |
||||
@ -0,0 +1,12 @@ |
||||
#ifndef _NGX_SHARED_H_INCLUDED_ |
||||
#define _NGX_SHARED_H_INCLUDED_ |
||||
|
||||
|
||||
#include <ngx_config.h> |
||||
#include <ngx_core.h> |
||||
|
||||
|
||||
void *ngx_create_shared_memory(size_t size, ngx_log_t *log); |
||||
|
||||
|
||||
#endif /* _NGX_SHARED_H_INCLUDED_ */ |
||||
@ -0,0 +1,12 @@ |
||||
#ifndef _NGX_SHARED_H_INCLUDED_ |
||||
#define _NGX_SHARED_H_INCLUDED_ |
||||
|
||||
|
||||
#include <ngx_config.h> |
||||
#include <ngx_core.h> |
||||
|
||||
|
||||
void *ngx_create_shared_memory(size_t size, ngx_log_t *log); |
||||
|
||||
|
||||
#endif /* _NGX_SHARED_H_INCLUDED_ */ |
||||
Loading…
Reference in new issue