From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=DATE_IN_PAST_12_24 autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 31149 invoked from network); 19 Oct 2021 09:18:27 -0000 Received: from 4ess.inri.net (216.126.196.42) by inbox.vuxu.org with ESMTPUTF8; 19 Oct 2021 09:18:27 -0000 Received: from duke.felloff.net ([216.126.196.34]) by 4ess; Mon Oct 18 15:40:43 -0400 2021 Message-ID: Date: Mon, 18 Oct 2021 21:40:33 +0200 From: cinap_lenrek@felloff.net To: 9front@9front.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: descriptor DOM standard hypervisor-oriented table Subject: =?utf-8?q?Re:_[9front]_Re:_[9front]_Re:_[9front]_Dealing_with_log_files=E2=80=A6?= Reply-To: 9front@9front.org Precedence: bulk > i dont get this, plan9 services all (to my knowledge) open and > close the logfile on each message so you can just rename the logfile > and touch and chmod a new one. interesting point. according to the code, it keeps the fd around, but it checks for each message if the file name or qid changed... but apparently only for some kind of race condition when the fd got closed and reopand after a rfork(RFCFD) if the dirstat fails, it will also reopen, but leak the old file descriptors (as it assumes it is the fd realloc race). the result is indeed that the file gets reopend when you rename the old file and create a new one. -- cinap PS: /sys/src/libc/9sys/syslog.c /* * Print * sysname: time: mesg * on /sys/log/logname. * If cons or log file can't be opened, print on the system console, too. */ void syslog(int cons, char *logname, char *fmt, ...) { char buf[1024]; char *ctim, *p; va_list arg; int n; Dir *d; char err[ERRMAX]; err[0] = '\0'; errstr(err, sizeof err); lock(&sl); /* * paranoia makes us stat to make sure a fork+close * hasn't broken our fd's */ d = dirfstat(sl.fd); if(sl.fd < 0 || sl.name == nil || strcmp(sl.name, logname) != 0 || !eqdirdev(d, sl.d)){ free(sl.name); sl.name = strdup(logname); if(sl.name == nil) cons = 1; else{ free(sl.d); sl.d = nil; _syslogopen(); if(sl.fd < 0) cons = 1; else sl.d = dirfstat(sl.fd); } } free(d); if(cons){ d = dirfstat(sl.consfd); if(sl.consfd < 0 || !eqdirdev(d, sl.consd)){ free(sl.consd); sl.consd = nil; sl.consfd = open("#c/cons", OWRITE|OCEXEC); if(sl.consfd >= 0) sl.consd = dirfstat(sl.consfd); } free(d); } if(fmt == nil){ unlock(&sl); return; } ctim = ctime(time(0)); p = buf + snprint(buf, sizeof(buf)-1, "%s ", sysname()); strncpy(p, ctim+4, 15); p += 15; *p++ = ' '; errstr(err, sizeof err); va_start(arg, fmt); p = vseprint(p, buf+sizeof(buf)-1, fmt, arg); va_end(arg); *p++ = '\n'; n = p - buf; if(sl.fd >= 0){ seek(sl.fd, 0, 2); write(sl.fd, buf, n); } if(cons && sl.consfd >=0) write(sl.consfd, buf, n); unlock(&sl); }