svn commit: samba r14079 - in branches/SAMBA_4_0/source: cldap_server kdc ldap_server nbt_server smb_server smbd web_server winbind wrepl_server

metze at samba.org metze at samba.org
Thu Mar 9 17:48:41 GMT 2006


Author: metze
Date: 2006-03-09 17:48:41 +0000 (Thu, 09 Mar 2006)
New Revision: 14079

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=14079

Log:
I just found the setproctitle library from alt linux:-)

- add set_title hook to the process models
- use setproctitle library in process_model standard if available
- the the title for the task servers and on connections

metze
Modified:
   branches/SAMBA_4_0/source/cldap_server/cldap_server.c
   branches/SAMBA_4_0/source/kdc/kdc.c
   branches/SAMBA_4_0/source/ldap_server/ldap_server.c
   branches/SAMBA_4_0/source/nbt_server/nbt_server.c
   branches/SAMBA_4_0/source/smb_server/smb_server.c
   branches/SAMBA_4_0/source/smbd/process_model.h
   branches/SAMBA_4_0/source/smbd/process_model.m4
   branches/SAMBA_4_0/source/smbd/process_model.mk
   branches/SAMBA_4_0/source/smbd/process_single.c
   branches/SAMBA_4_0/source/smbd/process_standard.c
   branches/SAMBA_4_0/source/smbd/process_thread.c
   branches/SAMBA_4_0/source/smbd/service_stream.c
   branches/SAMBA_4_0/source/smbd/service_task.c
   branches/SAMBA_4_0/source/web_server/web_server.c
   branches/SAMBA_4_0/source/winbind/wb_server.c
   branches/SAMBA_4_0/source/wrepl_server/wrepl_server.c


Changeset:
Modified: branches/SAMBA_4_0/source/cldap_server/cldap_server.c
===================================================================
--- branches/SAMBA_4_0/source/cldap_server/cldap_server.c	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/cldap_server/cldap_server.c	2006-03-09 17:48:41 UTC (rev 14079)
@@ -137,6 +137,8 @@
 		return;
 	}
 
+	task_server_set_title(task, "task[cldapd]");
+
 	cldapd = talloc(task, struct cldapd_server);
 	if (cldapd == NULL) {
 		task_server_terminate(task, "cldapd: out of memory");

Modified: branches/SAMBA_4_0/source/kdc/kdc.c
===================================================================
--- branches/SAMBA_4_0/source/kdc/kdc.c	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/kdc/kdc.c	2006-03-09 17:48:41 UTC (rev 14079)
@@ -544,6 +544,8 @@
 		return;
 	}
 
+	task_server_set_title(task, "task[kdc]");
+
 	kdc = talloc(task, struct kdc_server);
 	if (kdc == NULL) {
 		task_server_terminate(task, "kdc: out of memory");

Modified: branches/SAMBA_4_0/source/ldap_server/ldap_server.c
===================================================================
--- branches/SAMBA_4_0/source/ldap_server/ldap_server.c	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/ldap_server/ldap_server.c	2006-03-09 17:48:41 UTC (rev 14079)
@@ -548,6 +548,8 @@
 	struct ldapsrv_service *ldap_service;
 	NTSTATUS status;
 
+	task_server_set_title(task, "task[ldapsrv]");
+
 	ldap_service = talloc_zero(task, struct ldapsrv_service);
 	if (ldap_service == NULL) goto failed;
 

Modified: branches/SAMBA_4_0/source/nbt_server/nbt_server.c
===================================================================
--- branches/SAMBA_4_0/source/nbt_server/nbt_server.c	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/nbt_server/nbt_server.c	2006-03-09 17:48:41 UTC (rev 14079)
@@ -41,6 +41,8 @@
 		return;
 	}
 
