[dovecot-cvs] dovecot/src/lib process-title.c,NONE,1.1 process-title.h,NONE,1.1 Makefile.am,1.17,1.18

cras at procontrol.fi cras at procontrol.fi
Tue Dec 3 02:13:19 EET 2002


Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv6582/src/lib

Modified Files:
	Makefile.am 
Added Files:
	process-title.c process-title.h 
Log Message:
Login process now changes it's name if verbose_proctitle = yes, and we're
running BSD. This is also possible with Linux with a pretty ugly hack, which
you can enable by modifying lib/process-title.c if you _really_ want to.

And a nasty bugfix - login_process_per_connection setting didn't work with
imaps port connections which is exactly where it was mostly wanted.



--- NEW FILE: process-title.c ---
/*
    Copyright (c) 2002 Timo Sirainen

    LINUX_PROCTITLE_HACK code from:
    http://lightconsulting.com/~thalakan/process-title-notes.html

    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "lib.h"
#include "process-title.h"

/* NOTE: This really is a horrible hack, I don't recommend using it for
   anything else than debugging. */
/*#define LINUX_PROCTITLE_HACK*/

static char *process_name = NULL;

#ifdef LINUX_PROCTITLE_HACK
static char *process_title;
static size_t process_title_len;

static void linux_proctitle_init(char *argv[], char *envp[])
{
	extern char **environ;
	char **p;
	int i;

	/* copy environment elsewhere */
	for (i = 0; envp[i] != NULL; i++)
		;

	if ((p = malloc((i + 1) * sizeof(char *))) == NULL)
		i_fatal("malloc() failed: %m");
	environ = p;

	for (i = 0; envp[i] != NULL; i++) {
		if ((environ[i] = malloc(strlen(envp[i]) + 1)) == NULL)
			i_fatal("malloc() failed: %m");

		strcpy(environ[i], envp[i]);
	}
	environ[i] = NULL;

	/* memory is allocated so that argv[] comes first, environment next.
	   Calculate the max. size for process name with by checking the
	   address for last environment and it's length. */
	process_title = argv[0];
	process_title_len = (size_t) (envp[i-1] - argv[0]) +
		strlen(envp[i-1]);
}

static void linux_proctitle_set(const char *title)
{
	strncpy(process_title, title, process_title_len);
	process_title[process_title_len] = '\0';
}

#endif

void process_title_init(char *argv[] __attr_unused__,
			char *envp[] __attr_unused__)
{
#ifdef LINUX_PROCTITLE_HACK
	linux_proctitle_init(argv, envp);
#endif
	process_name = argv[0];
}

void process_title_set(const char *title __attr_unused__)
{
	i_assert(process_name != NULL);

#ifdef HAVE_SETPROCTITLE
	if (title == NULL)
		setproctitle("%s", process_name);
	else
		setproctitle("%s %s", process_name, title);
#elif defined(LINUX_PROCTITLE_HACK)
	linux_proctitle_set(t_strconcat(process_name, " ", title, NULL));
#endif
}


--- NEW FILE: process-title.h ---
#ifndef __PROCESS_TITLE_H
#define __PROCESS_TITLE_H

/* Initialize title changing. */
void process_title_init(char *argv[], char *envp[]);

/* Change the process title if possible. */
void process_title_set(const char *title);

#endif

Index: Makefile.am
===================================================================
RCS file: /home/cvs/dovecot/src/lib/Makefile.am,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- Makefile.am	1 Dec 2002 15:39:20 -0000	1.17
+++ Makefile.am	3 Dec 2002 00:13:17 -0000	1.18
@@ -36,6 +36,7 @@
 	obuffer.c \
 	obuffer-file.c \
 	primes.c \
+	process-title.c \
 	randgen.c \
 	restrict-access.c \
 	restrict-process-size.c \
@@ -78,6 +79,7 @@
 	obuffer.h \
 	obuffer-internal.h \
 	primes.h \
+	process-title.h \
 	randgen.h \
 	restrict-access.h \
 	restrict-process-size.h \




More information about the dovecot-cvs mailing list