char *status_msg;
int crashes;
- subprogram_name = "monitor";
+ set_subprogram_name("monitor");
status_msg = xstrdup("healthy");
last_restart = TIME_MIN;
crashes = 0;
/* Running in new daemon process. */
proctitle_restore();
- subprogram_name = "";
+ set_subprogram_name("");
}
/* Close standard file descriptors (except any that the client has requested we
/* 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;
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]) {
}
}
+/* 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.
*/
(TYPE) (POINTER))
extern const char *program_name;
-extern const char *subprogram_name;
/* Returns the number of elements in ARRAY. */
#define ARRAY_SIZE(ARRAY) (sizeof ARRAY / sizeof *ARRAY)
#define set_program_name(name) \
set_program_name__(name, VERSION, __DATE__, __TIME__)
+const char *get_subprogram_name(void);
+void set_subprogram_name(const char *name);
+
const char *get_program_version(void);
void ovs_print_version(uint8_t min_ofp, uint8_t max_ofp);
ds_clear(s);
for (p = facilities[facility].pattern; *p != '\0'; ) {
+ const char *subprogram_name;
enum { LEFT, RIGHT } justify = RIGHT;
int pad = '0';
size_t length, field, used;
ds_put_format(s, "%lld", time_msec() - time_boot_msec());
break;
case 't':
+ subprogram_name = get_subprogram_name();
ds_put_cstr(s, subprogram_name[0] ? subprogram_name : "main");
break;
case 'T':
+ subprogram_name = get_subprogram_name();
if (subprogram_name[0]) {
ds_put_format(s, "(%s)", subprogram_name);
}
server_sock = fd;
- subprogram_name = "worker";
+ set_subprogram_name("worker");
proctitle_set("worker process for pid %lu", (unsigned long int) getppid());
VLOG_INFO("worker process started");