"Fossies" - the Fresh Open Source Software Archive

Member "ftss-0.9.3/src/ftss.c" (2 Nov 2009, 3832 Bytes) of package /linux/www/old/ftss-0.9.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ftss.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright 2009 FableTech
    3  *
    4  * Licensed under the Apache License, Version 2.0 (the "License");
    5  * you may not use this file except in compliance with the License.
    6  * You may obtain a copy of the License at
    7  *
    8  *     http://www.apache.org/licenses/LICENSE-2.0
    9  *
   10  * Unless required by applicable law or agreed to in writing, software
   11  * distributed under the License is distributed on an "AS IS" BASIS,
   12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13  * See the License for the specific language governing permissions and
   14  * limitations under the License.
   15  */
   16 #undef PACKAGE_BUGREPORT
   17 #undef PACKAGE_NAME
   18 #undef PACKAGE_STRING
   19 #undef PACKAGE_TARNAME
   20 #undef PACKAGE_VERSION
   21 
   22 #include "apr_shm.h"
   23 #include "apr_errno.h"
   24 #include "apr_general.h"
   25 #include "apr_lib.h"
   26 #include "apr_strings.h"
   27 #include "apr_time.h"
   28 
   29 #include "httpd.h"
   30 #include "scoreboard.h"
   31 
   32 #include <errno.h>
   33 #include <stdio.h>
   34 #include <stdlib.h>
   35 #if APR_HAVE_UNISTD_H
   36 #include <unistd.h>
   37 #endif
   38 
   39 
   40 
   41 static const char statuschr[] = { '.','S','_','R','W','K','L','D','C','G','I' };
   42 
   43 
   44 int main(int argc, char *argv[])
   45 {
   46     apr_status_t rv;
   47     apr_pool_t *pool;
   48     apr_shm_t *shm;
   49     void *p;
   50     size_t size;
   51     global_score *global;
   52     process_score *parent;
   53     worker_score *server;
   54     int i, j;
   55 
   56     if (argc != 2) {
   57         fprintf(stderr, "Usage: %s /path/to/scoreboard\n", argv[0]);
   58         return EXIT_FAILURE;
   59     }
   60 
   61     apr_initialize();
   62 
   63     if ((rv = apr_pool_create(&pool, NULL)) != APR_SUCCESS) {
   64         fprintf(stderr, "%s: apr_pool_create() failed: %d\n",
   65             argv[0], rv);
   66         return EXIT_FAILURE;
   67     }
   68 
   69     
   70     if ((rv = apr_shm_attach(&shm, argv[1], pool)) != APR_SUCCESS) {
   71         fprintf(stderr, "%s: apr_shm_attach() failed: %d\n",
   72             argv[0], rv);
   73         return EXIT_FAILURE;
   74     }
   75 
   76     if (!(p = apr_shm_baseaddr_get(shm))) {
   77         fprintf(stderr, "%s: apr_shm_baseaddr_get() failed.\n",
   78             argv[0]);
   79         return EXIT_FAILURE;
   80     }
   81 
   82     if ((size = apr_shm_size_get(shm)) < sizeof(*global)) {
   83         fprintf(stderr, "%s: Scoreboard too small.\n",
   84             argv[0]);
   85         return EXIT_FAILURE;
   86     }
   87     //printf("p=%p, size = %u\n", p, (unsigned int)size);
   88 
   89     global = p;
   90     p += sizeof(*global);
   91 
   92     if (size != (
   93             sizeof(*global)
   94             + sizeof(*parent)
   95                 * global->server_limit
   96             + sizeof(*server)
   97                 * global->server_limit
   98                 * global->thread_limit
   99 #ifdef SCOREBOARD_BALANCERS
  100             + sizeof(lb_score)
  101                 * global->lb_limit
  102 #endif
  103     )) {
  104         fprintf(stderr, "%s: Wrong scoreboard size.\n",
  105             argv[0]);
  106         return EXIT_FAILURE;
  107     }
  108 
  109 /*
  110     printf("global->server_limit = %d\n", global->server_limit);
  111     printf("global->thread_limit = %d\n", global->thread_limit);
  112     printf("global->sb_type = %d\n", global->sb_type);
  113     printf("global->running_generation = %d\n", global->running_generation);
  114     printf("global->restart_time = %lld\n", global->restart_time);
  115 #ifdef SCOREBOARD_BALANCERS
  116     printf("global->lb_limit = %d\n", global->lb_limit);
  117 #endif
  118 */
  119 
  120     parent = p;
  121     p += sizeof(*parent) * global->server_limit;
  122 
  123 /*
  124     for (i=0; i<global->server_limit; i++) {
  125         if (!parent->pid) continue;
  126         printf("parent pid = %d\n", parent->pid);
  127     }
  128 */
  129 
  130     for (i=0; i<global->server_limit; i++) {
  131         if (!parent[i].pid) continue;
  132         for (j=0; j<global->thread_limit; j++) {
  133             server = p;
  134             p += sizeof(*server);
  135             if (server->status == SERVER_DEAD) continue;
  136             if (server->status >= SERVER_NUM_STATUS) continue;
  137             //printf("status = %d\n", server->status);
  138             //printf("->vhost = [%s]\n", server->vhost);
  139             //printf("->request = [%s]\n", server->request);
  140             printf("%d", parent[i].pid);
  141             printf("\t%c", statuschr[server->status]);
  142             printf("\t%.32s", server->client);
  143             printf("\t%.32s", server->vhost);
  144             printf("\t%.64s", server->request);
  145             printf("\n");
  146         }
  147     }
  148 
  149     if ((rv = apr_shm_detach(shm)) != APR_SUCCESS) {
  150         fprintf(stderr, "%s: apr_shm_detach() failed: %d\n",
  151             argv[0], rv);
  152         return EXIT_FAILURE;
  153     }
  154 
  155     return EXIT_SUCCESS;
  156 }