2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-30 22:05:19 +00:00

util: Make subprogram_name thread-specific.

Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
Ben Pfaff
2013-07-12 14:18:01 -07:00
parent 4c694ff745
commit bc9fb3a9cd
5 changed files with 29 additions and 7 deletions

View File

@@ -38,9 +38,9 @@ COVERAGE_DEFINE(util_xalloc);
/* argv[0] without directory names. */
const char *program_name;
/* Ordinarily "" but set to "monitor" for a monitor process or "worker" for a
* worker process. */
const char *subprogram_name = "";
/* Name for the currently running thread or process, for log messages, process
* listings, and debuggers. */
DEFINE_PER_THREAD_MALLOCED_DATA(char *, subprogram_name);
/* --version option output. */
static char *program_version;
@@ -281,6 +281,7 @@ ovs_error(int err_no, const char *format, ...)
void
ovs_error_valist(int err_no, const char *format, va_list args)
{
const char *subprogram_name = get_subprogram_name();
int save_errno = errno;
if (subprogram_name[0]) {
@@ -385,6 +386,22 @@ set_program_name__(const char *argv0, const char *version, const char *date,
}
}
/* Returns the name of the currently running thread or process. */
const char *
get_subprogram_name(void)
{
const char *name = subprogram_name_get();
return name ? name : "";
}
/* Sets 'name' as the name of the currently running thread or process. (This
* appears in log messages.) */
void
set_subprogram_name(const char *name)
{
free(subprogram_name_set(xstrdup(name)));
}
/* Returns a pointer to a string describing the program version. The
* caller must not modify or free the returned string.
*/