2 * libdpkg - Debian packaging suite library routines
3 * log.c - logging related functions
5 * Copyright © 2005 Scott James Remnant <scott@netsplit.com>
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
30 #include <dpkg/i18n.h>
31 #include <dpkg/dpkg.h>
32 #include <dpkg/dpkg-db.h>
33 #include <dpkg/fdio.h>
35 const char *log_file
= NULL
;
38 log_message(const char *fmt
, ...)
40 static struct varbuf log
;
41 static FILE *logfd
= NULL
;
50 logfd
= fopen(log_file
, "a");
52 notice(_("could not open log '%s': %s"),
53 log_file
, strerror(errno
));
58 setcloexec(fileno(logfd
), log_file
);
63 varbuf_vprintf(&log
, fmt
, args
);
67 strftime(time_str
, sizeof(time_str
), "%Y-%m-%d %H:%M:%S",
69 fprintf(logfd
, "%s %s\n", time_str
, log
.buf
);
77 static struct pipef
*status_pipes
= NULL
;
82 struct pipef
*pipe_new
;
84 setcloexec(fd
, _("<package status and progress file descriptor>"));
86 pipe_new
= nfmalloc(sizeof(struct pipef
));
88 pipe_new
->next
= status_pipes
;
89 status_pipes
= pipe_new
;
93 statusfd_send(const char *fmt
, ...)
95 static struct varbuf vb
;
104 varbuf_vprintf(&vb
, fmt
, args
);
105 /* Sanitize string to not include new lines, as front-ends should be
106 * doing their own word-wrapping. */
107 varbuf_map_char(&vb
, '\n', ' ');
108 varbuf_add_char(&vb
, '\n');
111 for (pipef
= status_pipes
; pipef
; pipef
= pipef
->next
) {
112 if (fd_write(pipef
->fd
, vb
.buf
, vb
.used
) < 0)
113 ohshite(_("unable to write to status fd %d"),