1 /*
2 * Copyright (c) 2002-2013 Balabit
3 * Copyright (c) 1998-2013 Balázs Scheidler
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * As an additional exemption you are allowed to compile & link against the
20 * OpenSSL libraries as published by the OpenSSL project. See the file
21 * COPYING for details.
22 *
23 */
24
25 #include "logtransport.h"
26 #include "messages.h"
27
28 #include <unistd.h>
29
30 void
log_transport_free_method(LogTransport * s)31 log_transport_free_method(LogTransport *s)
32 {
33 if (s->fd != -1)
34 {
35 msg_trace("Closing log transport fd",
36 evt_tag_int("fd", s->fd));
37 close(s->fd);
38 }
39 }
40
41 void
log_transport_init_instance(LogTransport * self,gint fd)42 log_transport_init_instance(LogTransport *self, gint fd)
43 {
44 self->fd = fd;
45 self->cond = 0;
46 self->free_fn = log_transport_free_method;
47 }
48
49 void
log_transport_free(LogTransport * self)50 log_transport_free(LogTransport *self)
51 {
52 self->free_fn(self);
53 g_free(self);
54 }
55
56 gint
log_transport_release_fd(LogTransport * s)57 log_transport_release_fd(LogTransport *s)
58 {
59 gint fd = s->fd;
60 s->fd = -1;
61
62 return fd;
63 }
64
65