Back to index

php5  5.3.10
Classes | Defines | Functions | Variables
php_pcntl.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  php_pcntl_pending_signal

Defines

#define phpext_pcntl_ptr   &pcntl_module_entry
#define PCNTL_G(v)   (pcntl_globals.v)
#define REGISTER_PCNTL_ERRNO_CONSTANT(name)   REGISTER_LONG_CONSTANT("PCNTL_" #name, name, CONST_CS | CONST_PERSISTENT)

Functions

 PHP_MINIT_FUNCTION (pcntl)
 PHP_MSHUTDOWN_FUNCTION (pcntl)
 PHP_RINIT_FUNCTION (pcntl)
 PHP_RSHUTDOWN_FUNCTION (pcntl)
 PHP_MINFO_FUNCTION (pcntl)
 PHP_FUNCTION (pcntl_alarm)
 PHP_FUNCTION (pcntl_fork)
 PHP_FUNCTION (pcntl_waitpid)
 PHP_FUNCTION (pcntl_wait)
 PHP_FUNCTION (pcntl_wifexited)
 PHP_FUNCTION (pcntl_wifstopped)
 PHP_FUNCTION (pcntl_wifsignaled)
 PHP_FUNCTION (pcntl_wexitstatus)
 PHP_FUNCTION (pcntl_wtermsig)
 PHP_FUNCTION (pcntl_wstopsig)
 PHP_FUNCTION (pcntl_signal)
 PHP_FUNCTION (pcntl_signal_dispatch)
 PHP_FUNCTION (pcntl_get_last_error)
 PHP_FUNCTION (pcntl_strerror)
 PHP_FUNCTION (pcntl_exec)

Variables

zend_module_entry pcntl_module_entry
HashTable php_signal_table
int processing_signal_queue
struct php_pcntl_pending_signalhead
struct php_pcntl_pending_signaltail
struct php_pcntl_pending_signalspares
int last_error

Class Documentation

struct php_pcntl_pending_signal

Definition at line 62 of file php_pcntl.h.

Collaboration diagram for php_pcntl_pending_signal:
Class Members
struct php_pcntl_pending_signal * next
long signo

Define Documentation

#define PCNTL_G (   v)    (pcntl_globals.v)

Definition at line 77 of file php_pcntl.h.

Definition at line 25 of file php_pcntl.h.

#define REGISTER_PCNTL_ERRNO_CONSTANT (   name)    REGISTER_LONG_CONSTANT("PCNTL_" #name, name, CONST_CS | CONST_PERSISTENT)

Definition at line 80 of file php_pcntl.h.


Function Documentation

PHP_FUNCTION ( pcntl_alarm  )

Definition at line 557 of file pcntl.c.

{
       long seconds;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &seconds) == FAILURE)
              return;
       
       RETURN_LONG ((long) alarm(seconds));
}

Here is the call graph for this function:

PHP_FUNCTION ( pcntl_fork  )

Definition at line 541 of file pcntl.c.

{
       pid_t id;

       id = fork();
       if (id == -1) {
              PCNTL_G(last_error) = errno;
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error %d", errno);
       }
       
       RETURN_LONG((long) id);
}
PHP_FUNCTION ( pcntl_waitpid  )

Definition at line 570 of file pcntl.c.

{
       long pid, options = 0;
       zval *z_status = NULL;
       int status;
       pid_t child_id;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz|l", &pid, &z_status, &options) == FAILURE)
              return;
       
       convert_to_long_ex(&z_status);

       status = Z_LVAL_P(z_status);

       child_id = waitpid((pid_t) pid, &status, options);

       if (child_id < 0) {
              PCNTL_G(last_error) = errno;
       }

       Z_LVAL_P(z_status) = status;

       RETURN_LONG((long) child_id);
}

Here is the call graph for this function:

PHP_FUNCTION ( pcntl_wait  )

Definition at line 598 of file pcntl.c.

{
       long options = 0;
       zval *z_status = NULL;
       int status;
       pid_t child_id;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &z_status, &options) == FAILURE)
              return;
       
       convert_to_long_ex(&z_status);

       status = Z_LVAL_P(z_status);
#ifdef HAVE_WAIT3
       if(options) {
              child_id = wait3(&status, options, NULL);
       }
       else {
              child_id = wait(&status);
       }
#else
       child_id = wait(&status);
#endif
       if (child_id < 0) {
              PCNTL_G(last_error) = errno;
       }

       Z_LVAL_P(z_status) = status;

       RETURN_LONG((long) child_id);
}

Here is the call graph for this function:

PHP_FUNCTION ( pcntl_wifexited  )

Definition at line 633 of file pcntl.c.

