2 * Unix SMB/CIFS implementation.
3 * Wait for process death
4 * Copyright (C) Volker Lendecke 2016
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/>.
24 #include "server_id_watch.h"
25 #include "lib/util/tevent_unix.h"
27 struct server_id_watch_state
{
28 struct tevent_context
*ev
;
32 static void server_id_watch_waited(struct tevent_req
*subreq
);
34 struct tevent_req
*server_id_watch_send(TALLOC_CTX
*mem_ctx
,
35 struct tevent_context
*ev
,
38 struct tevent_req
*req
, *subreq
;
39 struct server_id_watch_state
*state
;
41 req
= tevent_req_create(mem_ctx
, &state
, struct server_id_watch_state
);
48 if (!serverid_exists(&state
->pid
)) {
50 return tevent_req_post(req
, ev
);
53 subreq
= tevent_wakeup_send(
54 state
, ev
, tevent_timeval_current_ofs(0, 500000));
55 if (tevent_req_nomem(subreq
, req
)) {
56 return tevent_req_post(req
, ev
);
58 tevent_req_set_callback(subreq
, server_id_watch_waited
, req
);
63 static void server_id_watch_waited(struct tevent_req
*subreq
)
65 struct tevent_req
*req
= tevent_req_callback_data(
66 subreq
, struct tevent_req
);
67 struct server_id_watch_state
*state
= tevent_req_data(
68 req
, struct server_id_watch_state
);
71 ok
= tevent_wakeup_recv(subreq
);
78 if (!serverid_exists(&state
->pid
)) {
83 subreq
= tevent_wakeup_send(
84 state
, state
->ev
, tevent_timeval_current_ofs(0, 500000));
85 if (tevent_req_nomem(subreq
, req
)) {
88 tevent_req_set_callback(subreq
, server_id_watch_waited
, req
);
91 int server_id_watch_recv(struct tevent_req
*req
, struct server_id
*pid
)
93 struct server_id_watch_state
*state
= tevent_req_data(
94 req
, struct server_id_watch_state
);
97 if (tevent_req_is_unix_error(req
, &err
)) {