git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Verbose git-daemon logging

From
Junio C Hamano <junkio@cox.net>
Date
Sep 22, 2005, 23:42 UTC
Message-ID
<7vd5n0lle8.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20050922092528.GB21019@pasky.or.cz>
Petr Baudis <pasky@suse.cz> writes:
> What would be knowing parent PID be useful for? (It's not really the PID
> number that's useful anyway (at least mostly), it's just a good unique
> identifier to distinguish between several simultaneous sessions.)

Maybe running two daemons serving two sets of repos? But anyway what you have look more consistent so let's keep that.

> Fixed up patch follows.
Thanks.
Show 23 quoted lines
> +static void logreport(const char *err, va_list params)
> +{
> +	/* We should do a single write so that it is atomic and output
> +	 * of several processes does not get intermangled. */
> +	char buf[1024];
> +	int buflen;
> +	int maxlen, msglen;
> +
> +	buflen = snprintf(buf, sizeof(buf), "[%d] ", getpid());
> +
> +	maxlen = sizeof(buf) - buflen - 1;
> +	msglen = vsnprintf(buf + buflen, maxlen, err, params);
> +	if (msglen > maxlen)
> +		msglen = maxlen;
> +	else if (msglen < 0)
> +		msglen = -1; /* Protect against weird return values. */
> +	buflen += msglen;
> +
> +	buf[buflen++] = '\n';
> +	buf[buflen] = '\0';
> +
> +	fputs(buf, stderr);
> +}
The tail part still looks odd here.  Maybe something like this?

+static void logreport(const char *err, va_list params) +{ + /* We should do a single write so that it is atomic and output + * of several processes does not get intermangled. */ + char buf[1024]; + int buflen; + int maxlen, msglen; + + /* sizeof(buf) should be big enough for "[pid] \n" */ + buflen = snprintf(buf, sizeof(buf), "[%d] ", getpid()); + + maxlen = sizeof(buf) - buflen - 1; /* -1 for our own LF */ + msglen = vsnprintf(buf + buflen, maxlen, err, params); + + /* maxlen counted our own LF but also counts space given to + * vsnprintf for the terminating NUL. We want to make sure that + * we have space for our own LF and NUL after the "meat" of the + * message, so truncate it at maxlen - 1. + */ + if (msglen > maxlen - 1) + msglen = maxlen - 1; + else if (msglen < 0) + msglen = 0; /* Protect against weird return values. */ + buflen += msglen; + + buf[buflen++] = '\n'; + buf[buflen] = '\0'; + + fputs(buf, stderr); +}

Previous: Petr BaudisNext: Linus Torvalds
Message 4 of 6 in “Verbose git-daemon logging”
  1. Verbose git-daemon loggingPetr Baudis, Sep 21, 2005
  2. Junio C HamanoSep 22, 2005
  3. Petr BaudisSep 22, 2005
  4. Junio C HamanoSep 22, 2005
  5. Linus TorvaldsSep 22, 2005
  6. Morten WelinderSep 23, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.