Resync patch with contrib.
[dragonfly.git] / contrib / sendmail-8.14 / libsm / syslogio.c
blob24fa3a23b3136cb6b9f2c433ed60e6a96765f0fb
1 /*
2 * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
8 */
10 #include <sm/gen.h>
11 SM_RCSID("@(#)$Id: syslogio.c,v 1.29 2001/09/11 04:04:49 gshapiro Exp $")
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <fcntl.h>
15 #include <syslog.h>
16 #include <errno.h>
17 #ifdef SM_RPOOL
18 # include <sm/rpool.h>
19 #endif /* SM_RPOOL */
20 #include <sm/io.h>
21 #include "local.h"
24 ** Overall:
25 ** This is a output file type that copies its output to the syslog daemon.
26 ** Each line of output is written as a separate syslog message.
27 ** The client is responsible for calling openlog() before writing to
28 ** any syslog file, and calling closelog() after all syslog output is complete.
29 ** The only state associated with a syslog file is 'int priority',
30 ** which we store in fp->f_ival.
34 ** SM_SYSLOGOPEN -- open a file pointer to syslog
36 ** Parameters:
37 ** fp -- file pointer assigned for the open
38 ** info -- priority level of the syslog messages
39 ** flags -- not used
40 ** rpool -- ignored
42 ** Returns:
43 ** 0 (zero) success always (see Overall)
46 int
47 sm_syslogopen(fp, info, flags, rpool)
48 SM_FILE_T *fp;
49 const void *info;
50 int flags;
51 const void *rpool;
53 int *priority = (int *)info;
55 fp->f_ival = *priority;
56 return 0;
60 ** SM_SYSLOGREAD -- read function for syslog
62 ** This is a "stub" function (placeholder) that always returns an error.
63 ** It is an error to read syslog.
65 ** Parameters:
66 ** fp -- the file pointer
67 ** buf -- buffer to place the data read
68 ** n -- number of bytes to read
70 ** Returns:
71 ** -1 (error) always and sets errno
74 ssize_t
75 sm_syslogread(fp, buf, n)
76 SM_FILE_T *fp;
77 char *buf;
78 size_t n;
80 /* an error to read */
81 errno = ENODEV;
82 return -1;
86 ** SM_SYSLOGWRITE -- write function for syslog
88 ** Send output to syslog.
90 ** Parameters:
91 ** fp -- the file pointer
92 ** buf -- buffer that the write data comes from
93 ** n -- number of bytes to write
95 ** Returns:
96 ** 0 (zero) for success always
100 ** XXX TODO: more work needs to be done to ensure that each line of output
101 ** XXX written to a syslog file is mapped to exactly one syslog message.
103 ssize_t
104 sm_syslogwrite(fp, buf, n)
105 SM_FILE_T *fp;
106 char const *buf;
107 size_t n;
109 syslog(fp->f_ival, "%s", buf);
110 return 0;
114 ** SM_SYSLOGSEEK -- position the syslog file offset
116 ** This is a "stub" function (placeholder) that always returns an error.
117 ** It is an error to seek syslog.
119 ** Parameters:
120 ** fp -- the file pointer
121 ** offset -- the new offset position relative to 'whence'
122 ** whence -- flag indicating start of 'offset'
124 ** Returns:
125 ** -1 (error) always.
128 off_t
129 sm_syslogseek(fp, offset, whence)
130 SM_FILE_T *fp;
131 off_t offset;
132 int whence;
134 errno = ENODEV;
135 return -1;
139 ** SM_SYSLOGCLOSE -- close the syslog file pointer
141 ** Parameters:
142 ** fp -- the file pointer
144 ** Returns:
145 ** 0 (zero) success always (see Overall)
150 sm_syslogclose(fp)
151 SM_FILE_T *fp;
153 return 0;
157 ** SM_SYSLOGSETINFO -- set information for the file pointer
159 ** Parameters:
160 ** fp -- the file pointer being set
161 ** what -- what information is being set
162 ** valp -- information content being set to
164 ** Returns:
165 ** -1 on failure
166 ** 0 (zero) on success
168 ** Side Effects:
169 ** Sets internal file pointer data
173 sm_syslogsetinfo(fp, what, valp)
174 SM_FILE_T *fp;
175 int what;
176 void *valp;
178 switch (what)
180 case SM_IO_SL_PRIO:
181 fp->f_ival = *((int *)(valp));
182 return 0;
183 default:
184 errno = EINVAL;
185 return -1;
190 ** SM_SYSLOGGETINFO -- get information relating to the file pointer
192 ** Parameters:
193 ** fp -- the file pointer being queried
194 ** what -- the information type being queried
195 ** valp -- location to placed queried information
197 ** Returns:
198 ** 0 (zero) on success
199 ** -1 on failure
201 ** Side Effects:
202 ** Fills in 'valp' with data.
206 sm_sysloggetinfo(fp, what, valp)
207 SM_FILE_T *fp;
208 int what;
209 void *valp;
211 switch (what)
213 case SM_IO_SL_PRIO:
214 *((int *)(valp)) = fp->f_ival;
215 return 0;
216 default:
217 errno = EINVAL;
218 return -1;