diff options
author | Stefan Metzmacher <metze@samba.org> | 2006-03-09 17:48:41 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:56:49 -0500 |
commit | 651ca6553edadb2b97339fd3c112fdb6ef6c08bc (patch) | |
tree | 240f124aa3dcf08304c7f4bed6c2e0bd22ed83ed /source4/smbd | |
parent | 60823d1878563c398373ff2c761dd91a588af3b5 (diff) | |
download | samba-651ca6553edadb2b97339fd3c112fdb6ef6c08bc.tar.gz samba-651ca6553edadb2b97339fd3c112fdb6ef6c08bc.tar.bz2 samba-651ca6553edadb2b97339fd3c112fdb6ef6c08bc.zip |
r14079: 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
(This used to be commit 526f20bbecc9bbd607595637c15fc4001d3f0c70)
Diffstat (limited to 'source4/smbd')
-rw-r--r-- | source4/smbd/process_model.h | 4 | ||||
-rw-r--r-- | source4/smbd/process_model.m4 | 17 | ||||
-rw-r--r-- | source4/smbd/process_model.mk | 1 | ||||
-rw-r--r-- | source4/smbd/process_single.c | 6 | ||||
-rw-r--r-- | source4/smbd/process_standard.c | 39 | ||||
-rw-r--r-- | source4/smbd/process_thread.c | 6 | ||||
-rw-r--r-- | source4/smbd/service_stream.c | 25 | ||||
-rw-r--r-- | source4/smbd/service_task.c | 8 |
8 files changed, 103 insertions, 3 deletions
diff --git a/source4/smbd/process_model.h b/source4/smbd/process_model.h index 4080d2d4b6..d525ce9cdd 100644 --- a/source4/smbd/process_model.h +++ b/source4/smbd/process_model.h @@ -51,9 +51,11 @@ struct model_ops { 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 */ diff --git a/source4/smbd/process_model.m4 b/source4/smbd/process_model.m4 index 673d5e5e2b..ea7373e4f7 100644 --- a/source4/smbd/process_model.m4 +++ b/source4/smbd/process_model.m4 @@ -24,3 +24,20 @@ AC_MSG_RESULT(no) ) 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}]) diff --git a/source4/smbd/process_model.mk b/source4/smbd/process_model.mk index 22083a7a87..e09db012fb 100644 --- a/source4/smbd/process_model.mk +++ b/source4/smbd/process_model.mk @@ -17,6 +17,7 @@ INIT_FUNCTION = process_model_standard_init SUBSYSTEM = PROCESS_MODEL OBJ_FILES = \ process_standard.o +REQUIRED_SUBSYSTEMS = EXT_LIB_SETPROCTITLE # End MODULE process_model_standard ################################################ diff --git a/source4/smbd/process_single.c b/source4/smbd/process_single.c index 3e60b6bd5b..1ca2718454 100644 --- a/source4/smbd/process_single.c +++ b/source4/smbd/process_single.c @@ -88,12 +88,18 @@ static void single_terminate(struct event_context *ev, const char *reason) 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, }; /* diff --git a/source4/smbd/process_standard.c b/source4/smbd/process_standard.c index dadbe5bf80..798d0883c8 100644 --- a/source4/smbd/process_standard.c +++ b/source4/smbd/process_standard.c @@ -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 @@ static void standard_accept_connection(struct event_context *ev, 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 @@ static void standard_accept_connection(struct event_context *ev, 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 @@ static void standard_accept_connection(struct event_context *ev, /* 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 @@ static void standard_new_task(struct event_context *ev, 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 @@ static void standard_new_task(struct event_context *ev, /* 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 @@ static void standard_terminate(struct event_context *ev, const char *reason) 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 @@ static const struct model_ops standard_ops = { .accept_connection = standard_accept_connection, .new_task = standard_new_task, .terminate = standard_terminate, + .set_title = standard_set_title, }; /* diff --git a/source4/smbd/process_thread.c b/source4/smbd/process_thread.c index 10b7051356..bab630ef22 100644 --- a/source4/smbd/process_thread.c +++ b/source4/smbd/process_thread.c @@ -188,6 +188,11 @@ static void thread_terminate(struct event_context *event_ctx, const char *reason 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 @@ static const struct model_ops thread_ops = { .accept_connection = thread_accept_connection, .new_task = thread_new_task, .terminate = thread_terminate, + .set_title = thread_set_title, }; /* diff --git a/source4/smbd/service_stream.c b/source4/smbd/service_stream.c index 13cb570e0c..59e87304d3 100644 --- a/source4/smbd/service_stream.c +++ b/source4/smbd/service_stream.c @@ -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 @@ static void stream_new_connection(struct event_context *ev, { 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 @@ static void stream_new_connection(struct event_context *ev, 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 @@ NTSTATUS stream_setup_socket(struct event_context *event_context, 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); +} diff --git a/source4/smbd/service_task.c b/source4/smbd/service_task.c index c6784e7132..2963bac425 100644 --- a/source4/smbd/service_task.c +++ b/source4/smbd/service_task.c @@ -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 @@ NTSTATUS task_server_startup(struct event_context *event_ctx, 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); +} |