Patchwork [2,of,2] chg: change server's process title

login
register
mail settings
Submitter Jun Wu
Date Jan. 11, 2017, 1:13 a.m.
Message ID <b68bec41a5562c8fa0ed.1484097190@x1c>
Download mbox | patch
Permalink /patch/18177/
State Accepted
Headers show

Comments

Jun Wu - Jan. 11, 2017, 1:13 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1484091652 -28800
#      Wed Jan 11 07:40:52 2017 +0800
# Node ID b68bec41a5562c8fa0ed9ac0e94f0c2d6906a2e8
# Parent  a82e9f172feff7ca2380b3db8833ddc64cd35429
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r b68bec41a556
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 title is short, "chg:$PID", to fit in prctl's 15-char limit. The new
title can be observed using "ps -AO comm" under Linux, and is directly
observable using "ps -A" under FreeBSD.
Pierre-Yves David - Jan. 11, 2017, 7:57 a.m.
On 01/11/2017 02:13 AM, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1484091652 -28800
> #      Wed Jan 11 07:40:52 2017 +0800
> # Node ID b68bec41a5562c8fa0ed9ac0e94f0c2d6906a2e8
> # Parent  a82e9f172feff7ca2380b3db8833ddc64cd35429
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r b68bec41a556
> chg: change server's process title

Seems reasonable, these two are pushed

Cheers,
Pierre-Yves David - Jan. 11, 2017, 8:57 a.m.
On 01/11/2017 08:57 AM, Pierre-Yves David wrote:
> On 01/11/2017 02:13 AM, Jun Wu wrote:
>> # HG changeset patch
>> # User Jun Wu <quark@fb.com>
>> # Date 1484091652 -28800
>> #      Wed Jan 11 07:40:52 2017 +0800
>> # Node ID b68bec41a5562c8fa0ed9ac0e94f0c2d6906a2e8
>> # Parent  a82e9f172feff7ca2380b3db8833ddc64cd35429
>> # Available At https://bitbucket.org/quark-zju/hg-draft
>> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r
>> b68bec41a556
>> chg: change server's process title

I've also pushed a minor commit message update on Jun request.
Yuya Nishihara - Jan. 11, 2017, 3:03 p.m.
On Wed, 11 Jan 2017 09:13:10 +0800, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1484091652 -28800
> #      Wed Jan 11 07:40:52 2017 +0800
> # Node ID b68bec41a5562c8fa0ed9ac0e94f0c2d6906a2e8
> # Parent  a82e9f172feff7ca2380b3db8833ddc64cd35429
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r b68bec41a556
> chg: change server's process title

> +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");
> +}

snprintf() returns the length that would have been written to the buffer if
the buffer had enough space. I know maxdatasize should be at least 4k so
this is kinda nitpick, but I want to be strict about memory stuff.

Can you send a follow-up patch?
Jun Wu - Jan. 11, 2017, 3:44 p.m.
Excerpts from Yuya Nishihara's message of 2017-01-12 00:03:35 +0900:
> On Wed, 11 Jan 2017 09:13:10 +0800, Jun Wu wrote:
> > # HG changeset patch
> > # User Jun Wu <quark@fb.com>
> > # Date 1484091652 -28800
> > #      Wed Jan 11 07:40:52 2017 +0800
> > # Node ID b68bec41a5562c8fa0ed9ac0e94f0c2d6906a2e8
> > # Parent  a82e9f172feff7ca2380b3db8833ddc64cd35429
> > # Available At https://bitbucket.org/quark-zju/hg-draft 
> > #              hg pull https://bitbucket.org/quark-zju/hg-draft  -r b68bec41a556
> > chg: change server's process title
> 
> > +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");
> > +}
> 
> snprintf() returns the length that would have been written to the buffer if
> the buffer had enough space. I know maxdatasize should be at least 4k so
> this is kinda nitpick, but I want to be strict about memory stuff.
> 
> Can you send a follow-up patch?

Sure. I grafted the change from an older commit. If I were writing it again,
I probably will check the return value.

Patch

diff --git a/contrib/chg/hgclient.c b/contrib/chg/hgclient.c
--- a/contrib/chg/hgclient.c
+++ b/contrib/chg/hgclient.c
@@ -36,4 +36,5 @@  enum {
 	CAP_SETUMASK = 0x1000,
 	CAP_VALIDATE = 0x2000,
+	CAP_SETPROCNAME = 0x4000,
 };
 
@@ -51,4 +52,5 @@  static const cappair_t captable[] = {
 	{"setumask", CAP_SETUMASK},
 	{"validate", CAP_VALIDATE},
+	{"setprocname", CAP_SETPROCNAME},
 	{NULL, 0},  /* terminator */
 };
@@ -363,4 +365,12 @@  static void readhello(hgclient_t *hgc)
 }
 
+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)
 {
@@ -492,4 +502,6 @@  hgclient_t *hgc_open(const char *socknam
 	if (!(hgc->capflags & CAP_RUNCOMMAND))
 		abortmsg("insufficient capability: runcommand");
+	if (hgc->capflags & CAP_SETPROCNAME)
+		updateprocname(hgc);
 	if (hgc->capflags & CAP_ATTACHIO)
 		attachio(hgc);