Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/hostpid.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 | 2609eca99495 |
children | 00cd9aacd03c |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
8065
diff
changeset
|
1 /* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */ |
0 | 2 |
3 #include "lib.h" | |
4 #include "hostpid.h" | |
5 | |
6 #include <unistd.h> | |
8596
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
7 #include <netdb.h> |
0 | 8 |
9 const char *my_hostname = NULL; | |
10 const char *my_pid = NULL; | |
11 | |
8596
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
12 static char *my_domain = NULL; |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
13 |
0 | 14 void hostpid_init(void) |
15 { | |
678
1e5c655bad25
Renamed largest_t to uintmax_t which already exists in C99.
Timo Sirainen <tss@iki.fi>
parents:
179
diff
changeset
|
16 static char hostname[256], pid[MAX_INT_STRLEN]; |
0 | 17 |
8065
c832be51c7ac
hostpid_init(): If called again, update the hostname/pid.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
18 if (gethostname(hostname, sizeof(hostname)-1) == -1) |
c832be51c7ac
hostpid_init(): If called again, update the hostname/pid.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
19 i_strocpy(hostname, "unknown", sizeof(hostname)); |
c832be51c7ac
hostpid_init(): If called again, update the hostname/pid.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
20 hostname[sizeof(hostname)-1] = '\0'; |
c832be51c7ac
hostpid_init(): If called again, update the hostname/pid.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
21 my_hostname = hostname; |
0 | 22 |
8596
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
23 /* allow calling hostpid_init() multiple times to reset hostname */ |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
24 i_free_and_null(my_domain); |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
25 |
8065
c832be51c7ac
hostpid_init(): If called again, update the hostname/pid.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
26 i_strocpy(pid, dec2str(getpid()), sizeof(pid)); |
c832be51c7ac
hostpid_init(): If called again, update the hostname/pid.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
27 my_pid = pid; |
0 | 28 } |
8596
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
29 |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
30 const char *my_hostdomain(void) |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
31 { |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
32 struct hostent *hent; |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
33 const char *name; |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
34 |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
35 if (my_domain == NULL) { |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
36 hent = gethostbyname(my_hostname); |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
37 name = hent != NULL ? hent->h_name : NULL; |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
38 if (name == NULL) { |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
39 /* failed, use just the hostname */ |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
40 name = my_hostname; |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
41 } |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
42 my_domain = i_strdup(name); |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
43 } |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
44 return my_domain; |
2609eca99495
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
45 } |