view src/libident/support.c @ 72:ad034b57f3b2

fixed Debian bug 536060 (log files are closed after SIGHUP receival) Explanation: When run in daemon mode, first the log files are opened. They get assigned to the file descriptors 3 and 4 usually. Then std{in,out,err} are closed. When SIGHUP comes in, all open files are closes and masqmail reexecutes itself. The new masqmail instance opens the log files at fd 0 and 1 now, but std{in,out,err} are closed afterwards, thus the log files are closed. The fix is to close the log files before std{in,out,err} are closed, in case the log files have higher fds. After std{in,out,err} were closed, the log files get opened again, now. See also: http://bugs.debian.org/536060
author meillo@marmaro.de
date Wed, 16 Jun 2010 10:32:20 +0200
parents 26e34ae9a3e3
children
line wrap: on
line source

/*
** support.c
**
** Author: Pr Emanuelsson <pell@lysator.liu.se>
** Hacked by: Peter Eriksson <pen@lysator.liu.se>
*/
#include <stdio.h>
#include <ctype.h>

#ifdef HAVE_ANSIHEADERS
#  include <stdlib.h>
#  include <string.h>
#else
#  define strchr(str, c) index(str, c)
#endif

#define IN_LIBIDENT_SRC
#include "ident.h"


char*
id_strdup __P1(char *, str)
{
	char *cp;

	cp = (char *) malloc(strlen(str) + 1);
	if (cp == NULL) {
#ifdef DEBUG
		perror("libident: malloc");
#endif
		return NULL;
	}

	strcpy(cp, str);

	return cp;
}


char*
id_strtok __P3(char *, cp, char *, cs, char *, dc)
{
	static char *bp = 0;

	if (cp)
		bp = cp;

	/*
	 ** No delimitor cs - return whole buffer and point at end
	 */
	if (!cs) {
		while (*bp)
			bp++;
		return cs;
	}

	/*
	 ** Skip leading spaces
	 */
	while (isspace(*bp))
		bp++;

	/*
	 ** No token found?
	 */
	if (!*bp)
		return 0;

	cp = bp;
	while (*bp && !strchr(cs, *bp))
		bp++;

	/*
	 ** Remove trailing spaces
	 */
	*dc = *bp;
	for (dc = bp - 1; dc > cp && isspace(*dc); dc--);
	*++dc = '\0';

	bp++;

	return cp;
}