about summary refs log tree commit diff
path: root/log.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--log.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/log.c b/log.c
index af8f66e..9cd6557 100644
--- a/log.c
+++ b/log.c
@@ -80,11 +80,11 @@ static FILE *logFile(struct Tag tag, const struct tm *time) {
 	char path[sizeof("YYYY-MM-DD.log")];
 	strftime(path, sizeof(path), "%F.log", time);
 	int fd = openat(
-		log->dir, path, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, 0600
+		log->dir, path, O_RDWR | O_APPEND | O_CREAT | O_CLOEXEC, 0600
 	);
 	if (fd < 0) err(EX_CANTCREAT, "%s/%s", tag.name, path);
 
-	log->file = fdopen(fd, "a");
+	log->file = fdopen(fd, "a+");
 	if (!log->file) err(EX_CANTCREAT, "%s/%s", tag.name, path);
 	setlinebuf(log->file);
 
@@ -119,3 +119,21 @@ void logFmt(struct Tag tag, const time_t *ts, const char *format, ...) {
 	fprintf(file, "\n");
 	if (ferror(file)) err(EX_IOERR, "%s", tag.name);
 }
+
+void logReplay(struct Tag tag) {
+	if (logRoot < 0) return;
+
+	time_t t = time(NULL);
+	struct tm *time = localtime(&t);
+	if (!time) err(EX_SOFTWARE, "localtime");
+
+	FILE *file = logFile(tag, time);
+	rewind(file);
+
+	size_t len;
+	char *line;
+	while (NULL != (line = fgetln(file, &len))) {
+		uiFmt(tag, UICold, "\3%d%.*s", IRCGray, (int)(len - 1), line);
+	}
+	if (ferror(file)) err(EX_IOERR, "%s", tag.name);
+}
9-11-08 17:25:48 -0500'>2019-11-08Only change AWAY status for registered clientsJune McEnroe Turns out I did eventually fix this, because I may want to implement "passive clients" for logging or notification stuff, which wouldn't affect AWAY status either. 2019-11-07Just write the example normallyJune McEnroe 2019-11-07Include path in readlinkat errorJune McEnroe 2019-11-07Call clientConsume before clientRecvJune McEnroe This might reduce the frequency of a client getting its own message back because it was behind in the ring when it sent it. 2019-11-06Use -l:filename in Linux.mkJune McEnroe 2019-11-06Fix compat.h for #defined strlcpyJune McEnroe 2019-11-06Allow unsetting LIBRESSL_PREFIXJune McEnroe 2019-11-06Document calico service configurationJune McEnroe 2019-11-06Document SASL EXTERNAL configuration in more detailJune McEnroe 2019-11-06Document pounce service configurationJune McEnroe 2019-11-06Mention Darwin and GNU/Linux in READMEJune McEnroe 2019-11-06Assume LibreSSL from brew on DarwinJune McEnroe 2019-11-06Remove -DNO_EXPLICIT_BZERO from Darwin.mkJune McEnroe 2019-11-06Don't install rc scripts or dirs on LinuxJune McEnroe58a9811f7a869949&follow=1'>Fix whois idle unit calculationJune McEnroe 2020-02-11Cast towupper to wchar_tJune McEnroe 2020-02-11Cast set but unused variables to voidJune McEnroe 2020-02-11Declare strlcatJune McEnroe 2020-02-11Check if VDSUSP existsJune McEnroe 2020-02-11Fix completeReplace iterationJune McEnroe 2020-02-11Use pkg(8) to configure on FreeBSDJune McEnroe 2020-02-11Remove legacy codeJune McEnroe 2020-02-11Add INSTALLING section to READMEJune McEnroe