]> err.no Git - varnish/commitdiff
Report thread name and thread session in panic messages.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 20 Jul 2008 10:45:09 +0000 (10:45 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 20 Jul 2008 10:45:09 +0000 (10:45 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2972 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_acceptor.c
varnish-cache/bin/varnishd/cache_acceptor_epoll.c
varnish-cache/bin/varnishd/cache_acceptor_kqueue.c
varnish-cache/bin/varnishd/cache_acceptor_poll.c
varnish-cache/bin/varnishd/cache_backend_poll.c
varnish-cache/bin/varnishd/cache_expire.c
varnish-cache/bin/varnishd/cache_fetch.c
varnish-cache/bin/varnishd/cache_main.c
varnish-cache/bin/varnishd/cache_panic.c
varnish-cache/bin/varnishd/cache_pool.c

index b72f36be278168367ab49510582852f612e275e8..689f61f894ed3f716b26f02d6180c4b860778760 100644 (file)
@@ -510,7 +510,8 @@ int HTC_Complete(struct http_conn *htc);
 #undef HTTPH
 
 /* cache_main.c */
-void THR_Name(const char *name);
+void THR_SetName(const char *name);
+const char* THR_GetName(void);
 void THR_SetSession(const struct sess *sp);
 const struct sess * THR_GetSession(void);
 
index 65632cfea30d5e8bb810474fc3293981ea2f29fe..63289499d8183baa4a755b160bd3fe8ed51d3913 100644 (file)
@@ -162,7 +162,7 @@ vca_acct(void *arg)
        unsigned u;
        double now;
 
-       THR_Name("cache-acceptor");
+       THR_SetName("cache-acceptor");
        (void)arg;
 
        /* Set up the poll argument */
index 8652d7234a85453f17ede1b952b29d8367f3708b..0f323e23d4c1644f484ab3a7baf01af6695e4a69 100644 (file)
@@ -76,7 +76,7 @@ vca_main(void *arg)
        struct sess *sp, *sp2;
        int i;
 
-       THR_Name("cache-epoll");
+       THR_SetName("cache-epoll");
        (void)arg;
 
        epfd = epoll_create(16);
index aaaab3dfd0510c27e2ec5d8e4ccad3196d1834fc..eb5cb67f42657fb38e2b8a8db7bb9c1293214d38 100644 (file)
@@ -152,7 +152,7 @@ vca_kqueue_main(void *arg)
        double deadline;
        struct sess *sp;
 
-       THR_Name("cache-kqueue");
+       THR_SetName("cache-kqueue");
        (void)arg;
 
        kq = kqueue();
index 171179d257d62cf0740d46788d63ebaa8bd8774c..195123e9b5387b543d1878fc4da7b1ce9452c78f 100644 (file)
@@ -111,7 +111,7 @@ vca_main(void *arg)
        double deadline;
        int i, fd;
 
-       THR_Name("cache-poll");
+       THR_SetName("cache-poll");
        (void)arg;
 
        vca_poll(vca_pipes[0]);
index 72ad98e31791b1e163267a1d949b2d7b4115c29f..e5d72ae41779ee251e35a833b8497cf47920f784 100644 (file)
@@ -68,7 +68,7 @@ vbp_wrk_poll_backend(struct worker *w, void *priv)
 
        (void)w;
        CAST_OBJ_NOTNULL(vt, priv, VBP_TARGET_MAGIC);
-       THR_Name("backend poll");
+       THR_SetName("backend poll");
 
        while (!vt->stop) {
                printf("Poke backend %s\n", vt->backend->vcl_name);
@@ -76,7 +76,7 @@ vbp_wrk_poll_backend(struct worker *w, void *priv)
        }
        vt->backend->probe = NULL;
        FREE_OBJ(vt);
-       THR_Name("cache-worker");
+       THR_SetName("cache-worker");
 }
 
 void
index 3347891546d9d948a1c366ff1b284f8a142c251c..46f558c73ed68d052c48b5fbe9aa96e779cb9bab 100644 (file)
@@ -263,7 +263,7 @@ exp_timer(void *arg)
        struct sess *sp;
        unsigned char logbuf[1024];             /* XXX size ? */
 
-       THR_Name("cache-timeout");
+       THR_SetName("cache-timeout");
        (void)arg;
 
        sp = SES_New(NULL, 0);
index e098dcf731725c940bab4d8db7110941fb0dd740..443f8afdf1b4e42341758e722b57c2b68231b688 100644 (file)
@@ -317,6 +317,7 @@ Fetch(struct sess *sp)
        struct http_conn htc[1];
        int i;
 
+AZ(sp);
        CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
        CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
        CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
index 64405405d6046e1c026fd6c9ccfcbe9603508e88..4c093a12bb5b140760615d2c41433be3f48b1a4e 100644 (file)
@@ -65,19 +65,25 @@ THR_GetSession(void)
  * Name threads if our pthreads implementation supports it.
  */
 
+static pthread_key_t name_key;
+
 void
-THR_Name(const char *name)
+THR_SetName(const char *name)
 {
+
+       AZ(pthread_setspecific(name_key, name));
 #ifdef HAVE_PTHREAD_SET_NAME_NP
        pthread_set_name_np(pthread_self(), name);
-#else
-       /*
-        * XXX: we could stash it somewhere else (TLS ?)
-        */
-       (void)name;
 #endif
 }
 
+const char *
+THR_GetName(void)
+{
+
+       return (pthread_getspecific(name_key));
+}
+
 /*--------------------------------------------------------------------
  * XXX: Think more about which order we start things
  */
@@ -91,8 +97,9 @@ child_main(void)
        printf("Child starts\n");
 
        AZ(pthread_key_create(&sp_key, NULL));
+       AZ(pthread_key_create(&name_key, NULL));
 
-       THR_Name("cache-main");
+       THR_SetName("cache-main");
 
        PAN_Init();
        CLI_Init();
index ee6305276f797dad23686b99eaa085d2d93b4b99..f773b30e815aa81e92b3d424d0abc18d736a3f3a 100644 (file)
@@ -248,22 +248,30 @@ pan_ic(const char *func, const char *file, int line, const char *cond, int err,
 {
        int l;
        char *p;
+       const char *q;
+       const struct sess *sp;
 
        if (xxx) {
                vsb_printf(vsp,
                    "Missing errorhandling code in %s(), %s line %d:\n"
-                   "  Condition(%s) not true.\n",
+                   "  Condition(%s) not true.",
                    func, file, line, cond);
        } else {
                vsb_printf(vsp,
                    "Assert error in %s(), %s line %d:\n"
-                   "  Condition(%s) not true.\n",
+                   "  Condition(%s) not true.",
                    func, file, line, cond);
        }
        if (err)
-               vsb_printf(vsp,
-                   "  errno = %d (%s)\n", err, strerror(err));
-
+               vsb_printf(vsp, "  errno = %d (%s)", err, strerror(err));
+
+       q = THR_GetName();
+       if (q != NULL)
+               vsb_printf(vsp, "  thread = (%s)", q);
+       sp = THR_GetSession();
+       if (sp != NULL)
+               vsb_printf(vsp, "  sess = (%p)", sp);
+       vsb_printf(vsp, "\n");
        VSL_Panic(&l, &p);
        if (l < vsb_len(vsp))
                l = vsb_len(vsp);
index 3b21ae8bc30e54c7949d395972128d141abcfcec..5de2848ab28c8579405fc4ed864aab7cb096e6cb 100644 (file)
@@ -208,7 +208,7 @@ wrk_thread(void *priv)
        unsigned char wlog[8192];       /* XXX: size */
        struct workreq *wrq;
 
-       THR_Name("cache-worker");
+       THR_SetName("cache-worker");
        w = &ww;
        CAST_OBJ_NOTNULL(qp, priv, WQ_MAGIC);
        memset(w, 0, sizeof *w);
@@ -441,7 +441,7 @@ wrk_herdtimer_thread(void *priv)
        double t_idle;
        struct varnish_stats vsm, *vs;
 
-       THR_Name("wrk_herdtimer");
+       THR_SetName("wrk_herdtimer");
 
        memset(&vsm, 0, sizeof vsm);
        vs = &vsm;
@@ -534,7 +534,7 @@ wrk_herder_thread(void *priv)
 {
        unsigned u, w;
 
-       THR_Name("wrk_herder");
+       THR_SetName("wrk_herder");
        (void)priv;
        while (1) {
                for (u = 0 ; u < nwq; u++) {