s4-process_single: Use pid,task_id as cluster_id in process_single just like process_...
authorAndrew Bartlett <abartlet@samba.org>
Fri, 25 Jan 2013 12:00:12 +0000 (23:00 +1100)
committerStefan Metzmacher <metze@samba.org>
Sat, 26 Jan 2013 15:13:04 +0000 (16:13 +0100)
This avoids two different process single task servers (eg the drepl
server) sharing the same server id.  The task id starts at 2^31 to
avoid collision with the fd based scheme for connections.

Fix-bug: https://bugzilla.samba.org/show_bug.cgi?id=9598

Reported-by: Matthieu Patou <mat@matws.net>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Sat Jan 26 16:13:05 CET 2013 on sn-devel-104

source4/smbd/process_single.c

index ff677500341f553be9e3cb9090b879cba4438c41..a1b785ee41b712463f7c417bddc641e3d797842d 100644 (file)
@@ -91,15 +91,20 @@ static void single_new_task(struct tevent_context *ev,
                            void (*new_task)(struct tevent_context *, struct loadparm_context *, struct server_id, void *), 
                            void *private_data)
 {
-       /* start our taskids at 1, zero is reserved for the top
-          level samba task */
-       static uint32_t taskid = 1;
+       pid_t pid = getpid();
+       /* start our taskids at MAX_INT32, the first 2^31 tasks are is reserved for fd numbers */
+       static uint32_t taskid = INT32_MAX;
        
-       /* We use 1 so we cannot collide in with cluster ids generated
-        * in the accept connection above, and unlikly to collide with
-        * PIDs from process model standard (don't run samba as
-        * init) */
-       new_task(ev, lp_ctx, cluster_id(1, taskid++), private_data);
+       /*
+        * We use the PID so we cannot collide in with cluster ids
+        * generated in other single mode tasks, and, and won't
+        * collide with PIDs from process model starndard because a the
+        * combination of pid/task_id should be unique system-wide
+        *
+        * Using the pid unaltered makes debugging of which process
+        * owns the messaging socket easier.
+        */
+       new_task(ev, lp_ctx, cluster_id(pid, taskid++), private_data);
 }