From 3f829cfd05fcc94782c134e11311de99870402bc Mon Sep 17 00:00:00 2001 From: Mark Janssen Date: Fri, 11 Aug 2006 15:16:45 +0000 Subject: [PATCH] Reworked setproctitle stuff git-svn-id: https://proxytunnel.svn.sourceforge.net/svnroot/proxytunnel/trunk/proxytunnel@128 bc163920-b10d-0410-b2c5-a5491ca2ceef --- proxytunnel.c | 18 ++++++++++++------ setproctitle.c | 12 ++++++++++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/proxytunnel.c b/proxytunnel.c index d5f45b0..ca32cfa 100755 --- a/proxytunnel.c +++ b/proxytunnel.c @@ -228,8 +228,10 @@ void do_daemon() signal(SIGCHLD,SIG_IGN); #ifdef SETPROCTITLE - if( args_info.proctitle_given ) - setproctitle( "%s [daemon]\0", args_info.proctitle_arg ); + if( ! args_info.proctitle_given ) + setproctitle( "[daemon]\0" ); + else + setproctitle( "\0" ); #else if( args_info.proctitle_given ) message( "Setting process-title is not supported in this build\n"); @@ -299,8 +301,10 @@ void do_daemon() do_ssl(); #endif #ifdef SETPROCTITLE - if( args_info.proctitle_given ) - setproctitle( "%s [cpio]\0", args_info.proctitle_arg ); + if( ! args_info.proctitle_given ) + setproctitle( "[cpio]\0" ); + else + setproctitle( "\0" ); #else if( args_info.proctitle_given ) message( "Setting process-title is not supported in this build\n"); @@ -400,8 +404,10 @@ int main( int argc, char *argv[] ) do_ssl(); #endif #ifdef SETPROCTITLE - if( args_info.proctitle_given ) - setproctitle( "%s [cpio]\0", args_info.proctitle_arg ); + if( ! args_info.proctitle_given ) + setproctitle( "[cpio]\0" ); + else + setproctitle( "\0" ); #else if( args_info.proctitle_given ) message( "Setting process-title is not supported in this build\n"); diff --git a/setproctitle.c b/setproctitle.c index 7fc6edb..7fe9178 100644 --- a/setproctitle.c +++ b/setproctitle.c @@ -137,11 +137,19 @@ setproctitle(const char *fmt, ...) return; #endif - strlcpy(buf, __progname, sizeof(buf)); + if( args_info.proctitle_given ) + strlcpy(buf, args_info.proctitle_arg, sizeof(buf)); + else + { + strlcpy(buf, __progname, sizeof(buf)); + strlcat(buf, ": ", sizeof(buf)); + + } + va_start(ap, fmt); if (fmt != NULL) { - len = strlcat(buf, ": ", sizeof(buf)); + len = strlen(buf); if (len < sizeof(buf)) vsnprintf(buf + len, sizeof(buf) - len , fmt, ap); }