com php-src: Add posix_setrlimit() FR #5460 3: ext/posix/config.m4 ext/posix/php_posix.h ext/posix/posix.c ext/posix/tests/posix_setrlimit.phpt
| From: | Magnus Määttä | Date: | Wed, 08 Jul 2015 20:12:07 +0000 |
| Subject: | com php-src: Add posix_setrlimit() FR #5460 3: ext/posix/config.m4 ext/posix/php_posix.h ext/posix/posix.c ext/posix/tests/posix_setrlimit.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-87855@lists.php.net to get a copy of this message | ||
Commit: 963d906aff71325f0e3d3620318601c0fb5962c1
Author: Magnus Määttä <magnus@php.net> Wed, 8 Jul 2015 22:12:07 +0200
Parents: 301ee26568af14bafa3938768ac00962bcf2ee66
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=963d906aff71325f0e3d3620318601c0fb5962c1
Log:
Add posix_setrlimit() FR #54603
Bugs:
https://bugs.php.net/54603
Changed paths:
M ext/posix/config.m4
M ext/posix/php_posix.h
M ext/posix/posix.c
A ext/posix/tests/posix_setrlimit.phpt
Diff:
diff --git a/ext/posix/config.m4 b/ext/posix/config.m4
index 82b80ce..9dfa70d 100644
--- a/ext/posix/config.m4
+++ b/ext/posix/config.m4
@@ -11,7 +11,7 @@ if test "$PHP_POSIX" = "yes"; then
AC_CHECK_HEADERS(sys/mkdev.h)
- AC_CHECK_FUNCS(seteuid setegid setsid getsid setpgid getpgid ctermid mkfifo mknod getrlimit
getlogin getgroups makedev initgroups getpwuid_r getgrgid_r)
+ AC_CHECK_FUNCS(seteuid setegid setsid getsid setpgid getpgid ctermid mkfifo mknod setrlimit
getrlimit getlogin getgroups makedev initgroups getpwuid_r getgrgid_r)
AC_MSG_CHECKING([for working ttyname_r() implementation])
AC_TRY_RUN([
diff --git a/ext/posix/php_posix..h b/ext/posix/php_posix.h
index ced4afe..2132c7e 100644
--- a/ext/posix/php_posix.h
+++ b/ext/posix/php_posix.h
@@ -113,6 +113,10 @@ PHP_FUNCTION(posix_getpwuid);
PHP_FUNCTION(posix_getrlimit);
#endif
+#ifdef HAVE_SETRLIMIT
+PHP_FUNCTION(posix_setrlimit);
+#endif
+
#ifdef HAVE_INITGROUPS
PHP_FUNCTION(posix_initgroups);
#endif
diff --git a/ext/posix/posix.c b/ext/posix/posix.c
index 12fb3f3..ec28121 100644
--- a/ext/posix/posix.c
+++ b/ext/posix/posix.c
@@ -199,6 +199,14 @@ ZEND_BEGIN_ARG_INFO(arginfo_posix_getrlimit, 0)
ZEND_END_ARG_INFO()
#endif
+#ifdef HAVE_SETRLIMIT
+ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_setrlimit, 0, 0, 3)
+ ZEND_ARG_INFO(0, resource)
+ ZEND_ARG_INFO(0, softlimit)
+ ZEND_ARG_INFO(0, hardlimit)
+ZEND_END_ARG_INFO()
+#endif
+
ZEND_BEGIN_ARG_INFO(arginfo_posix_get_last_error, 0)
ZEND_END_ARG_INFO()
@@ -293,6 +301,9 @@ const zend_function_entry posix_functions[] = {
#ifdef HAVE_GETRLIMIT
PHP_FE(posix_getrlimit, arginfo_posix_getrlimit)
#endif
+#ifdef HAVE_SETRLIMIT
+ PHP_FE(posix_setrlimit, arginfo_posix_setrlimit)
+#endif
PHP_FE(posix_get_last_error, arginfo_posix_get_last_error)
PHP_FALIAS(posix_errno, posix_get_last_error, arginfo_posix_get_last_error)
@@ -344,7 +355,54 @@ static PHP_MINIT_FUNCTION(posix)
#ifdef S_IFSOCK
REGISTER_LONG_CONSTANT("POSIX_S_IFSOCK", S_IFSOCK, CONST_CS | CONST_PERSISTENT);
#endif
-
+#ifdef RLIMIT_AS
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_AS", RLIMIT_AS, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef RLIMIT_CORE
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_CORE", RLIMIT_CORE, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef RLIMIT_CPU
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_CPU", RLIMIT_CPU, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef RLIMIT_DATA
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_DATA", RLIMIT_DATA, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef RLIMIT_FSIZE
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_FSIZE", RLIMIT_FSIZE, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef RLIMIT_LOCKS
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_LOCKS", RLIMIT_LOCKS, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef RLIMIT_MEMLOCK
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_MEMLOCK", RLIMIT_MEMLOCK, CONST_CS |
CONST_PERSISTENT);
+#endif
+#ifdef RLIMIT_MSGQUEUE
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_MSGQUEUE", RLIMIT_MSGQUEUE, CONST_CS |
CONST_PERSISTENT);
+#endif
+#ifdef RLIMIT_NICE
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_NICE", RLIMIT_NICE, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef RLIMIT_NOFILE
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_NOFILE", RLIMIT_NOFILE, CONST_CS |
CONST_PERSISTENT);
+#endif
+#ifdef RLIMIT_NPROC
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_NPROC", RLIMIT_NPROC, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef RLIMIT_RSS
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_RSS", RLIMIT_RSS, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef RLIMIT_RTPRIO
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_RTPRIO", RLIMIT_RTPRIO, CONST_CS |
CONST_PERSISTENT);
+#endif
+#ifdef RLIMIT_RTTIME
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_RTTIME", RLIMIT_RTTIME, CONST_CS |
CONST_PERSISTENT);
+#endif
+#ifdef RLIMIT_SIGPENDING
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_SIGPENDING", RLIMIT_SIGPENDING, CONST_CS |
CONST_PERSISTENT);
+#endif
+#ifdef RLIMIT_STACK
+ REGISTER_LONG_CONSTANT("POSIX_RLIMIT_STACK", RLIMIT_STACK, CONST_CS | CONST_PERSISTENT);
+#endif
return SUCCESS;
}
/* }}} */
@@ -1322,6 +1380,44 @@ PHP_FUNCTION(posix_getrlimit)
#endif /* HAVE_GETRLIMIT */
+#ifdef HAVE_SETRLIMIT
+/* {{{ proto bool posix_setrlimit(int resource, string softlimit, string hardlimit)
+ Set system resource consumption limits (POSIX.1-2001) */
+PHP_FUNCTION(posix_setrlimit)
+{
+ struct rlimit rl;
+ char *cur, *max;
+ size_t cur_len, max_len;
+ int res;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "lss", &res, &cur, &cur_len,
&max, &max_len) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ if (!strcasecmp(cur, "unlimited")) {
+ rl.rlim_cur = RLIM_INFINITY;
+ } else {
+ rl.rlim_cur = zend_atol(cur, cur_len);
+ }
+
+ if (!strcasecmp(max, "unlimited")) {
+ rl.rlim_max = RLIM_INFINITY;
+ } else {
+ rl.rlim_max = zend_atol(max, max_len);
+ }
+
+ if (setrlimit(res, &rl) == -1) {
+ POSIX_G(last_error) = errno;
+ RETURN_FALSE;
+ }
+
+ RETURN_TRUE;
+}
+/* }}} */
+
+#endif /* HAVE_SETRLIMIT */
+
+
/* {{{ proto int posix_get_last_error(void)
Retrieve the error number set by the last posix function which failed. */
PHP_FUNCTION(posix_get_last_error)
diff --git a/ext/posix/tests/posix_setrlimit.phpt b/ext/posix/tests/posix_setrlimit.phpt
new file mode 100644
index 0000000..4806fcf
--- /dev/null
+++ b/ext/posix/tests/posix_setrlimit.phpt
@@ -0,0 +1,18 @@
+--TEST--
+posix_setrlimit(): Basic tests
+--SKIPIF--
+<?php
+if (!extension_loaded('posix')) die('skip - POSIX extension not loaded');
+if (!function_exists('posix_setrlimit')) die('skip posix_setrlimit() not
found');
+?>
+--FILE--
+<?php
+
+var_dump(posix_setrlimit(POSIX_RLIMIT_NOFILE, 128, 128));
+var_dump(posix_setrlimit(POSIX_RLIMIT_NOFILE, 129, 128));
+
+?>
+--EXPECTF--
+bool(true)
+bool(false)
+