instance.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
  3. * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License version 2.1
  7. * as published by the Free Software Foundation
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef __PROCD_INSTANCE_H
  15. #define __PROCD_INSTANCE_H
  16. #include <libubox/vlist.h>
  17. #include <libubox/uloop.h>
  18. #include <libubox/ustream.h>
  19. #include "../utils/utils.h"
  20. #define RESPAWN_ERROR (5 * 60)
  21. #define SIGNALLED_OFFSET 128
  22. struct jail {
  23. bool procfs;
  24. bool sysfs;
  25. bool ubus;
  26. bool log;
  27. bool ronly;
  28. bool netns;
  29. bool userns;
  30. bool cgroupsns;
  31. bool console;
  32. char *name;
  33. char *hostname;
  34. char *pidfile;
  35. struct blobmsg_list mount;
  36. struct blobmsg_list setns;
  37. int argc;
  38. };
  39. typedef enum instance_watchdog {
  40. INSTANCE_WATCHDOG_MODE_DISABLED,
  41. INSTANCE_WATCHDOG_MODE_PASSIVE,
  42. INSTANCE_WATCHDOG_MODE_ACTIVE,
  43. __INSTANCE_WATCHDOG_MODE_MAX,
  44. } instance_watchdog_mode_t;
  45. struct watchdog {
  46. instance_watchdog_mode_t mode;
  47. uint32_t freq;
  48. struct uloop_timeout timeout;
  49. };
  50. struct service_instance {
  51. struct vlist_node node;
  52. struct service *srv;
  53. const char *name;
  54. int8_t nice;
  55. bool valid;
  56. char *user;
  57. uid_t uid;
  58. gid_t pw_gid;
  59. char *group;
  60. gid_t gr_gid;
  61. bool halt;
  62. bool restart;
  63. bool respawn;
  64. int respawn_count;
  65. int reload_signal;
  66. struct timespec start;
  67. bool trace;
  68. bool has_jail;
  69. bool require_jail;
  70. bool immediately;
  71. bool no_new_privs;
  72. struct jail jail;
  73. char *seccomp;
  74. char *capabilities;
  75. char *pidfile;
  76. char *extroot;
  77. char *overlaydir;
  78. char *tmpoverlaysize;
  79. char *bundle;
  80. int syslog_facility;
  81. int exit_code;
  82. uint32_t term_timeout;
  83. uint32_t respawn_timeout;
  84. uint32_t respawn_threshold;
  85. uint32_t respawn_retry;
  86. struct blob_attr *config;
  87. struct uloop_process proc;
  88. struct uloop_timeout timeout;
  89. struct ustream_fd _stdout;
  90. struct ustream_fd _stderr;
  91. struct ustream_fd console;
  92. struct ustream_fd console_client;
  93. struct blob_attr *command;
  94. struct blob_attr *trigger;
  95. struct blobmsg_list env;
  96. struct blobmsg_list data;
  97. struct blobmsg_list netdev;
  98. struct blobmsg_list file;
  99. struct blobmsg_list limits;
  100. struct blobmsg_list errors;
  101. struct watchdog watchdog;
  102. };
  103. void instance_start(struct service_instance *in);
  104. void instance_stop(struct service_instance *in, bool halt);
  105. void instance_update(struct service_instance *in, struct service_instance *in_new);
  106. void instance_init(struct service_instance *in, struct service *s, struct blob_attr *config);
  107. void instance_free(struct service_instance *in);
  108. void instance_dump(struct blob_buf *b, struct service_instance *in, int debug);
  109. #endif