pthread_cond_init(peerhash_cond, &attrs);
pthread_condattr_destroy(&attrs);
-#ifdef GNU_LINUX
- pthread_setname_np(fpt->thread, "bgpd_ka");
-#elif defined(OPEN_BSD)
- pthread_set_name_np(fpt->thread, "bgpd_ka");
-#endif
+ frr_pthread_set_name(fpt, NULL, "bgpd_ka");
/* initialize peer hashtable */
peerhash = hash_create_size(2048, peer_hash_key, peer_hash_cmp, NULL);
.start = bgp_keepalives_start,
.stop = bgp_keepalives_stop,
};
- frr_pthread_new(&io, "BGP I/O thread");
- frr_pthread_new(&ka, "BGP Keepalives thread");
+ frr_pthread_new(&io, "BGP I/O thread", "bgpd_io");
+ frr_pthread_new(&ka, "BGP Keepalives thread", "bgpd_ka");
}
void bgp_pthreads_run()
}
struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr,
- const char *name)
+ const char *name, const char *os_name)
{
static struct frr_pthread holder = {};
struct frr_pthread *fpt = NULL;
fpt->attr = *attr;
name = (name ? name : "Anonymous thread");
fpt->name = XSTRDUP(MTYPE_FRR_PTHREAD, name);
+ if (os_name)
+ snprintf(fpt->os_name, OS_THREAD_NAMELEN,
+ "%s", os_name);
if (attr == &frr_pthread_attr_default)
fpt->attr.id = frr_pthread_get_id();
/* initialize startup synchronization primitives */
XFREE(MTYPE_FRR_PTHREAD, fpt);
}
-void frr_pthread_set_name(struct frr_pthread *fpt, const char *name)
+int frr_pthread_set_name(struct frr_pthread *fpt, const char *name,
+ const char *os_name)
{
- pthread_mutex_lock(&fpt->mtx);
- {
- if (fpt->name)
- XFREE(MTYPE_FRR_PTHREAD, fpt->name);
- fpt->name = XSTRDUP(MTYPE_FRR_PTHREAD, name);
+ int ret = 0;
+
+ if (name) {
+ pthread_mutex_lock(&fpt->mtx);
+ {
+ if (fpt->name)
+ XFREE(MTYPE_FRR_PTHREAD, fpt->name);
+ fpt->name = XSTRDUP(MTYPE_FRR_PTHREAD, name);
+ }
+ pthread_mutex_unlock(&fpt->mtx);
+ thread_master_set_name(fpt->master, name);
}
- pthread_mutex_unlock(&fpt->mtx);
- thread_master_set_name(fpt->master, name);
+
+ if (os_name) {
+ pthread_mutex_lock(&fpt->mtx);
+ snprintf(fpt->os_name, OS_THREAD_NAMELEN, "%s", os_name);
+ pthread_mutex_unlock(&fpt->mtx);
+#ifdef GNU_LINUX
+ ret = pthread_setname_np(fpt->thread, fpt->os_name);
+#elif defined(OPEN_BSD)
+ ret = pthread_set_name_np(fpt->thread, fpt->os_name);
+#endif
+ }
+
+ return ret;
}
struct frr_pthread *frr_pthread_get(uint32_t id)
fpt->master->handle_signals = false;
+ if (fpt->os_name)
+ frr_pthread_set_name(fpt, NULL, fpt->os_name);
+
frr_pthread_notify_running(fpt);
struct thread task;
DECLARE_MTYPE(FRR_PTHREAD);
DECLARE_MTYPE(PTHREAD_PRIM);
+#define OS_THREAD_NAMELEN 16
+
struct frr_pthread;
struct frr_pthread_attr;
* Requires: mtx
*/
char *name;
+
+ /* Used in pthread_set_name max 16 characters */
+ char os_name[OS_THREAD_NAMELEN];
};
extern struct frr_pthread_attr frr_pthread_attr_default;
*
* @param attr - the thread attributes
* @param name - Human-readable name
+ * @param os_name - 16 characters (including '\0') thread name to set in os,
* @return the created frr_pthread upon success, or NULL upon failure
*/
struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr,
- const char *name);
+ const char *name, const char *os_name);
/*
* Changes the name of the frr_pthread.
*
* @param fpt - the frr_pthread to operate on
* @param name - Human-readable name
+ * @param os_name - 16 characters thread name , including the null
+ * terminator ('\0') to set in os.
+ * @return - on success returns 0 otherwise nonzero error number.
*/
-void frr_pthread_set_name(struct frr_pthread *fpt, const char *name);
+int frr_pthread_set_name(struct frr_pthread *fpt, const char *name,
+ const char *os_name);
/*
* Destroys an frr_pthread.
.stop = frr_pthread_attr_default.stop
};
client->pthread =
- frr_pthread_new(&zclient_pthr_attrs, "Zebra API client thread");
+ frr_pthread_new(&zclient_pthr_attrs, "Zebra API client thread",
+ "zebra_apic");
zebra_vrf_update_all(client);