wscript: separate embedded_heimdal from system_heimdal
[Samba.git] / ctdb / common / run_event.h
blobf53bca3c525395a665d2ed0171263c6e2170036b
1 /*
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__
23 #include <talloc.h>
24 #include <tevent.h>
26 #include "common/run_proc.h"
28 /**
29 * @file run_event.h
31 * @brief Run scripts in a directory with specific event arguments.
33 * This abstraction allows one 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.
48 /**
49 * @brief The run process context
51 struct run_event_context;
53 struct run_event_script {
54 char *name;
55 struct timeval begin, end;
56 struct run_proc_result result;
57 int summary;
58 char *output;
61 struct run_event_script_list {
62 uint32_t num_scripts;
63 struct run_event_script *script;
64 int summary;
68 /**
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 run_proc_context *run_proc_ctx,
79 const char *script_dir, const char *debug_prog,
80 struct run_event_context **result);
82 /**
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_list(struct run_event_context *run_ctx,
91 TALLOC_CTX *mem_ctx,
92 struct run_event_script_list **output);
94 /**
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 * @param[in] continue_on_failure Whether to continue to run events on failure
124 * @return new tevent request, or NULL on failure
126 * arg_str contains optional arguments for an event.
128 struct tevent_req *run_event_send(TALLOC_CTX *mem_ctx,
129 struct tevent_context *ev,
130 struct run_event_context *run_ctx,
131 const char *event_str,
132 const char *arg_str,
133 struct timeval timeout,
134 bool continue_on_failure);
137 * @brief Async computation end to run an event
139 * @param[in] req Tevent request
140 * @param[out] perr errno in case of failure
141 * @param[in] mem_ctx Talloc memory context
142 * @param[out] output List of scripts executed and their status
143 * @return true on success, false on failure
145 bool run_event_recv(struct tevent_req *req, int *perr,
146 TALLOC_CTX *mem_ctx,
147 struct run_event_script_list **output);
149 #endif /* __CTDB_RUN_EVENT_H__ */