s3-lib Read and write the full struct server_id (except the unique_id)
authorAndrew Bartlett <abartlet@samba.org>
Wed, 8 Jun 2011 02:47:59 +0000 (12:47 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 8 Jun 2011 04:40:52 +0000 (14:40 +1000)
This is in preperation for making this code the common, only reader
and writer of this structure.

Andrew Bartlett

source3/lib/util.c

index 0b28c913ad45978eeaac3d15c4933a78dafe1211..4d45c0e3c2dba6b5758624bcad275ff9a3faea35 100644 (file)
@@ -1966,24 +1966,21 @@ bool procid_is_me(const struct server_id *pid)
 struct server_id interpret_pid(const char *pid_string)
 {
        struct server_id result;
-       int pid;
-       unsigned int vnn;
-       if (sscanf(pid_string, "%u:%d", &vnn, &pid) == 2) {
+       unsigned long long pid;
+       unsigned int vnn, task_id;
+       if (sscanf(pid_string, "%u:%llu:%u", &vnn, &pid, &task_id) == 2) {
                result.vnn = vnn;
                result.pid = pid;
+               result.task_id = task_id;
        }
        else if (sscanf(pid_string, "%d", &pid) == 1) {
                result.vnn = get_my_vnn();
                result.pid = pid;
+               result.task_id = 0;
        }
        else {
                result.vnn = NONCLUSTER_VNN;
-               result.pid = -1;
-       }
-       /* Assigning to result.pid may have overflowed
-          Map negative pid to -1: i.e. error */
-       if (result.pid < 0) {
-               result.pid = -1;
+               result.pid = (uint64_t)-1;
        }
        result.unique_id = 0;
        return result;
@@ -1991,16 +1988,17 @@ struct server_id interpret_pid(const char *pid_string)
 
 char *procid_str(TALLOC_CTX *mem_ctx, const struct server_id *pid)
 {
-       if (pid->vnn == NONCLUSTER_VNN) {
+       if (pid->vnn == NONCLUSTER_VNN && pid->task_id == 0) {
                return talloc_asprintf(mem_ctx,
-                               "%d",
-                               (int)pid->pid);
+                               "%llu",
+                               (unsigned long long)pid->pid);
        }
        else {
                return talloc_asprintf(mem_ctx,
-                                       "%u:%d",
-                                       (unsigned)pid->vnn,
-                                       (int)pid->pid);
+                                      "%u:%llu:%u",
+                                      (unsigned)pid->vnn,
+                                      (unsigned long long)pid->pid,
+                                      (unsigned)pid->task_id);
        }
 }
 
@@ -2011,7 +2009,7 @@ char *procid_str_static(const struct server_id *pid)
 
 bool procid_valid(const struct server_id *pid)
 {
-       return (pid->pid != -1);
+       return (pid->pid != (uint64_t)-1);
 }
 
 bool procid_is_local(const struct server_id *pid)