Skip to content

Commit

Permalink
util: Set thread name via pthreads in set_subprogram_name().
Browse files Browse the repository at this point in the history
This makes "top" and "ps" output more readable on FreeBSD at least, and
the names are also visible in debuggers.

Suggested-by: Ed Maste <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Andy Zhou <[email protected]>
Tested-by: Andy Zhou <[email protected]>
  • Loading branch information
blp committed Jul 25, 2013
1 parent dad0f0e commit 0f13e65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ AC_CHECK_DECLS([sys_siglist], [], [], [[#include <signal.h>]])
AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec, struct stat.st_mtimensec],
[], [], [[#include <sys/stat.h>]])
AC_CHECK_MEMBERS([struct ifreq.ifr_flagshigh], [], [], [[#include <net/if.h>]])
AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r])
AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r \
pthread_setname_np pthread_set_name_np])
AC_CHECK_HEADERS([mntent.h sys/statvfs.h linux/types.h linux/if_ether.h stdatomic.h])
AC_CHECK_HEADERS([net/if_mib.h], [], [], [[#include <sys/types.h>
#include <net/if.h>]])
Expand Down
8 changes: 7 additions & 1 deletion lib/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,17 @@ get_subprogram_name(void)
}

/* Sets 'name' as the name of the currently running thread or process. (This
* appears in log messages.) */
* appears in log messages and may also be visible in system process listings
* and debuggers.) */
void
set_subprogram_name(const char *name)
{
free(subprogram_name_set(xstrdup(name)));
#if HAVE_PTHREAD_SETNAME_NP
pthread_setname_np(pthread_self(), name);
#elif HAVE_PTHREAD_SET_NAME_NP
pthread_set_name_np(pthread_self(), name);
#endif
}

/* Returns a pointer to a string describing the program version. The
Expand Down

0 comments on commit 0f13e65

Please sign in to comment.