+	task_server_set_title(task, "task[nbtd]");
+
 	nbtsrv = talloc(task, struct nbtd_server);
 	if (nbtsrv == NULL) {
 		task_server_terminate(task, "nbtd: out of memory");

Modified: branches/SAMBA_4_0/source/smb_server/smb_server.c
===================================================================
--- branches/SAMBA_4_0/source/smb_server/smb_server.c	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/smb_server/smb_server.c	2006-03-09 17:48:41 UTC (rev 14079)
@@ -154,7 +154,7 @@
 }
 
 static const struct stream_server_ops smb_stream_ops = {
-	.name			= "smb",
+	.name			= "smbsrv",
 	.accept_connection	= smbsrv_accept,
 	.recv_handler		= smbsrv_recv,
 	.send_handler		= smbsrv_send,

Modified: branches/SAMBA_4_0/source/smbd/process_model.h
===================================================================
--- branches/SAMBA_4_0/source/smbd/process_model.h	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/smbd/process_model.h	2006-03-09 17:48:41 UTC (rev 14079)
@@ -51,9 +51,11 @@
 			 void (*)(struct event_context *, uint32_t, void *),
 			 void *);
 
-	/* function to terminate a task */
+	/* function to terminate a connection or task */
 	void (*terminate)(struct event_context *, const char *reason);
 
+	/* function to set a title for the connection or task */
+	void (*set_title)(struct event_context *, const char *title);
 };
 
 /* this structure is used by modules to determine the size of some critical types */

Modified: branches/SAMBA_4_0/source/smbd/process_model.m4
===================================================================
--- branches/SAMBA_4_0/source/smbd/process_model.m4	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/smbd/process_model.m4	2006-03-09 17:48:41 UTC (rev 14079)
@@ -24,3 +24,20 @@
 )
 
 SMB_EXT_LIB(PTHREAD,[-lpthread])
+
+AC_CHECK_HEADERS(setproctitle.h)
+AC_CHECK_LIB_EXT(setproctitle, SETPROCTITLE_LIBS, setproctitle)
+AC_MSG_CHECKING(whether to use setproctitle)
+if test x"$ac_cv_header_setproctitle_h" = x"yes" -a x"$ac_cv_lib_ext_setproctitle_setproctitle" = x"yes"; then
+	AC_MSG_RESULT(yes)
+	SMB_EXT_LIB_ENABLE(SETPROCTITLE,YES)
+	AC_DEFINE(HAVE_SETPROCTITLE,1,[Whether setproctitle() is available])
+else 
+	AC_MSG_RESULT(no)
+fi
+
+SMB_EXT_LIB(SETPROCTITLE,
+	[${SETPROCTITLE_LIBS}],
+	[${SETPROCTITLE_CFLAGS}],
+	[${SETPROCTITLE_CPPFLAGS}],
+	[${SETPROCTITLE_LDFLAGS}])

Modified: branches/SAMBA_4_0/source/smbd/process_model.mk
===================================================================
--- branches/SAMBA_4_0/source/smbd/process_model.mk	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/smbd/process_model.mk	2006-03-09 17:48:41 UTC (rev 14079)
@@ -17,6 +17,7 @@
 SUBSYSTEM = PROCESS_MODEL
 OBJ_FILES = \
 		process_standard.o
+REQUIRED_SUBSYSTEMS = EXT_LIB_SETPROCTITLE
 # End MODULE process_model_standard
 ################################################
 

Modified: branches/SAMBA_4_0/source/smbd/process_single.c
===================================================================
--- branches/SAMBA_4_0/source/smbd/process_single.c	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/smbd/process_single.c	2006-03-09 17:48:41 UTC (rev 14079)
@@ -88,12 +88,18 @@
 	DEBUG(2,("single_terminate: reason[%s]\n",reason));
 }
 
+/* called to set a title of a task or connection */
+static void single_set_title(struct event_context *ev, const char *title) 
+{
+}
+
 static const struct model_ops single_ops = {
 	.name			= "single",
 	.model_init		= single_model_init,
 	.new_task               = single_new_task,
 	.accept_connection	= single_accept_connection,
 	.terminate              = single_terminate,
+	.set_title		= single_set_title,
 };
 
 /*

Modified: branches/SAMBA_4_0/source/smbd/process_standard.c
===================================================================
--- branches/SAMBA_4_0/source/smbd/process_standard.c	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/smbd/process_standard.c	2006-03-09 17:48:41 UTC (rev 14079)
@@ -26,6 +26,7 @@
 #include "lib/events/events.h"
 #include "lib/tdb/include/tdb.h"
 #include "smb_server/smb_server.h"
+#include "lib/socket/socket.h"
 
 /* For specifiying event context to GSSAPI below */
 #include "system/kerberos.h"
