void gui_nonfatal(const char *fmt, ...) { va_list args; va_start(args, fmt); produce_message("Information", fmt, args); va_end(args); }
void gui_fatal(const char *fmt, ...) { va_list args; va_start(args, fmt); produce_message("Fatal error", fmt, args); va_end(args); exit(1); }
/** * Produces a single file exits hard on error. */ static int produce_file (FILE *fp) { char *sbuf = NULL; size_t size = 0; ssize_t len; int ret = 0; /* Read messages from fp, delimited by conf.delim */ while (conf.run && (len = getdelim(&sbuf, &size, conf.delim, fp)) != -1) { int msgflags = 0; char *buf = sbuf; char *key = NULL; size_t key_len = 0; size_t orig_len = len; if (len == 0) continue; /* Shave off delimiter */ if ((int)buf[len-1] == conf.delim) len--; if (len == 0) continue; /* Extract key, if desired and found. */ if (conf.flags & CONF_F_KEY_DELIM) { char *t; if ((t = memchr(buf, conf.key_delim, len))) { key_len = (size_t)(t-sbuf); key = buf; buf += key_len+1; len -= key_len+1; } } if (len > 1024 && !(conf.flags & CONF_F_TEE)) { /* If message is larger than this arbitrary * threshold it will be more effective to * not copy the data but let rdkafka own it * instead. * * Note that CONF_T_TEE must be checked, * otherwise a possible race might occur. */ msgflags |= RD_KAFKA_MSG_F_FREE; } else { /* For smaller messages a copy is * more efficient. */ msgflags |= RD_KAFKA_MSG_F_COPY; } /* Produce message */ if (produce_message(buf, len, key, key_len, msgflags) == -1) { ret = -1; break; } if (conf.flags & CONF_F_TEE && fwrite(sbuf, orig_len, 1, stdout) != 1) FATAL("Tee write error for message of %zd bytes: %s", orig_len, strerror(errno)); if (msgflags & RD_KAFKA_MSG_F_FREE) { /* rdkafka owns the allocated buffer * memory now. */ sbuf = NULL; size = 0; } /* Enforce -c <cnt> */ if (stats.tx == conf.msg_cnt) conf.run = 0; } if (conf.run) { if (!feof(fp)) FATAL("Unable to read message: %s", strerror(errno)); } if (sbuf) free(sbuf); return ret; }
void qfile_gui_fatal(const char *fmt, va_list args) { produce_message("Fatal error", fmt, args); exit(1); }