@@ -31,6 +31,8 @@ extern "C" {
3131 * Initialize the library. Call it before libcomcom_run_command().
3232 * Note that this erases the old SIGCHLD handler (if any).
3333 * @return 0 on success and -1 on error (also sets `errno`).
34+ *
35+ * You should usually also initialize SIGTERM/SIGINT signal handlers.
3436 */
3537int libcomcom_init (void );
3638
@@ -41,6 +43,8 @@ int libcomcom_init(void);
4143 * The old signal handler (the one obtained from `old` variable) is also
4244 * called from our SIGCHLD handler.
4345 * @return 0 on success and -1 on error (also sets `errno`).
46+ *
47+ * You should usually also initialize SIGTERM/SIGINT signal handlers.
4448 */
4549int libcomcom_init2 (struct sigaction * old );
4650
@@ -53,6 +57,8 @@ int libcomcom_init2(struct sigaction *old);
5357 * (not by sigaction()), then this function may not work (leads to undefined
5458 * behavior) on some non-Unix systems.
5559 * @return 0 on success and -1 on error (also sets `errno`).
60+ *
61+ * You should usually also initialize SIGTERM/SIGINT signal handlers.
5662 */
5763int libcomcom_init_stratum (void );
5864
@@ -64,7 +70,7 @@ int libcomcom_init_stratum(void);
6470 * @param output_len at this location is stored the length of command's stdout
6571 * @param file the command to run (PATH used)
6672 * @param argv arguments for the command to run
67- * @param envp environment for the command to run (pass `environ ` to duplicate our environment)
73+ * @param envp environment for the command to run (pass `NULL ` to duplicate our environment)
6874 * @param timeout timeout in milliseconds, -1 means infinite timeout
6975 * @return 0 on success and -1 on error (also sets `errno`).
7076 */
@@ -76,6 +82,7 @@ int libcomcom_run_command(const char *input, size_t input_len,
7682
7783/**
7884 * Should be run for normal termination (not in SIGTERM/SIGINT handler)
85+ * of our program.
7986 * @return 0 on success and -1 on error (also sets `errno`).
8087 */
8188int libcomcom_destroy (void );
@@ -88,20 +95,41 @@ int libcomcom_terminate(void);
8895
8996/**
9097 * Install SIGTERM and SIGINT handler which calls libcomcom_terminate().
91- * If your program needs to handle SIGTERM or SIGINT in another way,
92- * use libcomcom_terminate() instead.
9398 * @return 0 on success and -1 on error (also sets `errno`).
99+ *
100+ * You are recommended to use libcomcom_set_default_terminate2()
101+ * instead.
94102 */
95103int libcomcom_set_default_terminate (void );
96104
97105/**
98106 * Uninstall SIGTERM and SIGINT handler which calls libcomcom_terminate().
99- * If your program needs to handle SIGTERM or SIGINT in another way,
100- * use libcomcom_terminate() instead.
101107 * @return 0 on success and -1 on error (also sets `errno`).
108+ *
109+ * You are recommended to use libcomcom_reset_default_terminate2()
110+ * instead.
102111 */
103112int libcomcom_reset_default_terminate (void );
104113
114+ /**
115+ * Install SIGTERM and SIGINT handler which calls libcomcom_terminate().
116+ * @return 0 on success and -1 on error (also sets `errno`).
117+ *
118+ * The installed signal handler also calls old signal handler automatically.
119+ *
120+ * WARNING: If before calling these handlers were set by signal()
121+ * (not by sigaction()), then this function may not work (leads to undefined
122+ * behavior) on some non-Unix systems.
123+ */
124+ int libcomcom_set_default_terminate2 (void );
125+
126+ /**
127+ * Resets to signal handlers which were before calling
128+ * libcomcom_set_default_terminate2().
129+ * @return 0 on success and -1 on error (also sets `errno`).
130+ */
131+ int libcomcom_reset_default_terminate2 (void );
132+
105133#ifdef __cplusplus
106134}
107135#endif
0 commit comments