sys_start_process.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  1. /**
  2. * @file sys_start_process.c
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * @section DESCRIPTION
  30. *
  31. * Synopsis:
  32. * sys.start_process(list command, string mode [, map options])
  33. *
  34. * Options:
  35. * "keep_stdout":"true" - Start the program with the same stdout as the NCD process.
  36. * Must not be present if the process is being opened for reading.
  37. * "keep_stderr":true" - Start the program with the same stderr as the NCD process.
  38. * "do_setsid":"true" - Call setsid() in the child before exec. This is needed to
  39. * start the 'agetty' program.
  40. * "username":username_string - Start the process under the permissions of the
  41. * specified user.
  42. * "term_on_deinit":"false" - do not send SIGTERM to the process when this statement
  43. * is requested to terminate
  44. * "deinit_kill_time":milliseconds - how long to wait for the process to terminate
  45. * after this statement is requested to terminate until we send SIGKILL. If this option
  46. * is not present or is "never", SIGKILL will not be sent. If this option is empty, the
  47. * process will be sent SIGKILL immediately when the statement is requested to terminate.
  48. *
  49. * Variables:
  50. * is_error - "true" if there was an error starting the process, "false" if the process
  51. * has been started successfully
  52. *
  53. * Synopsis:
  54. * sys.start_process::wait()
  55. *
  56. * Variables:
  57. * exit_status - the exit code if the process terminated normally, -1 if it terminated
  58. * with a signal
  59. *
  60. * Synopsis:
  61. * sys.start_process::terminate()
  62. * sys.start_process::kill()
  63. *
  64. * Synopsis:
  65. * sys.start_process::read_pipe()
  66. *
  67. * Description:
  68. * Creates a read interface to the process's standard output. Data is read using the
  69. * read() method on this object. Read errors are reported implicitly by this statement
  70. * going down and the 'is_error' variable changing to "true".
  71. * When read_pipe() is initialized for a process, it takes ownership of the read pipe
  72. * to the process. When read_pipe() is requested to terminate, it will close the pipe.
  73. * Attempting to initialize read_pipe() on a process which was not started with 'r'
  74. * in the mode argument, or where another read_pipe() object has already taken ownership
  75. * of the read pipe, will result in throwing an error to the interpreter.
  76. *
  77. * Variables:
  78. * string is_error - "true" if there was a read error, "false" if not
  79. *
  80. * Synopsis:
  81. * sys.start_process::read_pipe::read()
  82. *
  83. * Description:
  84. * Reads some data. If a read error occurs, it is reported implicitly via the
  85. * read_pipe() object going down. If end of file is reached, this and any future read()
  86. * operations will indicate that via the 'not_eof' variable. It is guaranteed that after
  87. * EOF is reached, the read_pipe() object will not go down to report any errors.
  88. * WARNING: if a read() is requested to terminate before it has completed, the
  89. * read_pipe() will become unusable and any read() invocation after that will
  90. * throw an error to the interpreter.
  91. *
  92. * Variables:
  93. * string (empty) - data that was read, or an empty string on EOF
  94. * string not_eof - "true" is EOF was not reached, "false" if it was
  95. *
  96. * Synopsis:
  97. * sys.start_process::write_pipe()
  98. *
  99. * Description:
  100. * Creates a write interface to the process's standard input. Data is written using the
  101. * write() method on this object. Write errors are reported implicitly by this statement
  102. * going down and the ''is_error variable changing to "true".
  103. * When write_pipe() is initialized for a process, it takes ownership of the write pipe
  104. * to the process. When write_pipe() is requested to terminate, it will close the pipe
  105. * (unless the close() has been used).
  106. * Attempting to initialize write_pipe() on a process which was not started with 'w'
  107. * in the mode argument, or where another write_pipe() object has already taken ownership
  108. * of the write pope, will result in throwing an error to the interpreter.
  109. *
  110. * Variables:
  111. * string is_error - "true" if there was a write error, "false" if not
  112. *
  113. * Synopsis:
  114. * sys.start_process::write_pipe::write(string data)
  115. *
  116. * Description:
  117. * Writes the given data. If a write error occurs, it is reported implicitly via the
  118. * write_pipe() object going down.
  119. * WARNING: if a write() is requested to terminate before it has completed, the
  120. * write_pipe() will become unusable and any write() or close() invocation after
  121. * that will throw an error to the interpreter.
  122. *
  123. * Synopsis:
  124. * sys.start_process::write_pipe::close(string data)
  125. *
  126. * Description:
  127. * Closes the write pipe. This will make whatever is reading the other end of the pipe
  128. * encounter EOF after it has read any pending data. It is guaranteed that after the
  129. * pipe is closed, the write_pipe() object will not go down to report any errors.
  130. * After close() is performed, any further write() or close() calls are disallowed and
  131. * will throw errors to the interpreter.
  132. */
  133. #include <stdlib.h>
  134. #include <string.h>
  135. #include <stdio.h>
  136. #include <inttypes.h>
  137. #include <limits.h>
  138. #include <unistd.h>
  139. #include <misc/offset.h>
  140. #include <structure/LinkedList0.h>
  141. #include <system/BProcess.h>
  142. #include <system/BConnection.h>
  143. #include <ncd/extra/NCDBuf.h>
  144. #include <ncd/extra/build_cmdline.h>
  145. #include <ncd/extra/NCDBProcessOpts.h>
  146. #include <ncd/module_common.h>
  147. #include <generated/blog_channel_ncd_sys_start_process.h>
  148. #define READ_BUF_SIZE 8192
  149. #define PROCESS_STATE_ERROR 1
  150. #define PROCESS_STATE_RUNNING 2
  151. #define PROCESS_STATE_TERMINATED 3
  152. #define PROCESS_STATE_DYING 4
  153. #define READER_STATE_RUNNING 1
  154. #define READER_STATE_EOF 2
  155. #define READER_STATE_ERROR 3
  156. #define READER_STATE_ABORTED 4
  157. #define WRITER_STATE_RUNNING 1
  158. #define WRITER_STATE_CLOSED 2
  159. #define WRITER_STATE_ERROR 3
  160. #define WRITER_STATE_ABORTED 4
  161. struct process_instance {
  162. NCDModuleInst *i;
  163. BProcess process;
  164. BSmallTimer kill_timer;
  165. LinkedList0 waits_list;
  166. btime_t deinit_kill_time;
  167. int term_on_deinit;
  168. int read_fd;
  169. int write_fd;
  170. int exit_status;
  171. int state;
  172. };
  173. struct wait_instance {
  174. NCDModuleInst *i;
  175. struct process_instance *pinst;
  176. LinkedList0Node waits_list_node;
  177. int exit_status;
  178. };
  179. struct read_pipe_instance {
  180. NCDModuleInst *i;
  181. int state;
  182. int read_fd;
  183. BConnection connection;
  184. NCDBufStore store;
  185. struct read_instance *read_inst;
  186. };
  187. struct read_instance {
  188. NCDModuleInst *i;
  189. struct read_pipe_instance *read_pipe_inst;
  190. NCDBuf *buf;
  191. size_t read_size;
  192. };
  193. struct write_pipe_instance {
  194. NCDModuleInst *i;
  195. int state;
  196. int write_fd;
  197. BConnection connection;
  198. struct write_instance *write_inst;
  199. };
  200. struct write_instance {
  201. NCDModuleInst *i;
  202. struct write_pipe_instance *write_pipe_inst;
  203. b_cstring cstr;
  204. size_t pos;
  205. };
  206. static int parse_mode (NCDModuleInst *i, NCDValRef mode_arg, int *out_read, int *out_write)
  207. {
  208. if (!NCDVal_IsString(mode_arg)) {
  209. ModuleLog(i, BLOG_ERROR, "mode argument must be a string");
  210. return 0;
  211. }
  212. *out_read = 0;
  213. *out_write = 0;
  214. b_cstring cstr = NCDVal_StringCstring(mode_arg);
  215. B_CSTRING_LOOP_CHARS(cstr, char_pos, ch, {
  216. if (ch == 'r') {
  217. *out_read = 1;
  218. }
  219. else if (ch == 'w') {
  220. *out_write = 1;
  221. }
  222. else {
  223. ModuleLog(i, BLOG_ERROR, "invalid character in mode argument");
  224. return 0;
  225. }
  226. })
  227. return 1;
  228. }
  229. static void process_free (struct process_instance *o)
  230. {
  231. // close write fd
  232. if (o->write_fd != -1) {
  233. if (close(o->write_fd) < 0) {
  234. ModuleLog(o->i, BLOG_ERROR, "close failed");
  235. }
  236. }
  237. // close read fd
  238. if (o->read_fd != -1) {
  239. if (close(o->read_fd) < 0) {
  240. ModuleLog(o->i, BLOG_ERROR, "close failed");
  241. }
  242. }
  243. NCDModuleInst_Backend_Dead(o->i);
  244. }
  245. static void process_handler (void *vo, int normally, uint8_t normally_exit_status)
  246. {
  247. struct process_instance *o = vo;
  248. ASSERT(o->state == PROCESS_STATE_RUNNING || o->state == PROCESS_STATE_DYING)
  249. ModuleLog(o->i, BLOG_INFO, "process terminated");
  250. // free kill timer
  251. BReactor_RemoveSmallTimer(o->i->params->iparams->reactor, &o->kill_timer);
  252. // free process
  253. BProcess_Free(&o->process);
  254. // remember exit code
  255. o->exit_status = (!normally ? -1 : normally_exit_status);
  256. // finish waits
  257. LinkedList0Node *ln;
  258. while ((ln = LinkedList0_GetFirst(&o->waits_list))) {
  259. struct wait_instance *winst = UPPER_OBJECT(ln, struct wait_instance, waits_list_node);
  260. ASSERT(winst->pinst == o)
  261. LinkedList0_Remove(&o->waits_list, &winst->waits_list_node);
  262. winst->pinst = NULL;
  263. winst->exit_status = o->exit_status;
  264. NCDModuleInst_Backend_Up(winst->i);
  265. }
  266. // if we have been requested to die, then die now
  267. if (o->state == PROCESS_STATE_DYING) {
  268. process_free(o);
  269. return;
  270. }
  271. // set state
  272. o->state = PROCESS_STATE_TERMINATED;
  273. }
  274. static void process_kill_timer_handler (BSmallTimer *kill_timer)
  275. {
  276. struct process_instance *o = UPPER_OBJECT(kill_timer, struct process_instance, kill_timer);
  277. ASSERT(o->state == PROCESS_STATE_DYING)
  278. ModuleLog(o->i, BLOG_INFO, "killing process after timeout");
  279. BProcess_Kill(&o->process);
  280. }
  281. static int opts_func_unknown (void *user, NCDValRef key, NCDValRef val)
  282. {
  283. struct process_instance *o = user;
  284. if (NCDVal_IsString(key) && NCDVal_StringEquals(key, "term_on_deinit")) {
  285. o->term_on_deinit = ncd_read_boolean(val);
  286. return 1;
  287. }
  288. if (NCDVal_IsString(key) && NCDVal_StringEquals(key, "deinit_kill_time")) {
  289. if (NCDVal_StringEquals(val, "never")) {
  290. o->deinit_kill_time = -2;
  291. }
  292. else if (NCDVal_StringEqualsId(val, NCD_STRING_EMPTY, o->i->params->iparams->string_index)) {
  293. o->deinit_kill_time = -1;
  294. }
  295. else if (!ncd_read_time(val, &o->deinit_kill_time)) {
  296. ModuleLog(o->i, BLOG_ERROR, "wrong value for deinit_kill_time option");
  297. return 0;
  298. }
  299. return 1;
  300. }
  301. return 0;
  302. }
  303. static void process_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  304. {
  305. struct process_instance *o = vo;
  306. o->i = i;
  307. NCDModuleInst_Backend_PassMemToMethods(i);
  308. // check arguments
  309. NCDValRef command_arg;
  310. NCDValRef mode_arg;
  311. NCDValRef options_arg = NCDVal_NewInvalid();
  312. if (!NCDVal_ListRead(params->args, 2, &command_arg, &mode_arg) &&
  313. !NCDVal_ListRead(params->args, 3, &command_arg, &mode_arg, &options_arg)
  314. ) {
  315. ModuleLog(i, BLOG_ERROR, "wrong arity");
  316. goto fail0;
  317. }
  318. // parse mode
  319. int is_read;
  320. int is_write;
  321. if (!parse_mode(i, mode_arg, &is_read, &is_write)) {
  322. goto fail0;
  323. }
  324. // parse options
  325. NCDBProcessOpts opts;
  326. int keep_stdout;
  327. int keep_stderr;
  328. o->deinit_kill_time = -2;
  329. o->term_on_deinit = 1;
  330. if (!NCDBProcessOpts_Init2(&opts, options_arg, opts_func_unknown, o, i, BLOG_CURRENT_CHANNEL, &keep_stdout, &keep_stderr)) {
  331. goto fail0;
  332. }
  333. // keep-stdout option and read mode are not compatible
  334. if (keep_stdout && is_read) {
  335. ModuleLog(i, BLOG_ERROR, "keep-stdout and read mode are not compatible");
  336. goto fail1;
  337. }
  338. // prepare for creating pipes
  339. int fds[4];
  340. int fds_map[3];
  341. int start_num_fds = opts.nfds;
  342. int num_fds = start_num_fds;
  343. memcpy(fds, opts.fds, num_fds * sizeof(int));
  344. memcpy(fds_map, opts.fds_map, num_fds * sizeof(int));
  345. int read_fd = -1;
  346. int write_fd = -1;
  347. // create read pipe
  348. if (is_read) {
  349. int pipefd[2];
  350. if (pipe(pipefd) < 0) {
  351. ModuleLog(i, BLOG_ERROR, "pipe failed");
  352. goto error1;
  353. }
  354. read_fd = pipefd[0];
  355. fds[num_fds] = pipefd[1];
  356. fds_map[num_fds++] = STDOUT_FILENO;
  357. }
  358. // create write pipe
  359. if (is_write) {
  360. int pipefd[2];
  361. if (pipe(pipefd) < 0) {
  362. ModuleLog(i, BLOG_ERROR, "pipe failed");
  363. goto error1;
  364. }
  365. write_fd = pipefd[1];
  366. fds[num_fds] = pipefd[0];
  367. fds_map[num_fds++] = STDIN_FILENO;
  368. }
  369. // terminate fds array
  370. fds[num_fds] = -1;
  371. // build process parameters struct
  372. struct BProcess_params p_params = {};
  373. p_params.fds = fds;
  374. p_params.fds_map = fds_map;
  375. p_params.do_setsid = opts.do_setsid;
  376. p_params.username = opts.username;
  377. // build command line
  378. char *exec;
  379. CmdLine cl;
  380. if (!ncd_build_cmdline(i, BLOG_CURRENT_CHANNEL, command_arg, &exec, &cl)) {
  381. goto error1;
  382. }
  383. // start process
  384. int res = BProcess_Init2(&o->process, i->params->iparams->manager, process_handler, o, exec, CmdLine_Get(&cl), p_params);
  385. CmdLine_Free(&cl);
  386. free(exec);
  387. if (!res) {
  388. ModuleLog(i, BLOG_ERROR, "BProcess_Init failed");
  389. goto error1;
  390. }
  391. // init kill timer
  392. BSmallTimer_Init(&o->kill_timer, process_kill_timer_handler);
  393. // close child fds
  394. while (num_fds-- > start_num_fds) {
  395. if (close(fds[num_fds]) < 0) {
  396. ModuleLog(i, BLOG_ERROR, "close failed");
  397. }
  398. }
  399. // free opts
  400. NCDBProcessOpts_Free(&opts);
  401. // init waits list
  402. LinkedList0_Init(&o->waits_list);
  403. // remember our fds
  404. o->read_fd = read_fd;
  405. o->write_fd = write_fd;
  406. // set state
  407. o->state = PROCESS_STATE_RUNNING;
  408. // go up
  409. NCDModuleInst_Backend_Up(i);
  410. return;
  411. fail1:
  412. NCDBProcessOpts_Free(&opts);
  413. fail0:
  414. NCDModuleInst_Backend_DeadError(i);
  415. return;
  416. error1:
  417. if (write_fd != -1) {
  418. if (close(write_fd) < 0) {
  419. ModuleLog(i, BLOG_ERROR, "close failed");
  420. }
  421. }
  422. if (read_fd != -1) {
  423. if (close(read_fd) < 0) {
  424. ModuleLog(i, BLOG_ERROR, "close failed");
  425. }
  426. }
  427. while (num_fds-- > start_num_fds) {
  428. if (close(fds[num_fds]) < 0) {
  429. ModuleLog(i, BLOG_ERROR, "close failed");
  430. }
  431. }
  432. NCDBProcessOpts_Free(&opts);
  433. o->read_fd = -1;
  434. o->write_fd = -1;
  435. o->state = PROCESS_STATE_ERROR;
  436. NCDModuleInst_Backend_Up(i);
  437. }
  438. static void process_func_die (void *vo)
  439. {
  440. struct process_instance *o = vo;
  441. ASSERT(o->state != PROCESS_STATE_DYING)
  442. // if process is not running, die immediately
  443. if (o->state != PROCESS_STATE_RUNNING) {
  444. process_free(o);
  445. return;
  446. }
  447. if (o->term_on_deinit) {
  448. ModuleLog(o->i, BLOG_INFO, "terminating process");
  449. // send termination signal
  450. BProcess_Terminate(&o->process);
  451. } else {
  452. ModuleLog(o->i, BLOG_INFO, "not terminating process as requested");
  453. }
  454. if (o->deinit_kill_time == -1) {
  455. // user wants SIGKILL immediately
  456. ModuleLog(o->i, BLOG_INFO, "killing process immediately");
  457. BProcess_Kill(&o->process);
  458. } else if (o->deinit_kill_time >= 0) {
  459. // user wants SIGKILL after some time
  460. BReactor_SetSmallTimer(o->i->params->iparams->reactor, &o->kill_timer, BTIMER_SET_RELATIVE, o->deinit_kill_time);
  461. }
  462. // set state
  463. o->state = PROCESS_STATE_DYING;
  464. }
  465. static int process_func_getvar (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
  466. {
  467. struct process_instance *o = vo;
  468. if (name == NCD_STRING_IS_ERROR) {
  469. int is_error = (o->state == PROCESS_STATE_ERROR);
  470. *out = ncd_make_boolean(mem, is_error, o->i->params->iparams->string_index);
  471. return 1;
  472. }
  473. return 0;
  474. }
  475. static void wait_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  476. {
  477. struct wait_instance *o = vo;
  478. o->i = i;
  479. if (!NCDVal_ListRead(params->args, 0)) {
  480. ModuleLog(i, BLOG_ERROR, "wrong arity");
  481. goto fail0;
  482. }
  483. struct process_instance *pinst = params->method_user;
  484. if (pinst->state == PROCESS_STATE_ERROR) {
  485. ModuleLog(i, BLOG_ERROR, "wait() is disallowed after the process has failed to start");
  486. goto fail0;
  487. }
  488. if (pinst->state == PROCESS_STATE_TERMINATED) {
  489. // not waiting, set no pinst
  490. o->pinst = NULL;
  491. // remember exit code
  492. o->exit_status = pinst->exit_status;
  493. // go up
  494. NCDModuleInst_Backend_Up(i);
  495. } else {
  496. // waitint, set pinst
  497. o->pinst = pinst;
  498. // insert to waits list
  499. LinkedList0_Prepend(&pinst->waits_list, &o->waits_list_node);
  500. }
  501. return;
  502. fail0:
  503. NCDModuleInst_Backend_DeadError(i);
  504. }
  505. static void wait_func_die (void *vo)
  506. {
  507. struct wait_instance *o = vo;
  508. // remove from waits list
  509. if (o->pinst) {
  510. LinkedList0_Remove(&o->pinst->waits_list, &o->waits_list_node);
  511. }
  512. NCDModuleInst_Backend_Dead(o->i);
  513. }
  514. static int wait_func_getvar (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
  515. {
  516. struct wait_instance *o = vo;
  517. ASSERT(!o->pinst)
  518. if (name == NCD_STRING_EXIT_STATUS) {
  519. if (o->exit_status == -1) {
  520. *out = NCDVal_NewString(mem, "-1");
  521. } else {
  522. *out = ncd_make_uintmax(mem, o->exit_status);
  523. }
  524. return 1;
  525. }
  526. return 0;
  527. }
  528. static void terminate_kill_new_common (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params, int is_kill)
  529. {
  530. if (!NCDVal_ListRead(params->args, 0)) {
  531. ModuleLog(i, BLOG_ERROR, "wrong arity");
  532. goto fail0;
  533. }
  534. struct process_instance *pinst = params->method_user;
  535. if (pinst->state == PROCESS_STATE_ERROR) {
  536. ModuleLog(i, BLOG_ERROR, "terminate()/kill() is disallowed after the process has failed to start");
  537. goto fail0;
  538. }
  539. if (pinst->state != PROCESS_STATE_TERMINATED) {
  540. if (is_kill) {
  541. BProcess_Kill(&pinst->process);
  542. } else {
  543. BProcess_Terminate(&pinst->process);
  544. }
  545. }
  546. NCDModuleInst_Backend_Up(i);
  547. return;
  548. fail0:
  549. NCDModuleInst_Backend_DeadError(i);
  550. }
  551. static void terminate_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  552. {
  553. terminate_kill_new_common(vo, i, params, 0);
  554. }
  555. static void kill_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  556. {
  557. terminate_kill_new_common(vo, i, params, 1);
  558. }
  559. static void read_pipe_free_connection (struct read_pipe_instance *o)
  560. {
  561. // disconnect read instance
  562. if (o->read_inst) {
  563. ASSERT(o->read_inst->read_pipe_inst == o)
  564. o->read_inst->read_pipe_inst = NULL;
  565. }
  566. // free store
  567. NCDBufStore_Free(&o->store);
  568. // free connection read interface
  569. BConnection_RecvAsync_Free(&o->connection);
  570. // free connection
  571. BConnection_Free(&o->connection);
  572. // close fd
  573. if (close(o->read_fd) < 0) {
  574. ModuleLog(o->i, BLOG_ERROR, "close failed");
  575. }
  576. }
  577. static void read_pipe_abort (struct read_pipe_instance *o)
  578. {
  579. ASSERT(o->state == READER_STATE_RUNNING)
  580. // release connection resources
  581. read_pipe_free_connection(o);
  582. // set state
  583. o->state = READER_STATE_ABORTED;
  584. }
  585. static void read_pipe_connection_handler (void *vo, int event)
  586. {
  587. struct read_pipe_instance *o = vo;
  588. ASSERT(o->state == READER_STATE_RUNNING)
  589. if (event == BCONNECTION_EVENT_RECVCLOSED) {
  590. // if we have read operation, make it finish with eof
  591. if (o->read_inst) {
  592. ASSERT(o->read_inst->read_pipe_inst == o)
  593. ASSERT(o->read_inst->buf)
  594. o->read_inst->read_pipe_inst = NULL;
  595. o->read_inst->read_size = 0;
  596. NCDModuleInst_Backend_Up(o->read_inst->i);
  597. o->read_inst = NULL;
  598. }
  599. // free connection resources
  600. read_pipe_free_connection(o);
  601. // set state closed
  602. o->state = READER_STATE_EOF;
  603. return;
  604. }
  605. ModuleLog(o->i, BLOG_ERROR, "read pipe error");
  606. // free connection resources
  607. read_pipe_free_connection(o);
  608. // set state error
  609. o->state = READER_STATE_ERROR;
  610. // backtrack
  611. NCDModuleInst_Backend_DownUp(o->i);
  612. }
  613. static void read_pipe_recv_handler_done (void *vo, int data_len)
  614. {
  615. struct read_pipe_instance *o = vo;
  616. ASSERT(o->state == READER_STATE_RUNNING)
  617. ASSERT(o->read_inst)
  618. ASSERT(o->read_inst->read_pipe_inst == o)
  619. ASSERT(o->read_inst->buf)
  620. ASSERT(data_len > 0)
  621. ASSERT(data_len <= NCDBufStore_BufSize(&o->store))
  622. // finish read operation
  623. o->read_inst->read_pipe_inst = NULL;
  624. o->read_inst->read_size = data_len;
  625. NCDModuleInst_Backend_Up(o->read_inst->i);
  626. o->read_inst = NULL;
  627. }
  628. static void read_pipe_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  629. {
  630. struct read_pipe_instance *o = vo;
  631. o->i = i;
  632. NCDModuleInst_Backend_PassMemToMethods(i);
  633. if (!NCDVal_ListRead(params->args, 0)) {
  634. ModuleLog(i, BLOG_ERROR, "wrong arity");
  635. goto fail0;
  636. }
  637. struct process_instance *pinst = params->method_user;
  638. if (pinst->read_fd == -1) {
  639. ModuleLog(i, BLOG_ERROR, "process did not start successfully, was not opened for reading or a read_pipe was already created");
  640. goto fail0;
  641. }
  642. // init connection
  643. if (!BConnection_Init(&o->connection, BConnection_source_pipe(pinst->read_fd), i->params->iparams->reactor, o, read_pipe_connection_handler)) {
  644. ModuleLog(i, BLOG_ERROR, "BConnection_Init failed");
  645. goto fail0;
  646. }
  647. // init connection read interface
  648. BConnection_RecvAsync_Init(&o->connection);
  649. // set recv done callback
  650. StreamRecvInterface_Receiver_Init(BConnection_RecvAsync_GetIf(&o->connection), read_pipe_recv_handler_done, o);
  651. // init store
  652. NCDBufStore_Init(&o->store, READ_BUF_SIZE);
  653. // set variables
  654. o->state = READER_STATE_RUNNING;
  655. o->read_fd = pinst->read_fd;
  656. o->read_inst = NULL;
  657. // steal read fd from process instance
  658. pinst->read_fd = -1;
  659. // go up
  660. NCDModuleInst_Backend_Up(i);
  661. return;
  662. fail0:
  663. NCDModuleInst_Backend_DeadError(i);
  664. }
  665. static void read_pipe_func_die (void *vo)
  666. {
  667. struct read_pipe_instance *o = vo;
  668. // free connection resources
  669. if (o->state == READER_STATE_RUNNING) {
  670. read_pipe_free_connection(o);
  671. }
  672. NCDModuleInst_Backend_Dead(o->i);
  673. }
  674. static int read_pipe_func_getvar (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
  675. {
  676. struct read_pipe_instance *o = vo;
  677. if (name == NCD_STRING_IS_ERROR) {
  678. int is_error = (o->state == READER_STATE_ERROR);
  679. *out = ncd_make_boolean(mem, is_error, o->i->params->iparams->string_index);
  680. return 1;
  681. }
  682. return 0;
  683. }
  684. static void read_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  685. {
  686. struct read_instance *o = vo;
  687. o->i = i;
  688. if (!NCDVal_ListRead(params->args, 0)) {
  689. ModuleLog(i, BLOG_ERROR, "wrong arity");
  690. goto fail0;
  691. }
  692. struct read_pipe_instance *read_pipe_inst = params->method_user;
  693. // check if a read error has already occured
  694. if (read_pipe_inst->state == READER_STATE_ERROR) {
  695. ModuleLog(i, BLOG_ERROR, "read() is disallowed after a read error has occured");
  696. goto fail0;
  697. }
  698. // check if the read_pipe has been aborted
  699. if (read_pipe_inst->state == READER_STATE_ABORTED) {
  700. ModuleLog(i, BLOG_ERROR, "read() is disallowed after a read() has been aborted");
  701. goto fail0;
  702. }
  703. // if EOF has already been encountered, complete the read immediately
  704. if (read_pipe_inst->state == READER_STATE_EOF) {
  705. o->buf = NULL;
  706. o->read_pipe_inst = NULL;
  707. o->read_size = 0;
  708. NCDModuleInst_Backend_Up(i);
  709. return;
  710. }
  711. ASSERT(read_pipe_inst->state == READER_STATE_RUNNING)
  712. // check if there's already a read in progress
  713. if (read_pipe_inst->read_inst) {
  714. ModuleLog(i, BLOG_ERROR, "read() is disallowed while another read() is in progress");
  715. goto fail0;
  716. }
  717. // get buffer
  718. o->buf = NCDBufStore_GetBuf(&read_pipe_inst->store);
  719. if (!o->buf) {
  720. ModuleLog(i, BLOG_ERROR, "NCDBufStore_GetBuf failed");
  721. goto fail0;
  722. }
  723. // set read_pipe
  724. o->read_pipe_inst = read_pipe_inst;
  725. // register read in read_pipe
  726. read_pipe_inst->read_inst = o;
  727. // receive
  728. size_t buf_size = NCDBufStore_BufSize(&read_pipe_inst->store);
  729. int to_read = (buf_size > INT_MAX ? INT_MAX : buf_size);
  730. StreamRecvInterface_Receiver_Recv(BConnection_RecvAsync_GetIf(&read_pipe_inst->connection), (uint8_t *)NCDBuf_Data(o->buf), to_read);
  731. return;
  732. fail0:
  733. NCDModuleInst_Backend_DeadError(i);
  734. }
  735. static void read_func_die (void *vo)
  736. {
  737. struct read_instance *o = vo;
  738. // if we're receiving, abort read_pipe
  739. if (o->read_pipe_inst) {
  740. ASSERT(o->read_pipe_inst->state == READER_STATE_RUNNING)
  741. ASSERT(o->read_pipe_inst->read_inst == o)
  742. ASSERT(o->buf)
  743. read_pipe_abort(o->read_pipe_inst);
  744. }
  745. // release buffer
  746. if (o->buf) {
  747. BRefTarget_Deref(NCDBuf_RefTarget(o->buf));
  748. }
  749. NCDModuleInst_Backend_Dead(o->i);
  750. }
  751. static int read_func_getvar (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
  752. {
  753. struct read_instance *o = vo;
  754. ASSERT(!o->read_pipe_inst)
  755. ASSERT(!(o->read_size > 0) || o->buf)
  756. if (name == NCD_STRING_EMPTY) {
  757. if (o->read_size > 0) {
  758. *out = NCDVal_NewExternalString(mem, NCDBuf_Data(o->buf), o->read_size, NCDBuf_RefTarget(o->buf));
  759. } else {
  760. *out = NCDVal_NewIdString(mem, NCD_STRING_EMPTY, o->i->params->iparams->string_index);
  761. }
  762. return 1;
  763. }
  764. if (name == NCD_STRING_NOT_EOF) {
  765. int not_eof = (o->read_size > 0);
  766. *out = ncd_make_boolean(mem, not_eof, o->i->params->iparams->string_index);
  767. return 1;
  768. }
  769. return 0;
  770. }
  771. static void write_pipe_free_connection (struct write_pipe_instance *o)
  772. {
  773. // disconnect write instance
  774. if (o->write_inst) {
  775. ASSERT(o->write_inst->write_pipe_inst == o)
  776. o->write_inst->write_pipe_inst = NULL;
  777. }
  778. // free connection send interface
  779. BConnection_SendAsync_Free(&o->connection);
  780. // free connection
  781. BConnection_Free(&o->connection);
  782. // close fd
  783. if (close(o->write_fd) < 0) {
  784. ModuleLog(o->i, BLOG_ERROR, "close failed");
  785. }
  786. }
  787. static void write_pipe_abort (struct write_pipe_instance *o)
  788. {
  789. ASSERT(o->state == WRITER_STATE_RUNNING)
  790. // release connection resources
  791. write_pipe_free_connection(o);
  792. // set state
  793. o->state = WRITER_STATE_ABORTED;
  794. }
  795. static void write_pipe_close (struct write_pipe_instance *o)
  796. {
  797. ASSERT(o->state == WRITER_STATE_RUNNING)
  798. // release connection resources
  799. write_pipe_free_connection(o);
  800. // set state
  801. o->state = WRITER_STATE_CLOSED;
  802. }
  803. static void write_pipe_connection_handler (void *vo, int event)
  804. {
  805. struct write_pipe_instance *o = vo;
  806. ASSERT(o->state == WRITER_STATE_RUNNING)
  807. ModuleLog(o->i, BLOG_ERROR, "write pipe error");
  808. // free connection resources
  809. write_pipe_free_connection(o);
  810. // set state error
  811. o->state = WRITER_STATE_ERROR;
  812. // backtrack
  813. NCDModuleInst_Backend_DownUp(o->i);
  814. }
  815. static void write_pipe_send_handler_done (void *vo, int data_len)
  816. {
  817. struct write_pipe_instance *o = vo;
  818. ASSERT(o->state == WRITER_STATE_RUNNING)
  819. ASSERT(o->write_inst)
  820. ASSERT(o->write_inst->write_pipe_inst == o)
  821. ASSERT(data_len > 0)
  822. ASSERT(data_len <= o->write_inst->cstr.length - o->write_inst->pos)
  823. struct write_instance *wr = o->write_inst;
  824. // update write progress
  825. wr->pos += data_len;
  826. // if there is more data, start another write operation
  827. if (wr->pos < wr->cstr.length) {
  828. size_t chunk_length;
  829. const char *chunk_data = b_cstring_get(wr->cstr, wr->pos, wr->cstr.length - wr->pos, &chunk_length);
  830. size_t to_send = (chunk_length > INT_MAX ? INT_MAX : chunk_length);
  831. StreamPassInterface_Sender_Send(BConnection_SendAsync_GetIf(&o->connection), (uint8_t *)chunk_data, to_send);
  832. return;
  833. }
  834. // finish write operation
  835. wr->write_pipe_inst = NULL;
  836. NCDModuleInst_Backend_Up(wr->i);
  837. o->write_inst = NULL;
  838. }
  839. static void write_pipe_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  840. {
  841. struct write_pipe_instance *o = vo;
  842. o->i = i;
  843. NCDModuleInst_Backend_PassMemToMethods(i);
  844. if (!NCDVal_ListRead(params->args, 0)) {
  845. ModuleLog(i, BLOG_ERROR, "wrong arity");
  846. goto fail0;
  847. }
  848. struct process_instance *pinst = params->method_user;
  849. if (pinst->write_fd == -1) {
  850. ModuleLog(i, BLOG_ERROR, "process did not start successfully, was not opened for writing or a write_pipe was already created");
  851. goto fail0;
  852. }
  853. // init connection
  854. if (!BConnection_Init(&o->connection, BConnection_source_pipe(pinst->write_fd), i->params->iparams->reactor, o, write_pipe_connection_handler)) {
  855. ModuleLog(i, BLOG_ERROR, "BConnection_Init failed");
  856. goto fail0;
  857. }
  858. // init connection send interface
  859. BConnection_SendAsync_Init(&o->connection);
  860. // set send done callback
  861. StreamPassInterface_Sender_Init(BConnection_SendAsync_GetIf(&o->connection), write_pipe_send_handler_done, o);
  862. // set variables
  863. o->state = WRITER_STATE_RUNNING;
  864. o->write_fd = pinst->write_fd;
  865. o->write_inst = NULL;
  866. // steal write fd from process instance
  867. pinst->write_fd = -1;
  868. // go up
  869. NCDModuleInst_Backend_Up(i);
  870. return;
  871. fail0:
  872. NCDModuleInst_Backend_DeadError(i);
  873. }
  874. static void write_pipe_func_die (void *vo)
  875. {
  876. struct write_pipe_instance *o = vo;
  877. // free connection resources
  878. if (o->state == WRITER_STATE_RUNNING) {
  879. write_pipe_free_connection(o);
  880. }
  881. NCDModuleInst_Backend_Dead(o->i);
  882. }
  883. static int write_pipe_func_getvar (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
  884. {
  885. struct write_pipe_instance *o = vo;
  886. if (name == NCD_STRING_IS_ERROR) {
  887. int is_error = (o->state == WRITER_STATE_ERROR);
  888. *out = ncd_make_boolean(mem, is_error, o->i->params->iparams->string_index);
  889. return 1;
  890. }
  891. return 0;
  892. }
  893. static void write_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  894. {
  895. struct write_instance *o = vo;
  896. o->i = i;
  897. NCDValRef data_arg;
  898. if (!NCDVal_ListRead(params->args, 1, &data_arg)) {
  899. ModuleLog(i, BLOG_ERROR, "wrong arity");
  900. goto fail0;
  901. }
  902. if (!NCDVal_IsString(data_arg)) {
  903. ModuleLog(i, BLOG_ERROR, "wrong type");
  904. goto fail0;
  905. }
  906. struct write_pipe_instance *write_pipe_inst = params->method_user;
  907. // check if a write error has already occured
  908. if (write_pipe_inst->state == WRITER_STATE_ERROR) {
  909. ModuleLog(i, BLOG_ERROR, "write() is disallowed after a write error has occured");
  910. goto fail0;
  911. }
  912. // check if the write_pipe has been aborted
  913. if (write_pipe_inst->state == WRITER_STATE_ABORTED) {
  914. ModuleLog(i, BLOG_ERROR, "write() is disallowed after a write() has been aborted");
  915. goto fail0;
  916. }
  917. // check if the write_pipe has been aborted
  918. if (write_pipe_inst->state == WRITER_STATE_CLOSED) {
  919. ModuleLog(i, BLOG_ERROR, "write() is disallowed after close() has been called");
  920. goto fail0;
  921. }
  922. ASSERT(write_pipe_inst->state == WRITER_STATE_RUNNING)
  923. // check if there's already a write in progress
  924. if (write_pipe_inst->write_inst) {
  925. ModuleLog(i, BLOG_ERROR, "write() is disallowed while another write() is in progress");
  926. goto fail0;
  927. }
  928. // initialize write progress state
  929. o->cstr = NCDVal_StringCstring(data_arg);
  930. o->pos = 0;
  931. // if there's nothing to send, go up immediately
  932. if (o->cstr.length == 0) {
  933. o->write_pipe_inst = NULL;
  934. NCDModuleInst_Backend_Up(i);
  935. return;
  936. }
  937. // set write_pipe
  938. o->write_pipe_inst = write_pipe_inst;
  939. // register write in write_pipe
  940. write_pipe_inst->write_inst = o;
  941. // start send operation
  942. size_t chunk_length;
  943. const char *chunk_data = b_cstring_get(o->cstr, o->pos, o->cstr.length - o->pos, &chunk_length);
  944. size_t to_send = (chunk_length > INT_MAX ? INT_MAX : chunk_length);
  945. StreamPassInterface_Sender_Send(BConnection_SendAsync_GetIf(&write_pipe_inst->connection), (uint8_t *)chunk_data, to_send);
  946. return;
  947. fail0:
  948. NCDModuleInst_Backend_DeadError(i);
  949. }
  950. static void write_func_die (void *vo)
  951. {
  952. struct write_instance *o = vo;
  953. // if we're sending, abort write_pipe
  954. if (o->write_pipe_inst) {
  955. ASSERT(o->write_pipe_inst->state == WRITER_STATE_RUNNING)
  956. ASSERT(o->write_pipe_inst->write_inst == o)
  957. write_pipe_abort(o->write_pipe_inst);
  958. }
  959. NCDModuleInst_Backend_Dead(o->i);
  960. }
  961. static void close_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  962. {
  963. if (!NCDVal_ListRead(params->args, 0)) {
  964. ModuleLog(i, BLOG_ERROR, "wrong arity");
  965. goto fail0;
  966. }
  967. struct write_pipe_instance *write_pipe_inst = params->method_user;
  968. // check if a write error has already occured
  969. if (write_pipe_inst->state == WRITER_STATE_ERROR) {
  970. ModuleLog(i, BLOG_ERROR, "close() is disallowed after a write error has occured");
  971. goto fail0;
  972. }
  973. // check if the write_pipe has been aborted
  974. if (write_pipe_inst->state == WRITER_STATE_ABORTED) {
  975. ModuleLog(i, BLOG_ERROR, "close() is disallowed after a write() has been aborted");
  976. goto fail0;
  977. }
  978. // check if the write_pipe has been closed
  979. if (write_pipe_inst->state == WRITER_STATE_CLOSED) {
  980. ModuleLog(i, BLOG_ERROR, "close() is disallowed after close() has been called");
  981. goto fail0;
  982. }
  983. // close
  984. write_pipe_close(write_pipe_inst);
  985. // go up
  986. NCDModuleInst_Backend_Up(i);
  987. return;
  988. fail0:
  989. NCDModuleInst_Backend_DeadError(i);
  990. }
  991. static struct NCDModule modules[] = {
  992. {
  993. .type = "sys.start_process",
  994. .func_new2 = process_func_new,
  995. .func_die = process_func_die,
  996. .func_getvar2 = process_func_getvar,
  997. .alloc_size = sizeof(struct process_instance),
  998. .flags = NCDMODULE_FLAG_ACCEPT_NON_CONTINUOUS_STRINGS
  999. }, {
  1000. .type = "sys.start_process::wait",
  1001. .func_new2 = wait_func_new,
  1002. .func_die = wait_func_die,
  1003. .func_getvar2 = wait_func_getvar,
  1004. .alloc_size = sizeof(struct wait_instance),
  1005. .flags = NCDMODULE_FLAG_ACCEPT_NON_CONTINUOUS_STRINGS
  1006. }, {
  1007. .type = "sys.start_process::terminate",
  1008. .func_new2 = terminate_func_new,
  1009. .flags = NCDMODULE_FLAG_ACCEPT_NON_CONTINUOUS_STRINGS
  1010. }, {
  1011. .type = "sys.start_process::kill",
  1012. .func_new2 = kill_func_new,
  1013. .flags = NCDMODULE_FLAG_ACCEPT_NON_CONTINUOUS_STRINGS
  1014. }, {
  1015. .type = "sys.start_process::read_pipe",
  1016. .func_new2 = read_pipe_func_new,
  1017. .func_die = read_pipe_func_die,
  1018. .func_getvar2 = read_pipe_func_getvar,
  1019. .alloc_size = sizeof(struct read_pipe_instance),
  1020. .flags = NCDMODULE_FLAG_ACCEPT_NON_CONTINUOUS_STRINGS
  1021. }, {
  1022. .type = "sys.start_process::read_pipe::read",
  1023. .func_new2 = read_func_new,
  1024. .func_die = read_func_die,
  1025. .func_getvar2 = read_func_getvar,
  1026. .alloc_size = sizeof(struct read_instance),
  1027. .flags = NCDMODULE_FLAG_ACCEPT_NON_CONTINUOUS_STRINGS
  1028. }, {
  1029. .type = "sys.start_process::write_pipe",
  1030. .func_new2 = write_pipe_func_new,
  1031. .func_die = write_pipe_func_die,
  1032. .func_getvar2 = write_pipe_func_getvar,
  1033. .alloc_size = sizeof(struct write_pipe_instance),
  1034. .flags = NCDMODULE_FLAG_ACCEPT_NON_CONTINUOUS_STRINGS
  1035. }, {
  1036. .type = "sys.start_process::write_pipe::write",
  1037. .func_new2 = write_func_new,
  1038. .func_die = write_func_die,
  1039. .alloc_size = sizeof(struct write_instance),
  1040. .flags = NCDMODULE_FLAG_ACCEPT_NON_CONTINUOUS_STRINGS
  1041. }, {
  1042. .type = "sys.start_process::write_pipe::close",
  1043. .func_new2 = close_func_new,
  1044. .flags = NCDMODULE_FLAG_ACCEPT_NON_CONTINUOUS_STRINGS
  1045. }, {
  1046. .type = NULL
  1047. }
  1048. };
  1049. const struct NCDModuleGroup ncdmodule_sys_start_process = {
  1050. .modules = modules
  1051. };