instance.h 2.4 KB

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