diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-05-11 00:10:42 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-05-11 00:10:42 +0300 |
commit | ffd2cf189d926abe00de0a79f292f1ea69d02aac (patch) | |
tree | ac5047e0bf1a0f2b579bf0d40299d59b2b26cc84 | |
parent | 998eaf2cdb444ee77ff67068ce3586de1eea8e4e (diff) | |
download | mailfromd-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-- | NEWS | 16 | ||||
-rw-r--r-- | doc/mailfromd.texi | 51 | ||||
-rw-r--r-- | mfd/Makefile.am | 1 | ||||
-rw-r--r-- | mfd/bi_gethostname.m4 | 123 | ||||
-rw-r--r-- | mfd/bi_system.m4 | 59 | ||||
-rw-r--r-- | mfd/prog.c | 14 | ||||
-rw-r--r-- | mfd/prog.h | 2 | ||||
-rw-r--r-- | mfd/snarf.m4 | 13 | ||||
-rw-r--r-- | mtasim/mtasim.c | 8 |
9 files changed, 279 insertions, 8 deletions
@@ -1,4 +1,4 @@ | |||
1 | Mailfromd NEWS -- history of user-visible changes. 2009-05-09 | 1 | Mailfromd NEWS -- history of user-visible changes. 2009-05-10 |
2 | Copyright (C) 2005, 2006, 2007, 2008, 2009 Sergey Poznyakoff | 2 | Copyright (C) 2005, 2006, 2007, 2008, 2009 Sergey Poznyakoff |
3 | See the end of file for copying conditions. | 3 | See the end of file for copying conditions. |
4 | 4 | ||
@@ -60,6 +60,20 @@ Index is 1-based. | |||
60 | All current_header functions raise the e_not_found exception if the | 60 | All current_header functions raise the e_not_found exception if the |
61 | requested header is not found. | 61 | requested header is not found. |
62 | 62 | ||
63 | New system information functions are added: | ||
64 | |||
65 | - string gethostname () | ||
66 | |||
67 | Return the host name of this machine. | ||
68 | |||
69 | - string getdomainname () | ||
70 | |||
71 | Return the domain name of this machine. | ||
72 | |||
73 | - string uname (string format) | ||
74 | |||
75 | Return system information formatted according to the format specification. | ||
76 | |||
63 | * New pragma `dbprop' | 77 | * New pragma `dbprop' |
64 | 78 | ||
65 | This pragma defines user database properties. It takes two or three | 79 | This pragma defines user database properties. It takes two or three |
diff --git a/doc/mailfromd.texi b/doc/mailfromd.texi index 0d171ab0..3d2e43c5 100644 --- a/doc/mailfromd.texi +++ b/doc/mailfromd.texi | |||
@@ -7728,6 +7728,20 @@ The function @code{revip} is defined in @ref{revip}. | |||
7728 | @node System functions | 7728 | @node System functions |
7729 | @subsubsection System functions | 7729 | @subsubsection System functions |
7730 | 7730 | ||
7731 | @deftypefn {Built-in Function} string gethostname () | ||
7732 | Return the host name of this machine. | ||
7733 | @end deftypefn | ||
7734 | |||
7735 | @deftypefn {Built-in Function} string getdomainname () | ||
7736 | Return the domain name of this machine. Note, that it does not | ||
7737 | necessarily coincide with the actual machine name in @acronym{DNS}. | ||
7738 | |||
7739 | Depending on the underlying @samp{libc} implementation, this call may | ||
7740 | return empty string or the string @samp{(none)}. Do not rely on it to | ||
7741 | get 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 () |
7732 | Return the time since the Epoch (00:00:00 UTC, January 1, 1970), | 7746 | Return the time since the Epoch (00:00:00 UTC, January 1, 1970), |
7733 | measured in seconds. | 7747 | measured in seconds. |
@@ -7763,6 +7777,43 @@ strftime('%Y-%m-%d %H:%M:%S %Z', 1164477564, 1) | |||
7763 | @end smallexample | 7777 | @end smallexample |
7764 | @end deftypefn | 7778 | @end deftypefn |
7765 | 7779 | ||
7780 | @deftypefn {Built-in Function} uname (string @var{format}) | ||
7781 | This function returns system information formatted according to | ||
7782 | the format specification @var{format}. Ordinary characters placed | ||
7783 | in the format string are copied to the output without conversion. | ||
7784 | Conversion specifiers are introduced by a @samp{%} character. | ||
7785 | The following conversions are defined: | ||
7786 | |||
7787 | @table @asis | ||
7788 | @item %s | ||
7789 | Name of this system. | ||
7790 | |||
7791 | @item %n | ||
7792 | Name of this node within the communications network to which this node | ||
7793 | is attached. Note, that it does not necessarily coincide with the | ||
7794 | actual machine name in @acronym{DNS}. | ||
7795 | |||
7796 | @item %r | ||
7797 | Kernel release. | ||
7798 | |||
7799 | @item %v | ||
7800 | Kernel version. | ||
7801 | |||
7802 | @item %m | ||
7803 | Name of the hardware type on which the system is running. | ||
7804 | @end table | ||
7805 | |||
7806 | For 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 | |||
7813 | Notice 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}) |
7767 | The function @code{system} executes a command specified in @var{str} | 7818 | The function @code{system} executes a command specified in @var{str} |
7768 | by calling @command{/bin/sh -c string}, and returns -1 on error or | 7819 | by calling @command{/bin/sh -c string}, and returns -1 on error or |
diff --git a/mfd/Makefile.am b/mfd/Makefile.am index 03c2fca3..a22c20f4 100644 --- a/mfd/Makefile.am +++ b/mfd/Makefile.am | |||
@@ -25,6 +25,7 @@ M4_FILES=\ | |||
25 | bi_curhdr.m4\ | 25 | bi_curhdr.m4\ |
26 | bi_db.m4\ | 26 | bi_db.m4\ |
27 | bi_dns.m4\ | 27 | bi_dns.m4\ |
28 | bi_gethostname.m4\ | ||
28 | bi_getopt.m4\ | 29 | bi_getopt.m4\ |
29 | bi_gettext.m4\ | 30 | bi_gettext.m4\ |
30 | bi_header.m4\ | 31 | bi_header.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 | */ | ||
33 | MF_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 | } | ||
77 | END | ||
78 | |||
79 | /* string getdomainname() | ||
80 | |||
81 | This implementation is based on xgetdomainname by Jim Meyering | ||
82 | */ | ||
83 | MF_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; | ||