{
#ifdef WIFEXITED
       long status_word;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &status_word) == FAILURE) {
              return;
       }

       if (WIFEXITED(status_word))
              RETURN_TRUE;
#endif
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_FUNCTION ( pcntl_wifstopped  )

Definition at line 651 of file pcntl.c.

{
#ifdef WIFSTOPPED
       long status_word;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &status_word) == FAILURE) {
              return;
       }

       if (WIFSTOPPED(status_word))
              RETURN_TRUE;
#endif
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_FUNCTION ( pcntl_wifsignaled  )

Definition at line 669 of file pcntl.c.

{
#ifdef WIFSIGNALED
       long status_word;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &status_word) == FAILURE) {
              return;
       }

       if (WIFSIGNALED(status_word))
              RETURN_TRUE;
#endif
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_FUNCTION ( pcntl_wexitstatus  )

Definition at line 687 of file pcntl.c.

{
#ifdef WEXITSTATUS
       long status_word;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &status_word) == FAILURE) {
              return;
       }

       RETURN_LONG(WEXITSTATUS(status_word));
#else
       RETURN_FALSE;
#endif
}

Here is the call graph for this function:

PHP_FUNCTION ( pcntl_wtermsig  )

Definition at line 705 of file pcntl.c.

{
#ifdef WTERMSIG
       long status_word;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &status_word) == FAILURE) {
              return;
       }

       RETURN_LONG(WTERMSIG(status_word));
#else
       RETURN_FALSE;
#endif
}

Here is the call graph for this function:

PHP_FUNCTION ( pcntl_wstopsig  )

Definition at line 723 of file pcntl.c.

{
#ifdef WSTOPSIG
       long status_word;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &status_word) == FAILURE) {
              return;
       }

       RETURN_LONG(WSTOPSIG(status_word));
#else
       RETURN_FALSE;
#endif
}

Here is the call graph for this function:

PHP_FUNCTION ( pcntl_signal  )

Definition at line 841 of file pcntl.c.

{
       zval *handle, **dest_handle = NULL;
       char *func_name;
       long signo;
       zend_bool restart_syscalls = 1;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz|b", &signo, &handle, &restart_syscalls) == FAILURE) {
              return;
       }

       if (!PCNTL_G(spares)) {
              /* since calling malloc() from within a signal handler is not portable,
               * pre-allocate a few records for recording signals */
              int i;
              for (i = 0; i < 32; i++) {
                     struct php_pcntl_pending_signal *psig;

                     psig = emalloc(sizeof(*psig));
                     psig->next = PCNTL_G(spares);
                     PCNTL_G(spares) = psig;
              }
       }

       /* Special long value case for SIG_DFL and SIG_IGN */
       if (Z_TYPE_P(handle)==IS_LONG) {
              if (Z_LVAL_P(handle)!= (long) SIG_DFL && Z_LVAL_P(handle) != (long) SIG_IGN) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value for handle argument specified");
              }
              if (php_signal(signo, (Sigfunc *) Z_LVAL_P(handle), (int) restart_syscalls) == SIG_ERR) {
                     PCNTL_G(last_error) = errno;
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error assigning signal");
                     RETURN_FALSE;
              }
              RETURN_TRUE;
       }
       
       if (!zend_is_callable(handle, 0, &func_name TSRMLS_CC)) {
              PCNTL_G(last_error) = EINVAL;
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s is not a callable function name error", func_name);
              efree(func_name);
              RETURN_FALSE;
       }
       efree(func_name);
       
       /* Add the function name to our signal table */
       zend_hash_index_update(&PCNTL_G(php_signal_table), signo, (void **) &handle, sizeof(zval *), (void **) &dest_handle);
       if (dest_handle) zval_add_ref(dest_handle);
       
       if (php_signal4(signo, pcntl_signal_handler, (int) restart_syscalls, 1) == SIG_ERR) {
              PCNTL_G(last_error) = errno;
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error assigning signal");
              RETURN_FALSE;
       }
       RETURN_TRUE;
}

Here is the call graph for this function:

Definition at line 901 of file pcntl.c.

Here is the call graph for this function:

PHP_FUNCTION ( pcntl_get_last_error  )

Definition at line 1177 of file pcntl.c.

PHP_FUNCTION ( pcntl_strerror  )

Definition at line 1185 of file pcntl.c.

{
        long error;

        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &error) == FAILURE) {
                RETURN_FALSE;
        }

        RETURN_STRING(strerror(error), 1);
}

Here is the call graph for this function:

PHP_FUNCTION ( pcntl_exec  )

Definition at line 741 of file pcntl.c.

