Add support of changing process title on starting to serve a new client. A new configure option --with-setproctitle could be used to enable this feature.
Signed-off-by: Dmitry V. Levin <[email protected]> --- Makefile.am | 2 +- configure.ac | 24 ++++++++++++++++++++++++ nbd-server.c | 9 +++++++++ 3 files changed, 34 insertions(+), 1 deletions(-) diff --git a/Makefile.am b/Makefile.am index 105ae72..b194769 100644 --- a/Makefile.am +++ b/Makefile.am @@ -12,7 +12,7 @@ nbd_trdump_SOURCES = nbd-trdump.c cliserv.h nbd.h nbd_server_CFLAGS = @CFLAGS@ @GLIB_CFLAGS@ nbd_tester_client_CFLAGS = @CFLAGS@ @GLIB_CFLAGS@ nbd_trdump_CFLAGS = @CFLAGS@ @GLIB_CFLAGS@ -nbd_server_LDADD = @GLIB_LIBS@ +nbd_server_LDADD = @GLIB_LIBS@ @SETPROCTITLE_LIBS@ nbd_tester_client_LDADD = @GLIB_LIBS@ make_integrityhuge_SOURCES = make-integrityhuge.c cliserv.h nbd.h EXTRA_DIST = gznbd simple_test integrity-test.tr integrityhuge-test.tr maketr diff --git a/configure.ac b/configure.ac index 0a867df..75390f7 100644 --- a/configure.ac +++ b/configure.ac @@ -129,6 +129,30 @@ AC_SUBST(NBD_CLIENT_NAME) AC_SEARCH_LIBS(bind, socket,, AC_MSG_ERROR([Could not find an implementation of the bind() system call])) AC_SEARCH_LIBS(inet_ntoa, nsl,, AC_MSG_ERROR([Could not find an implementation of the inet_ntoa() system call])) AC_SEARCH_LIBS(daemon, resolv,, AC_MSG_ERROR([Could not find an implementation of the daemon() system call])) + +AC_ARG_WITH([setproctitle], + [AC_HELP_STRING([--with-setproctitle], + [Use setproctitle in nbd-server (default is no)])], + [use_setproctitle=$withval], + [use_setproctitle=no] + ) +SETPROCTITLE_LIBS= +AC_MSG_CHECKING([whether to use setproctitle in nbd-server]) +AS_IF([test "x$use_setproctitle" = xyes], + [AC_MSG_RESULT([yes]) + AC_DEFINE([USE_SETPROCTITLE], [1], + [Define to 1 if you want nbd-server to use setproctitle]) + AC_CHECK_HEADERS([setproctitle.h]) + AC_SEARCH_LIBS([setproctitle],,, + [AC_CHECK_LIB([setproctitle], [setproctitle], + [SETPROCTITLE_LIBS="-lsetproctitle"], + [AC_MSG_ERROR([setproctitle not found])])] + ) + ], + [AC_MSG_RESULT([no])] + ) +AC_SUBST([SETPROCTITLE_LIBS]) + AC_CHECK_HEADERS([sys/mount.h],,, [[#include <sys/param.h> ]]) diff --git a/nbd-server.c b/nbd-server.c index 6bde787..1c21907 100644 --- a/nbd-server.c +++ b/nbd-server.c @@ -107,6 +107,12 @@ #include <sdp_inet.h> #endif +#if USE_SETPROCTITLE +# ifdef HAVE_SETPROCTITLE_H +# include <setproctitle.h> +# endif +#endif + /** Default position of the config file */ #ifndef SYSCONFDIR #define SYSCONFDIR "/etc" @@ -2249,6 +2255,9 @@ handle_connection(GArray *servers, int net, SERVER *serve, CLIENT *client) msg4(LOG_INFO, "Starting to serve %s for %s", client->exportname, client->clientname); +#if USE_SETPROCTITLE + setproctitle("%s", client->clientname); +#endif serveconnection(client); exit(EXIT_SUCCESS); -- 1.7.8.4 -- ldv ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Nbd-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nbd-general