@@ -33,6 +34,13 @@
 
 #include "passdb/secrets.h"
 
+#ifdef HAVE_SETPROCTITLE
+#include <setproctitle.h>
+#define SETPROCTITLE(x) setproctitle x
+#else
+#define SETPROCTITLE(x)
+#endif
+
 /*
   called when the process model is selected
 */
@@ -54,6 +62,7 @@
 	struct socket_context *sock2;
 	pid_t pid;
 	struct event_context *ev2;
+	struct socket_address *c, *s;
 
 	/* accept an incoming connection. */
 	status = socket_accept(sock, &sock2);
@@ -75,6 +84,8 @@
 		return;
 	}
 
+	pid = getpid();
+
 	/* This is now the child code. We need a completely new event_context to work with */
 	ev2 = event_context_init(NULL);
 
@@ -104,8 +115,18 @@
 	/* Ensure that the forked children do not expose identical random streams */
 	set_need_random_reseed();
 
+	/* setup the process title */
+	c = socket_get_peer_addr(sock2, ev2);
+	s = socket_get_my_addr(sock2, ev2);
+	if (s && c) {
+		SETPROCTITLE(("conn c[%s:%u] s[%s:%u] server_id[%d]",
+			      c->addr, c->port, s->addr, s->port, pid));
+	}
+	talloc_free(c);
+	talloc_free(s);
+
 	/* setup this new connection */
-	new_conn(ev2, sock2, getpid(), private);
+	new_conn(ev2, sock2, pid, private);
 
 	/* we can't return to the top level here, as that event context is gone,
 	   so we now process events in the new event context until there are no
@@ -133,6 +154,8 @@
 		return;
 	}
 
+	pid = getpid();
+
 	/* This is now the child code. We need a completely new event_context to work with */
 	ev2 = event_context_init(NULL);
 
@@ -153,8 +176,10 @@
 	/* Ensure that the forked children do not expose identical random streams */
 	set_need_random_reseed();
 
+	SETPROCTITLE(("task server_id[%d]", pid));
+
 	/* setup this new connection */
-	new_task(ev2, getpid(), private);
+	new_task(ev2, pid, private);
 
 	/* we can't return to the top level here, as that event context is gone,
 	   so we now process events in the new event context until there are no
@@ -184,6 +209,15 @@
 	exit(0);
 }
 
+/* called to set a title of a task or connection */
+static void standard_set_title(struct event_context *ev, const char *title) 
+{
+	if (title) {
+		SETPROCTITLE(("%s", title));
+	} else {
+		SETPROCTITLE((NULL));
+	}
+}
 
 static const struct model_ops standard_ops = {
 	.name			= "standard",
@@ -191,6 +225,7 @@
 	.accept_connection	= standard_accept_connection,
 	.new_task               = standard_new_task,
 	.terminate              = standard_terminate,
+	.set_title              = standard_set_title,
 };
 
 /*

Modified: branches/SAMBA_4_0/source/smbd/process_thread.c
===================================================================
--- branches/SAMBA_4_0/source/smbd/process_thread.c	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/smbd/process_thread.c	2006-03-09 17:48:41 UTC (rev 14079)
@@ -188,6 +188,11 @@
 	pthread_exit(NULL);  /* thread cleanup routine will do actual cleanup */
 }
 
+/* called to set a title of a task or connection */
+static void thread_set_title(struct event_context *ev, const char *title) 
+{
+}
+
 /*
   mutex init function for thread model
 */
@@ -520,6 +525,7 @@
 	.accept_connection	= thread_accept_connection,
 	.new_task               = thread_new_task,
 	.terminate              = thread_terminate,
