@@ -3767,7 +3767,13 @@ char * mkstr_dynamic(const char *fmt_dynamic, const char *fmt_reference, ...)
37673767static void vupslog (int priority , const char * fmt , va_list va , int use_strerror )
37683768{
37693769 int ret , errno_orig = errno ;
3770+ #ifdef HAVE_VA_COPY_VARIANT
3771+ size_t bufsize = 128 ;
3772+ #else
3773+ /* err on the safe(r) side, as re-runs can truncate
3774+ * the output when varargs are re-used */
37703775 size_t bufsize = LARGEBUF ;
3776+ #endif
37713777 char * buf = (char * )xcalloc (bufsize , sizeof (char ));
37723778
37733779 /* Be pedantic about our limitations */
@@ -3827,7 +3833,7 @@ static void vupslog(int priority, const char *fmt, va_list va, int use_strerror)
38273833 * Based on https://stackoverflow.com/a/72981237/4715872
38283834 */
38293835 if (bufsize < SIZE_MAX /2 ) {
3830- size_t newbufsize = bufsize * 2 ;
3836+ size_t newbufsize = bufsize < LARGEBUF ? LARGEBUF : bufsize * 2 ;
38313837 if (ret > 0 ) {
38323838 /* Be generous, we snprintfcat() some
38333839 * suffixes, prefix a timestamp, etc. */
@@ -4819,10 +4825,16 @@ void nut_prepare_search_paths(void) {
48194825 size_t count_builtin = 0 , count_filtered = 0 , i , j , index = 0 ;
48204826 const char * * filtered_search_paths ;
48214827 DIR * dp ;
4828+ #if HAVE_DECL_REALPATH
4829+ /* Per docs, buffer must be at least PATH_MAX bytes */
4830+ char realpath_buf [NUT_PATH_MAX + 1 ] = {0 }, * realpath_dirname = NULL ;
4831+ #endif
48224832
48234833 /* As a starting point, allow at least as many items as before */
48244834 /* TODO: somehow extend (xrealloc?) if we mix other paths later */
4825- for (i = 0 ; search_paths_builtin [i ] != NULL ; i ++ ) {}
4835+ for (i = 0 ; search_paths_builtin [i ] != NULL ; i ++ ) {
4836+ upsdebugx (7 , "counting search_paths_builtin[%d] : %s" , i , search_paths_builtin [i ]);
4837+ }
48264838 count_builtin = i + 1 ; /* +1 for the NULL */
48274839
48284840 /* Bytes inside should all be zeroed... */
@@ -4834,22 +4846,35 @@ void nut_prepare_search_paths(void) {
48344846 int dupe = 0 ;
48354847 const char * dirname = search_paths_builtin [i ];
48364848
4849+ upsdebugx (7 , "%s: checking search_paths_builtin[%" PRIuSIZE " of %" PRIuSIZE "] : %s" ,
4850+ __func__ , i , count_builtin - 1 , NUT_STRARG (dirname ));
48374851 if ((dp = opendir (dirname )) == NULL ) {
48384852 upsdebugx (5 , "%s: SKIP "
48394853 "unreachable directory #%" PRIuSIZE " : %s" ,
4840- __func__ , index ++ , dirname );
4854+ __func__ , index , NUT_STRARG (dirname ));
4855+ index ++ ;
48414856 continue ;
48424857 }
48434858 index ++ ;
48444859
48454860#if HAVE_DECL_REALPATH
48464861 /* allocates the buffer we free() later */
4847- dirname = (const char * )realpath (dirname , NULL );
4862+ upsdebugx (7 , "%s: call realpath()" , __func__ );
4863+ errno = 0 ;
4864+ realpath_dirname = realpath (dirname , realpath_buf );
4865+ if (errno || !realpath_dirname )
4866+ upsdebug_with_errno (7 , "%s: realpath() failed and returned: %s" , __func__ , NUT_STRARG (realpath_dirname ));
4867+ else
4868+ upsdebugx (7 , "%s: realpath() returned: %s" , __func__ , NUT_STRARG (realpath_dirname ));
4869+ if (realpath_dirname )
4870+ dirname = (const char * )realpath_dirname ;
48484871#endif
48494872
48504873 /* Revise for duplicates */
48514874 /* Note: (count_filtered == 0) means first existing dir seen, no hassle */
48524875 for (j = 0 ; j < count_filtered ; j ++ ) {
4876+ upsdebugx (7 , "%s: check for duplicates filtered_search_paths[%" PRIuSIZE " of %" PRIuSIZE "] : %s" ,
4877+ __func__ , j , count_filtered , NUT_STRARG (filtered_search_paths [j ]));
48534878 if (!strcmp (filtered_search_paths [j ], dirname )) {
48544879#if HAVE_DECL_REALPATH
48554880 if (strcmp (search_paths_builtin [i ], dirname )) {
@@ -4984,7 +5009,7 @@ static char * get_libname_in_dir(const char* base_libname, size_t base_libname_l
49845009 char current_test_path [NUT_PATH_MAX + 1 ];
49855010
49865011 upsdebugx (3 , "%s('%s', %" PRIuSIZE ", '%s', %i): Entering method..." ,
4987- __func__ , base_libname , base_libname_length , dirname , index );
5012+ __func__ , NUT_STRARG ( base_libname ) , base_libname_length , NUT_STRARG ( dirname ) , index );
49885013
49895014 memset (current_test_path , 0 , sizeof (current_test_path ));
49905015
@@ -5117,7 +5142,7 @@ static char * get_libname_in_pathset(const char* base_libname, size_t base_libna
51175142 /* First call to tokenization passes the string, others pass NULL */
51185143 pathset_tmp = xstrdup (pathset );
51195144 upsdebugx (4 , "%s: Looking for lib %s in a colon-separated path set" ,
5120- __func__ , base_libname );
5145+ __func__ , NUT_STRARG ( base_libname ) );
51215146 while (NULL != (onedir = strtok ( (onedir ? NULL : pathset_tmp ), ":" ))) {
51225147 libname_path = get_libname_in_dir (base_libname , base_libname_length , onedir , (* counter )++ );
51235148 if (libname_path != NULL )
@@ -5153,7 +5178,7 @@ char * get_libname(const char* base_libname)
51535178 size_t base_libname_length = strlen (base_libname );
51545179 struct stat st ;
51555180
5156- upsdebugx (3 , "%s('%s'): Entering method..." , __func__ , base_libname );
5181+ upsdebugx (3 , "%s('%s'): Entering method..." , __func__ , NUT_STRARG ( base_libname ) );
51575182
51585183 /* First, check for an exact hit by absolute/relative path
51595184 * if `base_libname` includes path separator character(s) */
0 commit comments