[syslog-ng] pipe cleanup
Balazs Scheidler
bazsi@balabit.hu
Sat, 4 Mar 2000 21:10:45 +0100
Hi,
I've began working on 1.5.0 and cleaned up pipe support. Thanks for the idea
about O_RDWR pipes for "Klaus Groenhoej" <kgr@kmd.dk>. No need to check for
spuriously closed pipes now.
I've backported the patch to 1.4.0 and is available attached to this mail.
This adds no additional functionality, and 1.4.0 should be o.k. as well, so
I don't release 1.4.1 immediately, rather I wait for feedback on 1.4.0.
Index: affile.c
===================================================================
RCS file: /home/bazsi/cvs/syslog-ng/src/affile.c,v
retrieving revision 1.30
diff -u -r1.30 affile.c
--- affile.c 2000/03/03 14:43:20 1.30
+++ affile.c 2000/03/04 19:56:34
@@ -179,7 +179,6 @@
(vars
(owner object affile_dest)
(dest object io_fd)
- (dest_buf object abstract_buffer)
(reap simple "struct callout *")
(expanded_fname string)
(prev object affile_dest_writer)
@@ -190,42 +189,30 @@
do_init_dest_writer(struct log_handler *c, struct syslog_config *cfg, struct persistent_config *persistent)
{
CAST(affile_dest_writer, self, c);
- int fd;
+ int fd, flags;
- if (self->dest)
- self->dest->buffer = NULL;
- if (!self->dest_buf)
- self->dest_buf = make_pkt_buffer_ext(self->owner->sync_freq,
- MAX(self->owner->super.log_fifo_size + 1,
- self->owner->sync_freq));
- self->dest = NULL;
- if (do_open_file(self->expanded_fname, O_WRONLY | O_CREAT | O_APPEND | O_NOCTTY | O_NONBLOCK, self->owner->perm, self->owner->flags & AFFILE_CREATE_DIRS, self->owner->dir_perm, &fd)) {
- struct resource_node *res;
+ if (self->owner->flags & AFFILE_PIPE)
+ flags = O_RDWR | O_NOCTTY | O_NONBLOCK;
+ else
+ flags = O_WRONLY | O_CREAT | O_APPEND |O_NOCTTY | O_NONBLOCK;
+ if (do_open_file(self->expanded_fname, flags, self->owner->perm, self->owner->flags & AFFILE_CREATE_DIRS, self->owner->dir_perm, &fd)) {
chown(self->expanded_fname->data, self->owner->uid, self->owner->gid);
- self->dest = io_write(make_io_fd(cfg->backend, fd),
- self->dest_buf,
- NULL);
- res = REMEMBER_RESOURCE(cfg->resources, &self->dest->super.super);
- self->dest->super.close_callback =
- make_driver_reinit_on_close(c, res, cfg->time_reopen, cfg);
+ self->dest =
+ io_write(make_io_fd(cfg->backend, fd),
+ make_pkt_buffer_ext(self->owner->sync_freq,
+ MAX(self->owner->super.log_fifo_size + 1,
+ self->owner->sync_freq)),
+ NULL);
+ REMEMBER_RESOURCE(cfg->resources, &self->dest->super.super);
if ((self->owner->flags & AFFILE_NO_EXPAND) == 0)
self->reap = io_callout(cfg->backend, TIME_REAP_DEST, make_affile_dest_reaper(self));
/* self->attempts = 0; */
}
else {
- if (errno == ENXIO) {
- /* opening the write side of the fifo failed */
- /* self->attempts++; */
- io_callout(cfg->backend, cfg->time_reopen, make_driver_reinit(c, cfg));
- if ((self->owner->flags & AFFILE_NO_EXPAND) == 0)
- self->reap = io_callout(cfg->backend, TIME_REAP_DEST, make_affile_dest_reaper(self));
- }
- else {
- werror("Cannot open file %S for writing (%z)\n", self->expanded_fname, strerror(errno));
- return ST_FAIL | ST_QUIT;
- }
+ werror("Cannot open file %S for writing (%z)\n", self->expanded_fname, strerror(errno));
+ return ST_FAIL | ST_QUIT;
}
return ST_OK | ST_GOON;
@@ -235,8 +222,8 @@
{
CAST(affile_dest_writer, self, c);
- if (self->dest_buf) {
- A_WRITE_STRING(&self->dest_buf->super, c_format("%S %S %S\n", msg->date, msg->host, msg->msg));
+ if (self->dest) {
+ A_WRITE_STRING(&self->dest->buffer->super, c_format("%S %S %S\n", msg->date, msg->host, msg->msg));
if (self->reap)
io_callout_set_timeout(self->reap, TIME_REAP_DEST);
}
--
Bazsi
PGP info: KeyID 9AF8D0A9 Fingerprint CD27 CFB0 802C 0944 9CFD 804E C82C 8EB1
url: http://www.balabit.hu/pgpkey.txt