async_conn_entry.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright [2021] JD.com, Inc.
  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. */
  17. #include "async_conn_entry.h"
  18. #include <unistd.h>
  19. #include "log.h"
  20. #define ROOT_PATH "/etc/dtc/"
  21. const char *fulldata_name = "async-connector";
  22. extern std::map<std::string, std::string> map_dtc_conf; //key:value --> dtc addr:conf file name
  23. AsyncConnEntry::AsyncConnEntry(WatchDog *watchdog, int sec)
  24. : WatchDogDaemon(watchdog, sec)
  25. {
  26. strncpy(watchdog_object_name_, fulldata_name, sizeof(watchdog_object_name_) < strlen(fulldata_name) ? sizeof(watchdog_object_name_) : strlen(fulldata_name));
  27. }
  28. AsyncConnEntry::~AsyncConnEntry(void)
  29. {
  30. }
  31. void AsyncConnEntry::exec()
  32. {
  33. std::map<std::string, std::string>::iterator it;
  34. for(it = map_dtc_conf.begin(); it != map_dtc_conf.end(); it++)
  35. {
  36. std::string addr = (*it).first;
  37. std::string filename = (*it).second;
  38. std::string filepath = string(ROOT_PATH) + filename;
  39. log4cplus_debug("filepath:%s", filepath.c_str());
  40. char *argv[3];
  41. argv[2] = NULL;
  42. argv[0] = (char *)fulldata_name;
  43. argv[1] = (char *)filepath.c_str();
  44. execv(argv[0], argv);
  45. }
  46. }