2
0

instance.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. int argc;
  37. };
  38. typedef enum instance_watchdog {
  39. INSTANCE_WATCHDOG_MODE_DISABLED,
  40. INSTANCE_WATCHDOG_MODE_PASSIVE,
  41. INSTANCE_WATCHDOG_MODE_ACTIVE,
  42. __INSTANCE_WATCHDOG_MODE_MAX,
  43. } instance_watchdog_mode_t;
  44. struct watchdog {
  45. instance_watchdog_mode_t mode;
  46. uint32_t freq;
  47. struct uloop_timeout timeout;
  48. };
  49. struct service_instance {
  50. struct vlist_node node;
  51. struct service *srv;
  52. const char *name;
  53. int8_t nice;
  54. bool valid;
  55. char *user;
  56. uid_t uid;
  57. gid_t pw_gid;
  58. char *group;
  59. gid_t gr_gid;
  60. bool halt;
  61. bool restart;
  62. bool respawn;
  63. int respawn_count;
  64. int reload_signal;
  65. struct timespec start;
  66. bool trace;
  67. bool has_jail;
  68. bool require_jail;
  69. bool immediately;
  70. bool no_new_privs;
  71. struct jail jail;
  72. char *seccomp;
  73. char *capabilities;
  74. char *pidfile;
  75. char *extroot;
  76. char *overlaydir;
  77. char *tmpoverlaysize;
  78. char *bundle;
  79. int syslog_facility;
  80. int exit_code;
  81. uint32_t term_timeout;
  82. uint32_t respawn_timeout;
  83. uint32_t respawn_threshold;
  84. uint32_t respawn_retry;
  85. struct blob_attr *config;
  86. struct uloop_process proc;
  87. struct uloop_timeout timeout;
  88. struct ustream_fd _stdout;
  89. struct ustream_fd _stderr;
  90. struct ustream_fd console;
  91. struct ustream_fd console_client;
  92. struct blob_attr *command;
  93. struct blob_attr *trigger;
  94. struct blobmsg_list env;
  95. struct blobmsg_list data;
  96. struct blobmsg_list netdev;
  97. struct blobmsg_list file;
  98. struct blobmsg_list limits;
  99. struct blobmsg_list errors;
  100. struct watchdog watchdog;
  101. };
  102. void instance_start(struct service_instance *in);
  103. void instance_stop(struct service_instance *in, bool halt);
  104. void instance_update(struct service_instance *in, struct service_instance *in_new);
  105. void instance_init(struct service_instance *in, struct service *s, struct blob_attr *config);
  106. void instance_free(struct service_instance *in);
  107. void instance_dump(struct blob_buf *b, struct service_instance *in, int debug);
  108. #endif