From 6e76dfcd595bbdef7628634340a7bda19b95fac4 Mon Sep 17 00:00:00 2001 From: miker Date: Tue, 12 Jun 2007 01:23:04 +0000 Subject: [PATCH] Patch from Scott McKellar: This small and inoffensive patch concerns two functions in utils.c: init_proc_title() and set_proc_title(). 1. I added some comments to explain what these functions do for a living. 2. I declared the __global_argv and __global_argv_size variables static. No other source file refers to them. 3. I removed the leading underscores from their names. Identifiers beginning with two underscores are reserved for the implementation. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@942 9efc2488-bf62-4759-914b-345cdb29e865 --- src/utils/utils.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/utils/utils.c b/src/utils/utils.c index 3282b9f..47b3d2f 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -25,29 +25,37 @@ inline void* safe_malloc( int size ) { return ptr; } - -char** __global_argv = NULL; -int __global_argv_size = 0; +/**************** + The following static variables, and the following two functions, + overwrite the argv array passed to main(). The purpose is to + change the program name as reported by ps and similar utilities. + + Warning: this code makes the non-portable assumption that the + strings to which argv[] points are contiguous in memory. The + C Standard makes no such guarantee. + ****************/ +static char** global_argv = NULL; +static int global_argv_size = 0; int init_proc_title( int argc, char* argv[] ) { - __global_argv = argv; + global_argv = argv; int i = 0; while( i < argc ) { - int len = strlen( __global_argv[i]); - bzero( __global_argv[i++], len ); - __global_argv_size += len; + int len = strlen( global_argv[i]); + bzero( global_argv[i++], len ); + global_argv_size += len; } - __global_argv_size -= 2; + global_argv_size -= 2; return 0; } int set_proc_title( char* format, ... ) { VA_LIST_TO_STRING(format); - bzero( *(__global_argv), __global_argv_size ); - return snprintf( *(__global_argv), __global_argv_size, VA_BUF ); + bzero( *(global_argv), global_argv_size ); + return snprintf( *(global_argv), global_argv_size, VA_BUF ); } -- 2.43.2