start.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. 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. #include "fspr.h"
  17. #include "fspr_general.h"
  18. #include "fspr_pools.h"
  19. #include "fspr_signal.h"
  20. #include "fspr_atomic.h"
  21. #include "fspr_arch_proc_mutex.h" /* for fspr_proc_mutex_unix_setup_lock() */
  22. #include "fspr_arch_internal_time.h"
  23. APR_DECLARE(fspr_status_t) fspr_app_initialize(int *argc,
  24. const char * const * *argv,
  25. const char * const * *env)
  26. {
  27. /* An absolute noop. At present, only Win32 requires this stub, but it's
  28. * required in order to move command arguments passed through the service
  29. * control manager into the process, and it's required to fix the char*
  30. * data passed in from win32 unicode into utf-8, win32's apr internal fmt.
  31. */
  32. return fspr_initialize();
  33. }
  34. static int initialized = 0;
  35. APR_DECLARE(fspr_status_t) fspr_initialize(void)
  36. {
  37. fspr_pool_t *pool;
  38. fspr_status_t status;
  39. if (initialized++) {
  40. return APR_SUCCESS;
  41. }
  42. #if !defined(BEOS) && !defined(OS2)
  43. fspr_proc_mutex_unix_setup_lock();
  44. fspr_unix_setup_time();
  45. #endif
  46. if ((status = fspr_pool_initialize()) != APR_SUCCESS)
  47. return status;
  48. if (fspr_pool_create(&pool, NULL) != APR_SUCCESS) {
  49. return APR_ENOPOOL;
  50. }
  51. fspr_pool_tag(pool, "fspr_initialize");
  52. /* fspr_atomic_init() used to be called from here aswell.
  53. * Pools rely on mutexes though, which can be backed by
  54. * atomics. Due to this circular dependency
  55. * fspr_pool_initialize() is taking care of calling
  56. * fspr_atomic_init() at the correct time.
  57. */
  58. fspr_signal_init(pool);
  59. return APR_SUCCESS;
  60. }
  61. APR_DECLARE_NONSTD(void) fspr_terminate(void)
  62. {
  63. initialized--;
  64. if (initialized) {
  65. return;
  66. }
  67. fspr_pool_terminate();
  68. }
  69. APR_DECLARE(void) fspr_terminate2(void)
  70. {
  71. fspr_terminate();
  72. }