s3: Add processes_exist
authorVolker Lendecke <vl@samba.org>
Wed, 26 Oct 2011 10:18:21 +0000 (12:18 +0200)
committerVolker Lendecke <vlendec@samba.org>
Thu, 27 Oct 2011 18:28:31 +0000 (20:28 +0200)
source3/include/proto.h
source3/lib/util.c

index 6ff2854ca2618dbfa9127ba4190faf319365fc5f..39a5d03d763b022e480ee6c5d7ee230c917eaae1 100644 (file)
@@ -512,6 +512,8 @@ int interpret_protocol(const char *str,int def);
 char *automount_lookup(TALLOC_CTX *ctx, const char *user_name);
 char *automount_lookup(TALLOC_CTX *ctx, const char *user_name);
 bool process_exists(const struct server_id pid);
+bool processes_exist(const struct server_id *pids, int num_pids,
+                    bool *results);
 const char *uidtoname(uid_t uid);
 char *gidtoname(gid_t gid);
 uid_t nametouid(const char *name);
index f547ec2a5649e9b1f75ba80d5aec27fac3008950..9b9d34c22f4766acd2b3776e756e2f109f3d686d 100644 (file)
@@ -657,6 +657,72 @@ bool process_exists(const struct server_id pid)
 #endif
 }
 
+bool processes_exist(const struct server_id *pids, int num_pids,
+                    bool *results)
+{
+       struct server_id *remote_pids = NULL;
+       int *remote_idx = NULL;
+       bool *remote_results = NULL;
+       int i, num_remote_pids;
+       bool result = false;
+
+       remote_pids = talloc_array(talloc_tos(), struct server_id, num_pids);
+       if (remote_pids == NULL) {
+               goto fail;
+       }
+       remote_idx = talloc_array(talloc_tos(), int, num_pids);
+       if (remote_idx == NULL) {
+               goto fail;
+       }
+       remote_results = talloc_array(talloc_tos(), bool, num_pids);
+       if (remote_results == NULL) {
+               goto fail;
+       }
+
+       num_remote_pids = 0;
+
+       for (i=0; i<num_pids; i++) {
+               if (procid_is_me(&pids[i])) {
+                       results[i] = true;
+                       continue;
+               }
+               if (procid_is_local(&pids[i])) {
+                       results[i] = ((kill(pids[i].pid,0) == 0) ||
+                                     (errno != ESRCH));
+                       continue;
+               }
+
+               remote_pids[num_remote_pids] = pids[i];
+               remote_idx[num_remote_pids] = i;
+               num_remote_pids += 1;
+       }
+
+       if (num_remote_pids != 0) {
+#ifdef CLUSTER_SUPPORT
+               if (!ctdb_processes_exist(messaging_ctdbd_connection(),
+                                         remote_pids, num_remote_pids,
+                                         remote_results)) {
+                       goto fail;
+               }
+#else
+               for (i=0; i<num_remote_pids; i++) {
+                       remote_results[i] = false;
+               }
+#endif
+
+               for (i=0; i<num_remote_pids; i++) {
+                       results[remote_idx[i]] = remote_results[i];
+               }
+       }
+
+       result = true;
+fail:
+       TALLOC_FREE(remote_results);
+       TALLOC_FREE(remote_idx);
+       TALLOC_FREE(remote_pids);
+       return result;
+}
+
 /*******************************************************************
  Convert a uid into a user name.
 ********************************************************************/