/src/samba/source3/lib/serverid.c
Line | Count | Source |
1 | | /* |
2 | | Unix SMB/CIFS implementation. |
3 | | Implementation of a reliable server_exists() |
4 | | Copyright (C) Volker Lendecke 2010 |
5 | | |
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. |
10 | | |
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. |
15 | | |
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/>. |
18 | | */ |
19 | | |
20 | | #include "replace.h" |
21 | | #include "lib/util/samba_util.h" |
22 | | #include "lib/util/server_id.h" |
23 | | #include "lib/util/debug.h" |
24 | | #include "source3/lib/util_procid.h" |
25 | | #include "source3/param/param_proto.h" |
26 | | #include "serverid.h" |
27 | | #include "ctdbd_conn.h" |
28 | | #include "lib/messages_ctdb.h" |
29 | | #include "lib/messaging/messages_dgm.h" |
30 | | |
31 | | static bool serverid_exists_local(const struct server_id *id) |
32 | 0 | { |
33 | 0 | bool exists = process_exists_by_pid(id->pid); |
34 | 0 | uint64_t unique; |
35 | 0 | int ret; |
36 | |
|
37 | 0 | if (!exists) { |
38 | 0 | return false; |
39 | 0 | } |
40 | | |
41 | 0 | if (id->unique_id == SERVERID_UNIQUE_ID_NOT_TO_VERIFY) { |
42 | 0 | return true; |
43 | 0 | } |
44 | | |
45 | 0 | ret = messaging_dgm_get_unique(id->pid, &unique); |
46 | 0 | if (ret != 0) { |
47 | 0 | if (ret == EACCES) { |
48 | 0 | DBG_ERR("Access denied on msg.lock file for PID %jd, " |
49 | 0 | "assuming process still exists\n", |
50 | 0 | (intmax_t)id->pid); |
51 | 0 | return true; |
52 | 0 | } |
53 | 0 | return false; |
54 | 0 | } |
55 | | |
56 | 0 | return (unique == id->unique_id); |
57 | 0 | } |
58 | | |
59 | | bool serverid_exists(const struct server_id *id) |
60 | 0 | { |
61 | 0 | if (procid_is_local(id)) { |
62 | 0 | return serverid_exists_local(id); |
63 | 0 | } |
64 | | |
65 | 0 | if (lp_clustering()) { |
66 | 0 | return ctdbd_process_exists(messaging_ctdb_connection(), |
67 | 0 | id->vnn, id->pid, id->unique_id); |
68 | 0 | } |
69 | | |
70 | 0 | return false; |
71 | 0 | } |