+	.set_title		= thread_set_title,
 };
 
 /*

Modified: branches/SAMBA_4_0/source/smbd/service_stream.c
===================================================================
--- branches/SAMBA_4_0/source/smbd/service_stream.c	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/smbd/service_stream.c	2006-03-09 17:48:41 UTC (rev 14079)
@@ -25,6 +25,7 @@
 #include "process_model.h"
 #include "lib/events/events.h"
 #include "lib/socket/socket.h"
+#include "smbd/service.h"
 #include "smbd/service_stream.h"
 #include "lib/messaging/irpc.h"
 
@@ -143,6 +144,7 @@
 {
 	struct stream_socket *stream_socket = talloc_get_type(private, struct stream_socket);
 	struct stream_connection *srv_conn;
+	struct socket_address *c, *s;
 
 	srv_conn = talloc_zero(ev, struct stream_connection);
 	if (!srv_conn) {
@@ -174,6 +176,21 @@
 		return;
 	}
 
+	c = socket_get_peer_addr(sock, ev);
+	s = socket_get_my_addr(sock, ev);
+	if (s && c) {
+		const char *title;
+		title = talloc_asprintf(s, "conn[%s] c[%s:%u] s[%s:%u] server_id[%d]",
+					stream_socket->ops->name, 
+					c->addr, c->port, s->addr, s->port,
+					server_id);
+		if (title) {
+			stream_connection_set_title(srv_conn, title);
+		}
+	}
+	talloc_free(c);
+	talloc_free(s);
+
 	/* call the server specific accept code */
 	stream_socket->ops->accept_connection(srv_conn);
 }
@@ -271,3 +288,11 @@
 
 	return NT_STATUS_OK;
 }
+
+/*
+  setup a connection title 
+*/
+void stream_connection_set_title(struct stream_connection *conn, const char *title)
+{
+	conn->model_ops->set_title(conn->event.ctx, title);
+}

Modified: branches/SAMBA_4_0/source/smbd/service_task.c
===================================================================
--- branches/SAMBA_4_0/source/smbd/service_task.c	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/smbd/service_task.c	2006-03-09 17:48:41 UTC (rev 14079)
@@ -23,6 +23,7 @@
 #include "includes.h"
 #include "process_model.h"
 #include "lib/events/events.h"
+#include "smbd/service.h"
 #include "smbd/service_task.h"
 #include "lib/messaging/irpc.h"
 
@@ -90,3 +91,10 @@
 	return NT_STATUS_OK;
 }
 
+/*
+  setup a task title 
+*/
+void task_server_set_title(struct task_server *task, const char *title)
+{
+	task->model_ops->set_title(task->event_ctx, title);
+}

Modified: branches/SAMBA_4_0/source/web_server/web_server.c
===================================================================
--- branches/SAMBA_4_0/source/web_server/web_server.c	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/web_server/web_server.c	2006-03-09 17:48:41 UTC (rev 14079)
@@ -238,6 +238,8 @@
 	uint16_t port = lp_web_port();
 	const struct model_ops *model_ops;
 
+	task_server_set_title(task, "task[websrv]");
+
 	/* run the web server as a single process */
 	model_ops = process_model_byname("single");
 	if (!model_ops) goto failed;

Modified: branches/SAMBA_4_0/source/winbind/wb_server.c
===================================================================
--- branches/SAMBA_4_0/source/winbind/wb_server.c	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/winbind/wb_server.c	2006-03-09 17:48:41 UTC (rev 14079)
@@ -116,6 +116,8 @@
 	struct wbsrv_service *service;
 	struct wbsrv_listen_socket *listen_socket;
 
+	task_server_set_title(task, "task[winbind]");
+
 	/* within the winbind task we want to be a single process, so
 	   ask for the single process model ops and pass these to the
 	   stream_setup_socket() call. */

Modified: branches/SAMBA_4_0/source/wrepl_server/wrepl_server.c
===================================================================
--- branches/SAMBA_4_0/source/wrepl_server/wrepl_server.c	2006-03-09 17:39:24 UTC (rev 14078)
+++ branches/SAMBA_4_0/source/wrepl_server/wrepl_server.c	2006-03-09 17:48:41 UTC (rev 14079)
@@ -437,6 +437,8 @@
 	NTSTATUS status;
 	struct wreplsrv_service *service;
 
+	task_server_set_title(task, "task[wreplsrv]");
+
 	service = talloc_zero(task, struct wreplsrv_service);
 	if (!service) {
 		task_server_terminate(task, "wreplsrv_task_init: out of memory");



More information about the samba-cvs mailing list