UnixUtil.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #ifndef __UNIXUTIL_H
  18. #define __UNIXUTIL_H
  19. #include <kopano/zcdefs.h>
  20. #include <dirent.h>
  21. #include <sys/resource.h>
  22. #include <kopano/ECConfig.h>
  23. namespace KC {
  24. class fs_deleter {
  25. public:
  26. void operator()(DIR *d)
  27. {
  28. if (d != nullptr)
  29. closedir(d);
  30. }
  31. };
  32. struct popen_rlimit {
  33. int resource;
  34. struct rlimit limit;
  35. };
  36. struct popen_rlimit_array {
  37. unsigned int cValues;
  38. struct popen_rlimit sLimit[1];
  39. };
  40. #define sized_popen_rlimit_array(_climit, _name) \
  41. struct _popen_rlimit_array_ ## _name { \
  42. unsigned int cValues; \
  43. struct popen_rlimit sLimit[_climit]; \
  44. } _name
  45. extern _kc_export int unix_runas(ECConfig *);
  46. extern _kc_export int unix_chown(const char *filename, const char *user, const char *group);
  47. extern _kc_export void unix_coredump_enable(void);
  48. extern _kc_export int unix_create_pidfile(const char *argv0, ECConfig *, bool force = true);
  49. extern _kc_export int unix_daemonize(ECConfig *);
  50. extern _kc_export int unix_fork_function(void *(*)(void *), void *param, int nfds, int *closefds);
  51. extern _kc_export bool unix_system(const char *logname, const char *command, const char **env);
  52. } /* namespace */
  53. #endif