PageRenderTime 27ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/sblim-sfcb-1.3.15/cimslp.c

#
C | 195 lines | 127 code | 25 blank | 43 comment | 12 complexity | 8a373ea423c3367a980197f6d2ef7a6f MD5 | raw file
Possible License(s): EPL-1.0
  1. /*
  2. * cimslp.c
  3. *
  4. * (C) Copyright IBM Corp. 2006
  5. *
  6. * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
  7. * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
  8. * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
  9. *
  10. * You can obtain a current copy of the Eclipse Public License from
  11. * http://www.opensource.org/licenses/eclipse-1.0.php
  12. *
  13. * Author: Sven Schuetz <sven@de.ibm.com>
  14. * Contributions:
  15. *
  16. * Description:
  17. *
  18. * Control functions, main if running standlone, or start thread
  19. * function if running in sfcb
  20. *
  21. */
  22. #include <getopt.h>
  23. #include <stdio.h>
  24. #include <unistd.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <errno.h>
  28. #include <signal.h>
  29. #include "config.h"
  30. #include "cimslp.h"
  31. #include "trace.h"
  32. #ifdef HAVE_SLP
  33. #include "control.h"
  34. #endif
  35. extern void addStartedAdapter(int pid);
  36. void
  37. freeCFG(cimomConfig * cfg)
  38. {
  39. free(cfg->cimhost);
  40. free(cfg->cimpassword);
  41. free(cfg->cimuser);
  42. free(cfg->commScheme);
  43. free(cfg->port);
  44. }
  45. void
  46. setUpDefaults(cimomConfig * cfg)
  47. {
  48. cfg->commScheme = strdup("http");
  49. cfg->cimhost = strdup("localhost");
  50. cfg->port = strdup("5988");
  51. cfg->cimuser = strdup("");
  52. cfg->cimpassword = strdup("");
  53. cfg->keyFile = NULL;
  54. cfg->trustStore = NULL;
  55. cfg->certFile = NULL;
  56. }
  57. void
  58. setUpTimes(int *slpLifeTime, int *sleepTime)
  59. {
  60. if (*slpLifeTime < 16) {
  61. *slpLifeTime = 16;
  62. }
  63. if (*slpLifeTime > SLP_LIFETIME_MAXIMUM) {
  64. *slpLifeTime = SLP_LIFETIME_DEFAULT;
  65. }
  66. *sleepTime = *slpLifeTime - 15;
  67. }
  68. static void
  69. handleSigUsr1(int sig)
  70. {
  71. //deregisterCIMService();
  72. mlogf(M_INFO, M_SHOW, "--- %s terminating %d\n", processName, getpid());
  73. exit(0);
  74. }
  75. static void
  76. handleSigHup(int sig)
  77. {
  78. mlogf(M_INFO, M_SHOW, "--- %s restarting %d\n", processName, getpid());
  79. }
  80. #ifdef HAVE_SLP
  81. void
  82. forkSLPAgent(cimomConfig cfg, int slpLifeTime, int sleepTime)
  83. {
  84. //cimSLPService service;
  85. int pid;
  86. pid = fork();
  87. if (pid < 0) {
  88. char *emsg = strerror(errno);
  89. mlogf(M_ERROR, M_SHOW, "-#- slp agent fork: %s", emsg);
  90. exit(2);
  91. }
  92. if (pid == 0) {
  93. setSignal(SIGUSR1, handleSigUsr1, 0);
  94. setSignal(SIGINT, SIG_IGN, 0);
  95. setSignal(SIGTERM, SIG_IGN, 0);
  96. setSignal(SIGHUP, handleSigHup, 0);
  97. if (strcasecmp(cfg.commScheme, "http") == 0) {
  98. processName = "SLP Agent for HTTP Adapter";
  99. } else {
  100. processName = "SLP Agent for HTTPS Adapter";
  101. }
  102. while (1) {
  103. //service = getSLPData(cfg);
  104. //registerCIMService(service, slpLifeTime);
  105. sleep(sleepTime);
  106. }
  107. /*
  108. * if awaked-exit
  109. */
  110. exit(0);
  111. } else {
  112. slppid = pid;
  113. //addStartedAdapter(pid);
  114. }
  115. }
  116. int
  117. slpAgent()
  118. {
  119. int slpLifeTime = SLP_LIFETIME_DEFAULT;
  120. int sleepTime;
  121. cimomConfig cfgHttp,
  122. cfgHttps;
  123. int enableHttp,
  124. enableHttps = 0;
  125. extern char *configfile;
  126. _SFCB_ENTER(TRACE_SLP, "slpAgent");
  127. setupControl(configfile);
  128. setUpDefaults(&cfgHttp);
  129. setUpDefaults(&cfgHttps);
  130. sleep(1);
  131. long i;
  132. if (!getControlBool("enableHttp", &enableHttp)) {
  133. getControlNum("httpPort", &i);
  134. free(cfgHttp.port);
  135. cfgHttp.port = malloc(6 * sizeof(char)); // portnumber has max. 5
  136. // digits
  137. sprintf(cfgHttp.port, "%d", (int) i);
  138. }
  139. if (!getControlBool("enableHttps", &enableHttps)) {
  140. free(cfgHttps.commScheme);
  141. cfgHttps.commScheme = strdup("https");
  142. getControlNum("httpsPort", &i);
  143. free(cfgHttps.port);
  144. cfgHttps.port = malloc(6 * sizeof(char)); // portnumber has max. 5
  145. // digits
  146. sprintf(cfgHttps.port, "%d", (int) i);
  147. getControlChars("sslClientTrustStore", &cfgHttps.trustStore);
  148. getControlChars("sslCertificateFilePath:", &cfgHttps.certFile);
  149. getControlChars("sslKeyFilePath", &cfgHttps.keyFile);
  150. }
  151. getControlNum("slpRefreshInterval", &i);
  152. slpLifeTime = (int) i;
  153. setUpTimes(&slpLifeTime, &sleepTime);
  154. /* Disable slp registration agent for now,
  155. * since it will be going away soon anyhow.
  156. if (enableHttp)
  157. forkSLPAgent(cfgHttp, slpLifeTime, sleepTime);
  158. if (enableHttps)
  159. forkSLPAgent(cfgHttps, slpLifeTime, sleepTime);
  160. */
  161. freeCFG(&cfgHttp);
  162. freeCFG(&cfgHttps);
  163. _SFCB_RETURN(0);
  164. }
  165. #endif
  166. /* MODELINES */
  167. /* DO NOT EDIT BELOW THIS COMMENT */
  168. /* Modelines are added by 'make pretty' */
  169. /* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil; -*- */
  170. /* vi:set ts=2 sts=2 sw=2 expandtab: */