{
       zval *args = NULL, *envs = NULL;
       zval **element;
       HashTable *args_hash, *envs_hash;
       int argc = 0, argi = 0;
       int envc = 0, envi = 0;
       int return_val = 0;
       char **argv = NULL, **envp = NULL;
       char **current_arg, **pair;
       int pair_length;
       char *key;
       uint key_length;
       char *path;
       int path_len;
       ulong key_num;
              
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|aa", &path, &path_len, &args, &envs) == FAILURE) {
              return;
       }
       
       if (ZEND_NUM_ARGS() > 1) {
              /* Build argumnent list */
              args_hash = HASH_OF(args);
              argc = zend_hash_num_elements(args_hash);
              
              argv = safe_emalloc((argc + 2), sizeof(char *), 0);
              *argv = path;
              for ( zend_hash_internal_pointer_reset(args_hash), current_arg = argv+1; 
                     (argi < argc && (zend_hash_get_current_data(args_hash, (void **) &element) == SUCCESS));
                     (argi++, current_arg++, zend_hash_move_forward(args_hash)) ) {

                     convert_to_string_ex(element);
                     *current_arg = Z_STRVAL_PP(element);
              }
              *(current_arg) = NULL;
       } else {
              argv = emalloc(2 * sizeof(char *));
              *argv = path;
              *(argv+1) = NULL;
       }

       if ( ZEND_NUM_ARGS() == 3 ) {
              /* Build environment pair list */
              envs_hash = HASH_OF(envs);
              envc = zend_hash_num_elements(envs_hash);
              
              envp = safe_emalloc((envc + 1), sizeof(char *), 0);
              for ( zend_hash_internal_pointer_reset(envs_hash), pair = envp; 
                     (envi < envc && (zend_hash_get_current_data(envs_hash, (void **) &element) == SUCCESS));
                     (envi++, pair++, zend_hash_move_forward(envs_hash)) ) {
                     switch (return_val = zend_hash_get_current_key_ex(envs_hash, &key, &key_length, &key_num, 0, NULL)) {
                            case HASH_KEY_IS_LONG:
                                   key = emalloc(101);
                                   snprintf(key, 100, "%ld", key_num);
                                   key_length = strlen(key);
                                   break;
                            case HASH_KEY_NON_EXISTANT:
                                   pair--;
                                   continue;
                     }

                     convert_to_string_ex(element);

                     /* Length of element + equal sign + length of key + null */ 
                     pair_length = Z_STRLEN_PP(element) + key_length + 2;
                     *pair = emalloc(pair_length);
                     strlcpy(*pair, key, key_length); 
                     strlcat(*pair, "=", pair_length);
                     strlcat(*pair, Z_STRVAL_PP(element), pair_length);
                     
                     /* Cleanup */
                     if (return_val == HASH_KEY_IS_LONG) efree(key);
              }
              *(pair) = NULL;

              if (execve(path, argv, envp) == -1) {
                     PCNTL_G(last_error) = errno;
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error has occured: (errno %d) %s", errno, strerror(errno));
              }
       
              /* Cleanup */
              for (pair = envp; *pair != NULL; pair++) efree(*pair);
              efree(envp);
       } else {

              if (execv(path, argv) == -1) {
                     PCNTL_G(last_error) = errno;
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error has occured: (errno %d) %s", errno, strerror(errno));
              }
       }

       efree(argv);
       
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_MINFO_FUNCTION ( pcntl  )

Definition at line 532 of file pcntl.c.

Here is the call graph for this function:

PHP_MINIT_FUNCTION ( pcntl  )

Definition at line 507 of file pcntl.c.

{
       return SUCCESS;
}
PHP_RINIT_FUNCTION ( pcntl  )

Definition at line 491 of file pcntl.c.

Definition at line 512 of file pcntl.c.

{
       struct php_pcntl_pending_signal *sig;

       /* FIXME: if a signal is delivered after this point, things will go pear shaped;
        * need to remove signal handlers */
       zend_hash_destroy(&PCNTL_G(php_signal_table));
       while (PCNTL_G(head)) {
              sig = PCNTL_G(head);
              PCNTL_G(head) = sig->next;
              efree(sig);
       }
       while (PCNTL_G(spares)) {
              sig = PCNTL_G(spares);
              PCNTL_G(spares) = sig->next;
              efree(sig);
       }
       return SUCCESS;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 70 of file php_pcntl.h.

Definition at line 71 of file php_pcntl.h.

zend_module_entry pcntl_module_entry

Definition at line 178 of file pcntl.c.

Definition at line 68 of file php_pcntl.h.

Definition at line 69 of file php_pcntl.h.

Definition at line 70 of file php_pcntl.h.

Definition at line 70 of file php_pcntl.h.