コード例 #1
0
ファイル: stats.c プロジェクト: 1FENQI/tinyproxy
/*
 * Initialize the statistics information to zero.
 */
void init_stats (void)
{
        stats = (struct stat_s *) malloc_shared_memory (sizeof (struct stat_s));
        if (stats == MAP_FAILED)
                return;

        memset (stats, 0, sizeof (struct stat_s));
}
コード例 #2
0
ファイル: heap.c プロジェクト: tenchman/tinyproxy-ex
/*
 * Allocate a block of memory from the "shared" region an initialize it to
 * zero.
 */
void *calloc_shared_memory(size_t nmemb, size_t size)
{
  void *ptr;
  long length;

  assert(nmemb > 0);
  assert(size > 0);

  length = nmemb * size;

  ptr = malloc_shared_memory(length);
  if (ptr == MAP_FAILED)
    return ptr;

  memset(ptr, 0, length);

  return ptr;
}
コード例 #3
0
ファイル: child.c プロジェクト: pdaian/somaroute
/*
 * Create a pool of children to handle incoming connections
 */
short int child_pool_create (void)
{
        unsigned int i;

        /*
         * Make sure the number of MaxClients is not zero, since this
         * variable determines the size of the array created for children
         * later on.
         */
        if (child_config.maxclients == 0) {
                log_message (LOG_ERR,
                             "child_pool_create: \"MaxClients\" must be "
                             "greater than zero.");
                return -1;
        }
        if (child_config.startservers == 0) {
                log_message (LOG_ERR,
                             "child_pool_create: \"StartServers\" must be "
                             "greater than zero.");
                return -1;
        }

        child_ptr =
            (struct child_s *) calloc_shared_memory (child_config.maxclients,
                                                     sizeof (struct child_s));
        if (!child_ptr) {
                log_message (LOG_ERR,
                             "Could not allocate memory for children.");
                return -1;
        }

        servers_waiting =
            (unsigned int *) malloc_shared_memory (sizeof (unsigned int));
        if (servers_waiting == MAP_FAILED) {
                log_message (LOG_ERR,
                             "Could not allocate memory for child counting.");
                return -1;
        }
        *servers_waiting = 0;

        /*
         * Create a "locking" file for use around the servers_waiting
         * variable.
         */
        _child_lock_init ();

        if (child_config.startservers > child_config.maxclients) {
                log_message (LOG_WARNING,
                             "Can not start more than \"MaxClients\" servers. "
                             "Starting %u servers instead.",
                             child_config.maxclients);
                child_config.startservers = child_config.maxclients;
        }

        for (i = 0; i != child_config.maxclients; i++) {
                child_ptr[i].status = T_EMPTY;
                child_ptr[i].connects = 0;
        }

        for (i = 0; i != child_config.startservers; i++) {
                DEBUG2 ("Trying to create child %d of %d", i + 1,
                        child_config.startservers);
                child_ptr[i].status = T_WAITING;
                child_ptr[i].tid = child_make (&child_ptr[i]);

                if (child_ptr[i].tid < 0) {
                        log_message (LOG_WARNING,
                                     "Could not create child number %d of %d",
                                     i, child_config.startservers);
                        return -1;
                } else {
                        log_message (LOG_INFO,
                                     "Creating child number %d of %d ...",
                                     i + 1, child_config.startservers);

                        SERVER_INC ();
                }
        }

        log_message (LOG_INFO, "Finished creating all children.");

        return 0;
}