Based on a patch by Ian Jackson <ian@davenant.greenend.org.uk>.
+2008-03-25 Ian Jackson <ian@davenant.greenend.org.uk>,
+ Guillem Jover <guillem@debian.org>
+
+ * lib/dbmodify.c (status_pipes): Move definitions to ...
+ * lib/log.c: ... here.
+ * lib/dpkg-db.h (struct pipef, status_pipes): Move declarations to ...
+ * lib/dpkg.h: ... here.
+ (statusfd_send): New function protoype.
+ * lib/log.c: Include <assert.h> and <unistd.h>.
+ (statusfd_send): New function.
+ * lib/dbmodify.c: Use statusfd_send instead of duplicate code.
+ * src/configure.c: Likewise.
+ * src/errors.c: Likewise.
+
2008-03-25 Guillem Jover <guillem@debian.org>
* lib/dbmodify.c (log_file, log_message): Move to ...
------
* Code cleanup:
- - Coalesce status_pipe handling.
- blankfoo embedded code.
- static variables inside functions.
- Coalesce admindir / infodir / foodir generation.
free(updatefnbuf);
}
-struct pipef *status_pipes= NULL;
-
void modstatdb_note(struct pkginfo *pkg) {
assert(cstatus >= msdbrw_write);
onerr_abort++;
- if (status_pipes) {
- static struct varbuf *status= NULL;
- struct pipef *pipef= status_pipes;
- int r;
- if (status == NULL) {
- status = nfmalloc(sizeof(struct varbuf));
- varbufinit(status);
- } else
- varbufreset(status);
- r= varbufprintf(status, "status: %s: %s\n", pkg->name, statusinfos[pkg->status].name);
- while (pipef) {
- write(pipef->fd, status->buf, r);
- pipef= pipef->next;
- }
- }
log_message("status %s %s %s", statusinfos[pkg->status].name, pkg->name,
versiondescribe(&pkg->installed.version, vdew_nonambig));
+ statusfd_send("status: %s: %s", pkg->name, statusinfos[pkg->status].name);
varbufreset(&uvb);
varbufrecord(&uvb, pkg, &pkg->installed);
msdbrw_noavail= 0100,
};
-struct pipef {
- int fd;
- struct pipef *next;
-};
-extern struct pipef *status_pipes;
-
enum modstatdb_rw modstatdb_init(const char *admindir, enum modstatdb_rw reqrwflags);
void modstatdb_note(struct pkginfo *pkg);
void modstatdb_checkpoint(void);
extern const char *log_file;
void log_message(const char *fmt, ...) PRINTFFORMAT(1, 2);
+/* FIXME: pipef and status_pipes should not be publicly exposed. */
+struct pipef {
+ int fd;
+ struct pipef *next;
+};
+extern struct pipef *status_pipes;
+
+void statusfd_send(const char *fmt, ...);
+
/*** cleanup.c ***/
void cu_closefile(int argc, void **argv);
#include <config.h>
+#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
+#include <unistd.h>
#include <time.h>
#include <errno.h>
fprintf(logfd, "%s %s\n", time_str, log->buf);
}
+struct pipef *status_pipes = NULL;
+
+void
+statusfd_send(const char *fmt, ...)
+{
+ static struct varbuf vb;
+ struct pipef *pipef;
+ const char *p;
+ int r, l;
+ va_list al;
+
+ if (!status_pipes)
+ return;
+
+ va_start(al, fmt);
+ varbufreset(&vb);
+ varbufvprintf(&vb, fmt, al);
+ varbufaddc(&vb, '\n');
+ va_end(al);
+
+ for (pipef = status_pipes; pipef; pipef = pipef->next) {
+ for (p = vb.buf, l = vb.used; l; p += r, l -= r) {
+ r = write(pipef->fd, vb.buf, vb.used);
+ if (r < 0)
+ ohshite("unable to write to status fd %d",
+ pipef->fd);
+ assert(r && r <= l);
+ }
+ }
+}
+
if (!(what&cfof_prompt))
return what;
- /* if there is a status pipe, send conffile-prompt there */
- if (status_pipes) {
- static struct varbuf *status= NULL;
- struct pipef *pipef= status_pipes;
- int r;
- if (status == NULL) {
- status = nfmalloc(sizeof(struct varbuf));
- varbufinit(status);
- } else
- varbufreset(status);
-
- r= varbufprintf(status, "status: %s : %s : '%s' '%s' %i %i \n",
+ statusfd_send("status: %s : %s : '%s' '%s' %i %i ",
cfgfile, "conffile-prompt",
realold, realnew, useredited, distedited);
- while (pipef) {
- write(pipef->fd, status->buf, r);
- pipef= pipef->next;
- }
- }
do {
/* Flush the terminal's input in case the user
fprintf(stderr, _("%s: error processing %s (--%s):\n %s\n"),
DPKG, arg, cipaction->olong, emsg);
- if (status_pipes) {
- static struct varbuf *status= NULL;
- struct pipef *pipef= status_pipes;
- int r;
- if (status == NULL) {
- status = nfmalloc(sizeof(struct varbuf));
- varbufinit(status);
- } else
- varbufreset(status);
-
- r= varbufprintf(status, "status: %s : %s : %s\n", arg, "error",emsg);
- while (pipef) {
- write(pipef->fd, status->buf, r);
- pipef= pipef->next;
- }
- }
-
+ statusfd_send("status: %s : %s : %s", arg, "error", emsg);
nr= malloc(sizeof(struct error_report));
if (!nr) {