Back to index

php5  5.3.10
Defines | Functions | Variables
fpm_env.h File Reference
#include "fpm_worker_pool.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define SETPROCTITLE_PREFIX   "php-fpm: "

Functions

int fpm_env_init_child (struct fpm_worker_pool_s *wp)
int fpm_env_init_main ()
void fpm_env_setproctitle (char *title)
int setenv (char *name, char *value, int overwrite)
void clearenv ()

Variables

char ** environ

Define Documentation

#define SETPROCTITLE_PREFIX   "php-fpm: "

Definition at line 10 of file fpm_env.h.


Function Documentation

void clearenv ( )

Definition at line 65 of file fpm_env.c.

{
       char **envp;
       char *s;

       /* this algo is the only one known to me
              that works well on all systems */
       while (*(envp = environ)) {
              char *eq = strchr(*envp, '=');

              s = strdup(*envp);

              if (eq) s[eq - *envp] = '\0';

              unsetenv(s);
              free(s);
       }

}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 138 of file fpm_env.c.

{
       struct key_value_s *kv;
       char *title;
       spprintf(&title, 0, "pool %s", wp->config->name);
       fpm_env_setproctitle(title);
       efree(title);

       clearenv();

       for (kv = wp->config->env; kv; kv = kv->next) {
              setenv(kv->key, kv->value, 1);
       }

       if (wp->user) {
              setenv("USER", wp->user, 1);
       }

       if (wp->home) {
              setenv("HOME", wp->home, 1);
       }

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 197 of file fpm_env.c.

{
       struct fpm_worker_pool_s *wp;
       int i;
       char *first = NULL;
       char *last = NULL;
       char *title;

       for (wp = fpm_worker_all_pools; wp; wp = wp->next) {
              if (0 > fpm_env_conf_wp(wp)) {
                     return -1;
              }
       }
#ifndef HAVE_SETPROCTITLE
#ifdef __linux__
       /*
        * This piece of code has been inspirated from nginx and pureftpd code, whic
        * are under BSD licence.
        *
        * To change the process title in Linux we have to set argv[1] to NULL
        * and to copy the title to the same place where the argv[0] points to.
        * However, argv[0] may be too small to hold a new title.  Fortunately, Linux
        * store argv[] and environ[] one after another.  So we should ensure that is
        * the continuous memory and then we allocate the new memory for environ[]
        * and copy it.  After this we could use the memory starting from argv[0] for
        * our process title.
        */

       for (i = 0; i < fpm_globals.argc; i++) {
              if (first == NULL) {
                     first = fpm_globals.argv[i];
              }
              if (last == NULL || fpm_globals.argv[i] == last + 1) {
                     last = fpm_globals.argv[i] + strlen(fpm_globals.argv[i]);
              }
       }
       if (environ) {
              for (i = 0; environ[i]; i++) {
                     if (first == NULL) {
                            first = environ[i];
                     }
                     if (last == NULL || environ[i] == last + 1) {
                            last = environ[i] + strlen(environ[i]);
                     }
              }
       }
       if (first == NULL || last == NULL) {
              return 0;
       }

       fpm_env_argv_len = last - first;
       fpm_env_argv = fpm_globals.argv;
       if (environ != NULL) {
              char **new_environ;
              unsigned int env_nb = 0U;

              while (environ[env_nb]) {
                     env_nb++;
              }

              if ((new_environ = malloc((1U + env_nb) * sizeof (char *))) == NULL) {
                     return -1;
              }
              new_environ[env_nb] = NULL;
              while (env_nb > 0U) {
                     env_nb--;
                     new_environ[env_nb] = strdup(environ[env_nb]);
              }
              environ = new_environ;
       }
#endif
#endif

       spprintf(&title, 0, "master process (%s)", fpm_globals.config);
       fpm_env_setproctitle(title); 
       efree(title);
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fpm_env_setproctitle ( char *  title)

Definition at line 121 of file fpm_env.c.

{
#ifdef HAVE_SETPROCTITLE
       setproctitle("%s", title);
#else
#ifdef __linux__
       if (fpm_env_argv != NULL && fpm_env_argv_len > strlen(SETPROCTITLE_PREFIX) + 3) {
              memset(fpm_env_argv[0], 0, fpm_env_argv_len);
              strncpy(fpm_env_argv[0], SETPROCTITLE_PREFIX, fpm_env_argv_len - 2);
              strncpy(fpm_env_argv[0] + strlen(SETPROCTITLE_PREFIX), title, fpm_env_argv_len - strlen(SETPROCTITLE_PREFIX) - 2);
              fpm_env_argv[1] = NULL;
       }
#endif
#endif
}

Here is the caller graph for this function:

int setenv ( char *  name,
char *  value,
int  overwrite 
)

Definition at line 44 of file fpm_env.c.

{
       int name_len = strlen(name);
       int value_len = strlen(value);
       char *var = alloca(name_len + 1 + value_len + 1);

       memcpy(var, name, name_len);

       var[name_len] = '=';

       memcpy(var + name_len + 1, value, value_len);

       var[name_len + 1 + value_len] = '\0';

       return putenv(var);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char** environ