server_id: Change format to vnn:pid.task_id, pid.task_id or pid
authorAndrew Bartlett <abartlet@samba.org>
Thu, 9 Jun 2011 01:18:15 +0000 (11:18 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 9 Jun 2011 10:40:09 +0000 (12:40 +0200)
This helps ensure the string cannot be ambiguous, while also ensuring
that it remains simple in the non-cluster case.

The asymmetry of reading get_my_vnn() but writing based on
NONCLUSTER_VNN is acceptable because in the non-clustered case, they
are equal, and in the clustered case we will print the full string.

Andrew Bartlett

lib/util/server_id.c
source3/lib/util.c

index a67c40eb193c437d748d1eafe8d7661e2283be3a..195deeac7c152ed5864fa17fcb2df7ff4031b84f 100644 (file)
@@ -26,9 +26,14 @@ char *server_id_str(TALLOC_CTX *mem_ctx, const struct server_id *id)
                return talloc_asprintf(mem_ctx,
                                       "%llu",
                                       (unsigned long long)id->pid);
+       } else if (id->vnn == NONCLUSTER_VNN) {
+               return talloc_asprintf(mem_ctx,
+                                      "%llu.%u",
+                                      (unsigned long long)id->pid,
+                                      (unsigned)id->task_id);
        } else {
                return talloc_asprintf(mem_ctx,
-                                      "%u:%llu:%u",
+                                      "%u:%llu.%u",
                                       (unsigned)id->vnn,
                                       (unsigned long long)id->pid,
                                       (unsigned)id->task_id);
index 5fb8a41dae13004b659827951e3ea238d160a84b..499f5f7f6b0852f02ba38ece414d3aade1f503f2 100644 (file)
@@ -1971,16 +1971,26 @@ struct server_id interpret_pid(const char *pid_string)
 
        ZERO_STRUCT(result);
 
-       /* We accept either the 2 or 3 componet form for backwards compatability in the smbstatus command line tool */
-       if (sscanf(pid_string, "%u:%llu:%u", &vnn, &pid, &task_id) >= 2) {
+       /* We accept various forms with 1, 2 or 3 component forms
+        * because the server_id_str() can print different forms, and
+        * we want backwards compatibility for scripts that may call
+        * smbclient. */
+       if (sscanf(pid_string, "%u:%llu.%u", &vnn, &pid, &task_id) == 3) {
                result.vnn = vnn;
                result.pid = pid;
                result.task_id = task_id;
+       } else if (sscanf(pid_string, "%u:%llu", &vnn, &pid) == 2) {
+               result.vnn = vnn;
+               result.pid = pid;
+               result.task_id = 0;
+       } else if (sscanf(pid_string, "%llu.%u", &pid, &task_id) == 2) {
+               result.vnn = get_my_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;
-       }
-       else {
+       } else {
                result.vnn = NONCLUSTER_VNN;
                result.pid = (uint64_t)-1;
        }