void statusfd_send(const char *fmt, ...) { static struct varbuf vb; struct pipef *pipef; va_list args; if (!status_pipes) return; va_start(args, fmt); varbuf_reset(&vb); varbuf_vprintf(&vb, fmt, args); /* Sanitize string to not include new lines, as front-ends should be * doing their own word-wrapping. */ varbuf_map_char(&vb, '\n', ' '); varbuf_add_char(&vb, '\n'); va_end(args); for (pipef = status_pipes; pipef; pipef = pipef->next) { if (fd_write(pipef->fd, vb.buf, vb.used) < 0) ohshite(_("unable to write to status fd %d"), pipef->fd); } }
void log_message(const char *fmt, ...) { static struct varbuf log; static FILE *logfd = NULL; char time_str[20]; time_t now; va_list args; if (!log_file) return; if (!logfd) { logfd = fopen(log_file, "a"); if (!logfd) { notice(_("could not open log '%s': %s"), log_file, strerror(errno)); log_file = NULL; return; } setlinebuf(logfd); setcloexec(fileno(logfd), log_file); } va_start(args, fmt); varbuf_reset(&log); varbuf_vprintf(&log, fmt, args); va_end(args); time(&now); strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", localtime(&now)); fprintf(logfd, "%s %s\n", time_str, log.buf); }
int varbuf_printf(struct varbuf *v, const char *fmt, ...) { int r; va_list args; va_start(args, fmt); r = varbuf_vprintf(v, fmt, args); va_end(args); return r; }
dpkg_error_set(struct dpkg_error *err, int type, const char *fmt, va_list args) { struct varbuf str = VARBUF_INIT; if (err == NULL) return; err->type = type; varbuf_vprintf(&str, fmt, args); err->str = str.buf; }
void compress_filter(struct compress_params *params, int fd_in, int fd_out, const char *desc_fmt, ...) { va_list args; struct varbuf desc = VARBUF_INIT; va_start(args, desc_fmt); varbuf_vprintf(&desc, desc_fmt, args); va_end(args); compressor(params->type)->compress(fd_in, fd_out, params, desc.buf); }
void decompress_filter(enum compressor_type type, int fd_in, int fd_out, const char *desc_fmt, ...) { va_list args; struct varbuf desc = VARBUF_INIT; va_start(args, desc_fmt); varbuf_vprintf(&desc, desc_fmt, args); va_end(args); compressor(type)->decompress(fd_in, fd_out, desc.buf); }