annotate src/lib/process-title.c @ 9191:b340ecb24469 HEAD

Fix VPATH build of RQUOTA support. Some rpcgen derive #include "..." paths from the infile argument. This will be off for VPATH builds, as the generated rquota_xdr.c code will look in $(srcdir), but we'll generate the rquota.h file in $(builddir). Play safe and copy rquota.x to $(builddir) first. This fixes the build on openSUSE 11.1.
author Matthias Andree <matthias.andree@gmx.de>
date Tue, 07 Jul 2009 21:01:36 +0200
parents b9faf4db2a9f
children cf291558ce28
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8590
b9faf4db2a9f Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
1 /* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
745
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
1741
9df02b1533b3 Removed most of the license comments from src/lib/*.c. It's just fine to
Timo Sirainen <tss@iki.fi>
parents: 894
diff changeset
3 /*
9df02b1533b3 Removed most of the license comments from src/lib/*.c. It's just fine to
Timo Sirainen <tss@iki.fi>
parents: 894
diff changeset
4 LINUX_PROCTITLE_HACK code from:
9df02b1533b3 Removed most of the license comments from src/lib/*.c. It's just fine to
Timo Sirainen <tss@iki.fi>
parents: 894
diff changeset
5 http://lightconsulting.com/~thalakan/process-title-notes.html
745
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 */
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "lib.h"
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "process-title.h"
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10
894
efe7c015dd78 Include unistd.h for setproctitle(), FreeBSD wants it.
Timo Sirainen <tss@iki.fi>
parents: 864
diff changeset
11 #include <stdlib.h> /* NetBSD, OpenBSD */
efe7c015dd78 Include unistd.h for setproctitle(), FreeBSD wants it.
Timo Sirainen <tss@iki.fi>
parents: 864
diff changeset
12 #include <unistd.h> /* FreeBSD */
864
a090577ffdca setproctitle() needs stdlib.h
Timo Sirainen <tss@iki.fi>
parents: 807
diff changeset
13
745
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 /* NOTE: This really is a horrible hack, I don't recommend using it for
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 anything else than debugging. */
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 /*#define LINUX_PROCTITLE_HACK*/
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 static char *process_name = NULL;
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 #ifdef LINUX_PROCTITLE_HACK
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 static char *process_title;
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 static size_t process_title_len;
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 static void linux_proctitle_init(char *argv[], char *envp[])
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 {
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 extern char **environ;
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 char **p;
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 int i;
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 /* copy environment elsewhere */
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 for (i = 0; envp[i] != NULL; i++)
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 ;
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 if ((p = malloc((i + 1) * sizeof(char *))) == NULL)
3198
cb285bd5d8c9 If we run out of memory, exit with FATAL_OUTOFMEM status instead of dumping
Timo Sirainen <tss@iki.fi>
parents: 1741
diff changeset
35 i_fatal_status(FATAL_OUTOFMEM, "malloc() failed: %m");
745
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 environ = p;
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 for (i = 0; envp[i] != NULL; i++) {
807
35abd7a5d381 Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents: 801
diff changeset
39 if ((environ[i] = strdup(envp[i])) == NULL)
3198
cb285bd5d8c9 If we run out of memory, exit with FATAL_OUTOFMEM status instead of dumping
Timo Sirainen <tss@iki.fi>
parents: 1741
diff changeset
40 i_fatal_status(FATAL_OUTOFMEM, "strdup() failed: %m");
745
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 }
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 environ[i] = NULL;
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 /* memory is allocated so that argv[] comes first, environment next.
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 Calculate the max. size for process name with by checking the
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 address for last environment and it's length. */
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 process_title = argv[0];
807
35abd7a5d381 Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents: 801
diff changeset
48 process_title_len = (size_t) (envp[i-1] - argv[0]) + strlen(envp[i-1]);
745
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 }
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 static void linux_proctitle_set(const char *title)
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 {
6422
18173a52f721 Renamed strocpy() to i_strocpy().
Timo Sirainen <tss@iki.fi>
parents: 6411
diff changeset
53 i_strocpy(process_title, title, process_title_len);
745
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 }
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 #endif
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 3198
diff changeset
58 void process_title_init(char *argv[] ATTR_UNUSED,
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 3198
diff changeset
59 char *envp[] ATTR_UNUSED)
745
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 {
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 #ifdef LINUX_PROCTITLE_HACK
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 linux_proctitle_init(argv, envp);
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 #endif
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 process_name = argv[0];
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 }
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 3198
diff changeset
67 void process_title_set(const char *title ATTR_UNUSED)
745
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 {
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 i_assert(process_name != NULL);
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 #ifdef HAVE_SETPROCTITLE
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 if (title == NULL)
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 setproctitle("%s", process_name);
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 else
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 setproctitle("%s %s", process_name, title);
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 #elif defined(LINUX_PROCTITLE_HACK)
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 linux_proctitle_set(t_strconcat(process_name, " ", title, NULL));
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 #endif
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 }
32040b730b37 Login process now changes it's name if verbose_proctitle = yes, and we're
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80