aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-05-11 00:10:42 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2009-05-11 00:10:42 +0300
commitffd2cf189d926abe00de0a79f292f1ea69d02aac (patch)
treeac5047e0bf1a0f2b579bf0d40299d59b2b26cc84
parent998eaf2cdb444ee77ff67068ce3586de1eea8e4e (diff)
downloadmailfromd-ffd2cf189d926abe00de0a79f292f1ea69d02aac.tar.gz
mailfromd-ffd2cf189d926abe00de0a79f292f1ea69d02aac.tar.bz2
Implement some system information functions.
* mfd/bi_gethostname.m4: New file. * NEWS, doc/mailfromd.texi: Update. * mfd/Makefile.am (M4_FILES): Add bi_gethostname.m4. * mfd/bi_system.m4 (uname): New function. * mfd/prog.c (heap_obstack_cancel, heap_obstack_base): New function. * mfd/prog.h: Likewise. * mfd/snarf.m4 (MF_OBSTACK_BASE, MF_OBSTACK_CANCEL): New defuns. * mtasim/mtasim.c (stop_mailfromd): Reset signal handler before doing kill, so that waitpid works on hosts with BSD signal semantics.
-rw-r--r--NEWS16
-rw-r--r--doc/mailfromd.texi51
-rw-r--r--mfd/Makefile.am1
-rw-r--r--mfd/bi_gethostname.m4123
-rw-r--r--mfd/bi_system.m459
-rw-r--r--mfd/prog.c14
-rw-r--r--mfd/prog.h2
-rw-r--r--mfd/snarf.m413
-rw-r--r--mtasim/mtasim.c8
9 files changed, 279 insertions, 8 deletions
diff --git a/NEWS b/NEWS
index c79dfa7d..b50d87a8 100644
--- a/NEWS
+++ b/NEWS
@@ -1,2 +1,2 @@
1Mailfromd NEWS -- history of user-visible changes. 2009-05-09 1Mailfromd NEWS -- history of user-visible changes. 2009-05-10
2Copyright (C) 2005, 2006, 2007, 2008, 2009 Sergey Poznyakoff 2Copyright (C) 2005, 2006, 2007, 2008, 2009 Sergey Poznyakoff
@@ -62,2 +62,16 @@ requested header is not found.
62 62
63New system information functions are added:
64
65- string gethostname ()
66
67Return the host name of this machine.
68
69- string getdomainname ()
70
71Return the domain name of this machine.
72
73- string uname (string format)
74
75Return system information formatted according to the format specification.
76
63* New pragma `dbprop' 77* New pragma `dbprop'
diff --git a/doc/mailfromd.texi b/doc/mailfromd.texi
index 0d171ab0..3d2e43c5 100644
--- a/doc/mailfromd.texi
+++ b/doc/mailfromd.texi
@@ -7730,2 +7730,16 @@ The function @code{revip} is defined in @ref{revip}.
7730 7730
7731@deftypefn {Built-in Function} string gethostname ()
7732Return the host name of this machine.
7733@end deftypefn
7734
7735@deftypefn {Built-in Function} string getdomainname ()
7736Return the domain name of this machine. Note, that it does not
7737necessarily coincide with the actual machine name in @acronym{DNS}.
7738
7739Depending on the underlying @samp{libc} implementation, this call may
7740return empty string or the string @samp{(none)}. Do not rely on it to
7741get the real hostname of the box @command{mailfromd} runs on, use
7742@acronym{DNS} functions instead.
7743@end deftypefn
7744
7731@deftypefn {Built-in Function} number time () 7745@deftypefn {Built-in Function} number time ()
@@ -7765,2 +7779,39 @@ strftime('%Y-%m-%d %H:%M:%S %Z', 1164477564, 1)
7765 7779
7780@deftypefn {Built-in Function} uname (string @var{format})
7781This function returns system information formatted according to
7782the format specification @var{format}. Ordinary characters placed
7783in the format string are copied to the output without conversion.
7784Conversion specifiers are introduced by a @samp{%} character.
7785The following conversions are defined:
7786
7787@table @asis
7788@item %s
7789Name of this system.
7790
7791@item %n
7792Name of this node within the communications network to which this node
7793is attached. Note, that it does not necessarily coincide with the
7794actual machine name in @acronym{DNS}.
7795
7796@item %r
7797Kernel release.
7798
7799@item %v
7800Kernel version.
7801
7802@item %m
7803Name of the hardware type on which the system is running.
7804@end table
7805
7806For example:
7807
7808@smallexample
7809 uname('%n runs %s, release %r on %m')
7810 @result{} "Trurl runs Linux, release 2.6.26 on i686"
7811@end smallexample
7812
7813Notice the use of single quotes.
7814
7815@end deftypefn
7816
7766@deftypefn {Built-in Function} number system (string @var{str}) 7817@deftypefn {Built-in Function} number system (string @var{str})
diff --git a/mfd/Makefile.am b/mfd/Makefile.am
index 03c2fca3..a22c20f4 100644
--- a/mfd/Makefile.am
+++ b/mfd/Makefile.am
@@ -27,2 +27,3 @@ M4_FILES=\
27 bi_dns.m4\ 27 bi_dns.m4\
28 bi_gethostname.m4\
28 bi_getopt.m4\ 29 bi_getopt.m4\
diff --git a/mfd/bi_gethostname.m4 b/mfd/bi_gethostname.m4
new file mode 100644
index 00000000..315a2d1b
--- /dev/null
+++ b/mfd/bi_gethostname.m4
@@ -0,0 +1,123 @@
1/* This file is part of Mailfromd. -*- c -*-
2 Copyright (C) 2009 Sergey Poznyakoff
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifndef ENAMETOOLONG
18# define ENAMETOOLONG 0
19#endif
20
21#ifndef INITIAL_HOSTNAME_LENGTH
22# define INITIAL_HOSTNAME_LENGTH 34
23#endif
24
25#ifndef INITIAL_DOMAINNAME_LENGTH
26# define INITIAL_DOMAINNAME_LENGTH 34
27#endif
28
29/* string gethostname()
30
31 This implementation is based on xgethostname by Jim Meyering
32*/
33MF_DEFUN(gethostname, STRING)
34{
35 size_t size = INITIAL_HOSTNAME_LENGTH;
36
37 MF_OBSTACK_BEGIN();
38 while (1) {
39 size_t nsize;
40 size_t size_1;
41 char *hostname;
42
43 MF_OBSTACK_GROW(NULL, size);
44 hostname = MF_OBSTACK_BASE();
45
46 /* Use SIZE_1 here rather than SIZE to work around the bug in
47 SunOS 5.5's gethostname whereby it NUL-terminates HOSTNAME
48 even when the name is as long as the supplied buffer. */
49 size_1 = size - 1;
50 hostname[size_1 - 1] = '\0';
51 errno = 0;
52
53 if (gethostname(hostname, size_1) == 0) {
54 if (!hostname[size_1 - 1])
55 break;
56 } else if (errno != 0
57 && errno != ENAMETOOLONG && errno != EINVAL
58 /* OSX/Darwin does this when the buffer is not
59 large enough */
60 && errno != ENOMEM) {
61 int saved_errno = errno;
62 MF_OBSTACK_CANCEL();
63 MF_THROW(mfe_failure,
64 "%s", mu_strerror(saved_errno));
65 }
66
67 nsize = size * 2;
68 if (nsize <= size) {
69 MF_OBSTACK_CANCEL();
70 MF_THROW(mfe_failure,
71 "%s", mu_strerror(ENOMEM));
72 }
73 size = nsize;
74 }
75 MF_RETURN_OBSTACK();
76}
77END
78
79/* string getdomainname()
80
81 This implementation is based on xgetdomainname by Jim Meyering
82*/
83MF_DEFUN(getdomainname, STRING)
84{
85 size_t size = INITIAL_DOMAINNAME_LENGTH;
86
87 MF_OBSTACK_BEGIN();
88 while (1) {
89 size_t nsize;
90 size_t size_1;
91 char *domainname;
92 int rc;
93
94 MF_OBSTACK_GROW(NULL, size);
95 domainname = MF_OBSTACK_BASE();
96
97 size_1 = size - 1;
98 domainname[size_1 - 1] = '\0';
99 errno = 0;
100
101 rc = getdomainname(domainname, size);
102 if (rc >= 0 && domainname[size_1] == '\0')
103 break;
104 else if (rc < 0 && errno != EINVAL) {
105 int saved_errno = errno;
106 MF_OBSTACK_CANCEL();
107 MF_THROW(mfe_failure,
108 "%s", mu_strerror(saved_errno));
109 }
110
111 nsize = size * 2;
112 if (nsize <= size) {
113 MF_OBSTACK_CANCEL();
114 MF_THROW(mfe_failure,
115 "%s", mu_strerror(ENOMEM));
116 }
117 size = nsize;
118 }
119 MF_RETURN_OBSTACK();
120}
121END
122
123MF_INIT</