2 Run scripts in a directory with specific event arguments
4 Copyright (C) Amitay Isaacs 2017
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef __CTDB_RUN_EVENT_H__
21 #define __CTDB_RUN_EVENT_H__
26 #include "common/run_proc.h"
31 * @brief Run scripts in a directory with specific event arguments.
33 * This abstraction allows to execute multiple scripts in a directory
34 * (specified by script_dir) with given event and arguments.
36 * At one time, only one event can be run. Multiple run_event calls
37 * will cause events to be queued up. They will be run sequentially.
39 * A "monitor" event is special and has special semantics.
41 * If a monitor event is running and another event is scheduled, the
42 * currently running monitor event is cancelled.
44 * If an event (not monitor) is running and monitor event is scheduled,
45 * then the monior event will be cancelled immediately.
49 * @brief The run process context
51 struct run_event_context
;
53 struct run_event_script
{
55 struct timeval begin
, end
;
56 struct run_proc_result result
;
61 struct run_event_script_list
{
63 struct run_event_script
*script
;
69 * @brief Initialize the context for running events
71 * @param[in] mem_ctx Talloc memory context
72 * @param[in] ev Tevent context
73 * @param[in] script_dir Directory containing script to run
74 * @param[in] debug_prog Path of a program to run if a script hangs
75 * @param[out] result New run_event context
76 * @return 0 on success, errno on error
78 int run_event_init(TALLOC_CTX
*mem_ctx
, struct tevent_context
*ev
,
79 const char *script_dir
, const char *debug_prog
,
80 struct run_event_context
**result
);
83 * @brief Get a list of scripts
85 * @param[in] run_ctx Run_event context
86 * @param[in] mem_ctx Talloc memory context
87 * @param[out] output List of valid scripts
88 * @return 0 on success, errno on failure
90 int run_event_script_list(struct run_event_context
*run_ctx
,
92 struct run_event_script_list
**output
);
95 * @brief Enable a script
97 * @param[in] run_ctx Run_event context
98 * @param[in] script_name Name of the script to enable
99 * @return 0 on success, errno on failure
101 int run_event_script_enable(struct run_event_context
*run_ctx
,
102 const char *script_name
);
105 * @brief Disable a script
107 * @param[in] run_ctx Run_event context
108 * @param[in] script_name Name of the script to disable
109 * @return 0 on success, errno on failure
111 int run_event_script_disable(struct run_event_context
*run_ctx
,
112 const char *script_name
);
115 * @brief Async computation start to run an event
117 * @param[in] mem_ctx Talloc memory context
118 * @param[in] ev Tevent context
119 * @param[in] run_ctx Run_event context
120 * @param[in] event_str The event argument to the script
121 * @param[in] arg_str Event arguments to the script
122 * @param[in] timeout How long to wait for execution
123 * @return new tevent request, or NULL on failure
125 * arg_str contains optional arguments for an event.
127 struct tevent_req
*run_event_send(TALLOC_CTX
*mem_ctx
,
128 struct tevent_context
*ev
,
129 struct run_event_context
*run_ctx
,
130 const char *event_str
,
132 struct timeval timeout
);
135 * @brief Async computation end to run an event
137 * @param[in] req Tevent request
138 * @param[out] perr errno in case of failure
139 * @param[in] mem_ctx Talloc memory context
140 * @param[out] output List of scripts executed and their status
141 * @return true on success, false on failure
143 bool run_event_recv(struct tevent_req
*req
, int *perr
,
145 struct run_event_script_list
**output
);
147 #endif /* __CTDB_RUN_EVENT_H__ */