iliaa           Mon Feb 17 20:41:06 2003 EDT

  Modified files:              
    /php4/ext/pcntl     config.m4 pcntl.c php_pcntl.h 
  Log:
  Added pcntl_setpriority & pcntl_getpriority(). These functions can be used
  to fetch and alter the priority of a process.
  
  
Index: php4/ext/pcntl/config.m4
diff -u php4/ext/pcntl/config.m4:1.7 php4/ext/pcntl/config.m4:1.8
--- php4/ext/pcntl/config.m4:1.7        Tue Mar 12 11:49:27 2002
+++ php4/ext/pcntl/config.m4    Mon Feb 17 20:41:06 2003
@@ -1,5 +1,5 @@
 dnl
-dnl $Id: config.m4,v 1.7 2002/03/12 16:49:27 sas Exp $
+dnl $Id: config.m4,v 1.8 2003/02/18 01:41:06 iliaa Exp $
 dnl
 
 dnl Process Control (pcntl) extentsion --EXPERIMENTAL--
@@ -13,6 +13,9 @@
   AC_CHECK_FUNCS(fork, [ AC_DEFINE(HAVE_FORK,1,[ ]) ], [ AC_MSG_ERROR(pcntl: fork() 
not supported by this platform) ])
   AC_CHECK_FUNCS(waitpid, [ AC_DEFINE(HAVE_WAITPID,1,[ ]) ], [ AC_MSG_ERROR(pcntl: 
fork() not supported by this platform) ])
   AC_CHECK_FUNCS(sigaction, [ AC_DEFINE(HAVE_SIGACTION,1,[ ]) ], [ 
AC_MSG_ERROR(pcntl: sigaction() not supported by this platform) ])
-  
+
+  PHP_CHECK_FUNC(getpriority)
+  PHP_CHECK_FUNC(setpriority)
+   
   PHP_NEW_EXTENSION(pcntl, pcntl.c php_signal.c, $ext_shared, cli)
 fi
Index: php4/ext/pcntl/pcntl.c
diff -u php4/ext/pcntl/pcntl.c:1.31 php4/ext/pcntl/pcntl.c:1.32
--- php4/ext/pcntl/pcntl.c:1.31 Tue Dec 31 11:07:11 2002
+++ php4/ext/pcntl/pcntl.c      Mon Feb 17 20:41:06 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: pcntl.c,v 1.31 2002/12/31 16:07:11 sebastian Exp $ */
+/* $Id: pcntl.c,v 1.32 2003/02/18 01:41:06 iliaa Exp $ */
 
 #define PCNTL_DEBUG 0
 
@@ -36,6 +36,11 @@
 #include "ext/standard/info.h"
 #include "php_pcntl.h"
 
+#if HAVE_GETPRIORITY || HAVE_SETPRIORITY
+#include <sys/time.h>
+#include <sys/resource.h>
+#endif
+
 ZEND_DECLARE_MODULE_GLOBALS(pcntl)
 
 function_entry pcntl_functions[] = {
@@ -50,6 +55,8 @@
        PHP_FE(pcntl_wstopsig,          NULL)
        PHP_FE(pcntl_exec,                      NULL)
        PHP_FE(pcntl_alarm,                     NULL)
+       PHP_FE(pcntl_getpriority,       NULL)
+       PHP_FE(pcntl_setpriority,       NULL)
        {NULL, NULL, NULL}      
 };
 
@@ -132,6 +139,12 @@
 #endif
        REGISTER_LONG_CONSTANT("SIGSYS",   (long) SIGSYS, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("SIGBABY",  (long) SIGSYS, CONST_CS | CONST_PERSISTENT);
+
+#if HAVE_GETPRIORITY || HAVE_SETPRIORITY
+       REGISTER_LONG_CONSTANT("PRIO_PGRP", PRIO_PGRP, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("PRIO_USER", PRIO_USER, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("PRIO_PROCESS", PRIO_PROCESS, CONST_CS | 
+CONST_PERSISTENT);
+#endif
 }
 
 static void php_pcntl_init_globals(zend_pcntl_globals *pcntl_globals)
@@ -493,6 +506,83 @@
        RETURN_TRUE;
 }
 /* }}} */
+
+#ifdef HAVE_GETPRIORITY
+/* {{{ proto int pcntl_getpriority(int pid, [int process_identifier]])
+   Get the priority of any process */
+PHP_FUNCTION(pcntl_getpriority)
+{
+       long who = PRIO_PROCESS;
+       long pid = getpid();
+       int pri;
+       
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &pid, &who) == 
+FAILURE) {
+               RETURN_FALSE;
+       }
+
+       /* needs to be cleared, since any returned value is valid */ 
+       errno = 0;
+
+       pri = getpriority(who, pid);
+
+       if (errno) {
+               switch (errno) {
+                       case ESRCH:
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%l: No 
+process was located using the given parameters.", errno);
+                               break;
+                       case EINVAL:
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%l: 
+Invalid identifier flag.", errno);
+                               break;
+                       default:
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown 
+error %l has occured.", errno);
+                               break;
+               }
+               RETURN_FALSE;
+       }
+
+       RETURN_LONG(pri);
+}
+/* }}} */
+#endif
+
+#ifdef HAVE_SETPRIORITY
+/* {{{ proto bool pcntl_setpriority(int priority, [int pid, [int process_identifier]])
+   Change the priority of any process */
+PHP_FUNCTION(pcntl_setpriority)
+{
+       long who = PRIO_PROCESS;
+       long pid = getpid();
+       long pri;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|ll", &pri, &pid, &who) 
+== FAILURE) {
+               RETURN_FALSE;
+       }
+
+       if (setpriority(who, pid, pri)) {
+               switch (errno) {
+                       case ESRCH:
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%l: No 
+process was located using the given parameters.", errno);
+                               break;
+                       case EINVAL:
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%l: 
+Invalid identifier flag.", errno);
+                               break;
+                       case EPERM:
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%l: A 
+process was located, but neither its effective nor real user ID matched the effective 
+user ID of the caller.", errno);
+                               break;
+                       case EACCES:
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%l: Only 
+a super user may attempt to increase the process priority.", errno);
+                               break;
+                       default:
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown 
+error %l has occured.", errno);
+                               break;
+               }
+               RETURN_FALSE;
+       }
+       
+       RETURN_TRUE;
+}
+/* }}} */
+#endif
 
 /* Our custom signal handler that calls the appropriate php_function */
 static void pcntl_signal_handler(int signo)
Index: php4/ext/pcntl/php_pcntl.h
diff -u php4/ext/pcntl/php_pcntl.h:1.12 php4/ext/pcntl/php_pcntl.h:1.13
--- php4/ext/pcntl/php_pcntl.h:1.12     Tue Dec 31 11:07:11 2002
+++ php4/ext/pcntl/php_pcntl.h  Mon Feb 17 20:41:06 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_pcntl.h,v 1.12 2002/12/31 16:07:11 sebastian Exp $ */
+/* $Id: php_pcntl.h,v 1.13 2003/02/18 01:41:06 iliaa Exp $ */
 
 #ifndef PHP_PCNTL_H
 #define PHP_PCNTL_H
@@ -50,6 +50,8 @@
 PHP_FUNCTION(pcntl_wstopsig);
 PHP_FUNCTION(pcntl_signal);
 PHP_FUNCTION(pcntl_exec);
+PHP_FUNCTION(pcntl_getpriority);
+PHP_FUNCTION(pcntl_setpriority);
 
 static void pcntl_signal_handler(int);
 static void pcntl_tick_handler();



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to