# HG changeset patch # User Jun Wu # Date 1484091652 -28800 # Node ID e882c7bb5a0ba2589a44108c9a87b300a13e08df # Parent 378686afca52374822420e0fcd026fb9de502b81 chg: change server's process title This patch uses the newly introduced "setprocname" interface to update the process title server-side, to make it easier to tell what a worker is actually doing. The new title is "chg[worker/$PID]", where PID is the process ID of the connected client. It can be directly observed using "ps -AF" under Linux, or "ps -A" under FreeBSD. diff -r 378686afca52 -r e882c7bb5a0b contrib/chg/hgclient.c --- a/contrib/chg/hgclient.c Wed Jan 11 07:36:48 2017 +0800 +++ b/contrib/chg/hgclient.c Wed Jan 11 07:40:52 2017 +0800 @@ -35,6 +35,7 @@ CAP_SETENV = 0x0800, CAP_SETUMASK = 0x1000, CAP_VALIDATE = 0x2000, + CAP_SETPROCNAME = 0x4000, }; typedef struct { @@ -50,6 +51,7 @@ {"setenv", CAP_SETENV}, {"setumask", CAP_SETUMASK}, {"validate", CAP_VALIDATE}, + {"setprocname", CAP_SETPROCNAME}, {NULL, 0}, /* terminator */ }; @@ -362,6 +364,14 @@ debugmsg("capflags=0x%04x, pid=%d", hgc->capflags, hgc->pid); } +static void updateprocname(hgclient_t *hgc) +{ + size_t n = (size_t)snprintf(hgc->ctx.data, hgc->ctx.maxdatasize, + "chg[worker/%d]", (int)getpid()); + hgc->ctx.datasize = n; + writeblockrequest(hgc, "setprocname"); +} + static void attachio(hgclient_t *hgc) { debugmsg("request attachio"); @@ -491,6 +501,8 @@ readhello(hgc); if (!(hgc->capflags & CAP_RUNCOMMAND)) abortmsg("insufficient capability: runcommand"); + if (hgc->capflags & CAP_SETPROCNAME) + updateprocname(hgc); if (hgc->capflags & CAP_ATTACHIO) attachio(hgc); if (hgc->capflags & CAP_CHDIR)