| 1 | /*- |
|---|
| 2 | * Copyright (c) 2006 Verdens Gang AS |
|---|
| 3 | * Copyright (c) 2006-2009 Linpro AS |
|---|
| 4 | * All rights reserved. |
|---|
| 5 | * |
|---|
| 6 | * Author: Poul-Henning Kamp <phk@phk.freebsd.dk> |
|---|
| 7 | * |
|---|
| 8 | * Redistribution and use in source and binary forms, with or without |
|---|
| 9 | * modification, are permitted provided that the following conditions |
|---|
| 10 | * are met: |
|---|
| 11 | * 1. Redistributions of source code must retain the above copyright |
|---|
| 12 | * notice, this list of conditions and the following disclaimer. |
|---|
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 14 | * notice, this list of conditions and the following disclaimer in the |
|---|
| 15 | * documentation and/or other materials provided with the distribution. |
|---|
| 16 | * |
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
|---|
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|---|
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|---|
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
|---|
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|---|
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|---|
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|---|
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|---|
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|---|
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|---|
| 27 | * SUCH DAMAGE. |
|---|
| 28 | */ |
|---|
| 29 | |
|---|
| 30 | #include "config.h" |
|---|
| 31 | |
|---|
| 32 | #include "svnid.h" |
|---|
| 33 | SVNID("$Id$") |
|---|
| 34 | |
|---|
| 35 | #include <stdio.h> |
|---|
| 36 | #include <unistd.h> |
|---|
| 37 | #include <stdlib.h> |
|---|
| 38 | #include <signal.h> |
|---|
| 39 | |
|---|
| 40 | #include "cache.h" |
|---|
| 41 | #include "stevedore.h" |
|---|
| 42 | #include "hash_slinger.h" |
|---|
| 43 | |
|---|
| 44 | /*-------------------------------------------------------------------- |
|---|
| 45 | * Per thread storage for the session currently being processed by |
|---|
| 46 | * the thread. This is used for panic messages. |
|---|
| 47 | */ |
|---|
| 48 | |
|---|
| 49 | static pthread_key_t sp_key; |
|---|
| 50 | |
|---|
| 51 | void |
|---|
| 52 | THR_SetSession(const struct sess *sp) |
|---|
| 53 | { |
|---|
| 54 | |
|---|
| 55 | AZ(pthread_setspecific(sp_key, sp)); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | const struct sess * |
|---|
| 59 | THR_GetSession(void) |
|---|
| 60 | { |
|---|
| 61 | |
|---|
| 62 | return (pthread_getspecific(sp_key)); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | /*-------------------------------------------------------------------- |
|---|
| 66 | * Name threads if our pthreads implementation supports it. |
|---|
| 67 | */ |
|---|
| 68 | |
|---|
| 69 | static pthread_key_t name_key; |
|---|
| 70 | |
|---|
| 71 | void |
|---|
| 72 | THR_SetName(const char *name) |
|---|
| 73 | { |
|---|
| 74 | |
|---|
| 75 | AZ(pthread_setspecific(name_key, name)); |
|---|
| 76 | #ifdef HAVE_PTHREAD_SET_NAME_NP |
|---|
| 77 | pthread_set_name_np(pthread_self(), name); |
|---|
| 78 | #endif |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | const char * |
|---|
| 82 | THR_GetName(void) |
|---|
| 83 | { |
|---|
| 84 | |
|---|
| 85 | return (pthread_getspecific(name_key)); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | /*-------------------------------------------------------------------- |
|---|
| 89 | * XXX: Think more about which order we start things |
|---|
| 90 | */ |
|---|
| 91 | |
|---|
| 92 | void |
|---|
| 93 | child_main(void) |
|---|
| 94 | { |
|---|
| 95 | |
|---|
| 96 | setbuf(stdout, NULL); |
|---|
| 97 | setbuf(stderr, NULL); |
|---|
| 98 | printf("Child starts\n"); |
|---|
| 99 | |
|---|
| 100 | AZ(pthread_key_create(&sp_key, NULL)); |
|---|
| 101 | AZ(pthread_key_create(&name_key, NULL)); |
|---|
| 102 | |
|---|
| 103 | THR_SetName("cache-main"); |
|---|
| 104 | |
|---|
| 105 | VSL_Init(); /* First, LCK needs it. */ |
|---|
| 106 | |
|---|
| 107 | LCK_Init(); /* Locking, must be first */ |
|---|
| 108 | |
|---|
| 109 | PAN_Init(); |
|---|
| 110 | CLI_Init(); |
|---|
| 111 | Fetch_Init(); |
|---|
| 112 | |
|---|
| 113 | CNT_Init(); |
|---|
| 114 | VCL_Init(); |
|---|
| 115 | |
|---|
| 116 | HTTP_Init(); |
|---|
| 117 | SES_Init(); |
|---|
| 118 | |
|---|
| 119 | VBE_Init(); |
|---|
| 120 | VBP_Init(); |
|---|
| 121 | WRK_Init(); |
|---|
| 122 | |
|---|
| 123 | EXP_Init(); |
|---|
| 124 | HSH_Init(); |
|---|
| 125 | BAN_Init(); |
|---|
| 126 | |
|---|
| 127 | VCA_Init(); |
|---|
| 128 | |
|---|
| 129 | SMS_Init(); |
|---|
| 130 | STV_open(); |
|---|
| 131 | |
|---|
| 132 | BAN_Compile(); |
|---|
| 133 | |
|---|
| 134 | /* Wait for persistent storage to load if asked to */ |
|---|
| 135 | if (params->diag_bitmap & 0x00020000) |
|---|
| 136 | SMP_Ready(); |
|---|
| 137 | |
|---|
| 138 | CLI_Run(); |
|---|
| 139 | |
|---|
| 140 | STV_close(); |
|---|
| 141 | |
|---|
| 142 | printf("Child dies\n"); |
|---|
| 143 | } |
|---|