/src/helpers/session/session.cpp

https://gitlab.com/github-cloud-corporation/cynara · C++ · 43 lines · 14 code · 6 blank · 23 comment · 1 complexity · 100036a2c2eb43182ae3c925621cfaea MD5 · raw file

  1. /*
  2. * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
  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. * @file src/helpers/session/session.cpp
  18. * @author Radoslaw Bartosiak <r.bartosiak@samsung.com>
  19. * @author Aleksander Zdyb <a.zdyb@samsung.com>
  20. * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
  21. * @version 1.0
  22. * @brief Implementation of external libcynara-session API
  23. */
  24. #include <cstring>
  25. #include <string>
  26. #include <sys/stat.h>
  27. #include <attributes/attributes.h>
  28. #include <cynara-session.h>
  29. CYNARA_API
  30. char *cynara_session_from_pid(pid_t client_pid) {
  31. std::string path = std::string("/proc/") + std::to_string(client_pid);
  32. struct stat st;
  33. if (stat(path.c_str(), &st) < 0)
  34. return nullptr;
  35. std::string session = std::to_string(st.st_ctim.tv_sec) + path;
  36. return strdup(session.c_str());
  37. }