mjl avatar mjl committed ee6335d Draft

use syslog_r, not syslog. from patch by Matthias Bauer.

Comments (0)

Files changed (3)

 };
 
 extern int debugflag;
+extern struct syslog_data sdata;
 	char *port;
 };
 
+struct syslog_data sdata = SYSLOG_DATA_INIT;
+
 static int fflag;
 static int vflag;
 
 		n = preadn(datafd, data, want, offset);
 		if(n <= 0) {
 			*errmsg = "error reading header";
-			syslog(LOG_WARNING, "disklookup: error reading header for block at offset=%llu, score=%s type=%d: %s",
+			syslog_r(LOG_WARNING, &sdata, "disklookup: error reading header for block at offset=%llu, score=%s type=%d: %s",
 				offset, scorestr(score), (int)type, (n < 0) ? strerror(errno) : "end of file");
 			continue;
 		}
 		if(n < Diskdheadersize) {
 			*errmsg = "short read for header";
-			syslog(LOG_WARNING, "disklookup: short read for header for block at offset=%llu, have=%d, score=%s type=%d",
+			syslog_r(LOG_WARNING, &sdata, "disklookup: short read for header for block at offset=%llu, have=%d, score=%s type=%d",
 				offset, n, scorestr(score), (int)type);
 			continue;
 		}
 		err = unpackdheader(data, dh);
 		if(err != nil) {
 			*errmsg = err;
-			syslog(LOG_WARNING, "disklookup: unpacking header for block at offset=%llu, score=%s type=%d: %s",
+			syslog_r(LOG_WARNING, &sdata, "disklookup: unpacking header for block at offset=%llu, score=%s type=%d: %s",
 				offset, scorestr(score), (int)type, *errmsg);
 			continue;
 		}
 				n = preadn(datafd, data, dh->size, offset+Diskdheadersize);
 				if(n <= 0) {
 					*errmsg = "disklookup: error reading data";
-					syslog(LOG_WARNING, "error reading data for block at offset=%llu, score=%s type=%d: %s",
+					syslog_r(LOG_WARNING, &sdata, "error reading data for block at offset=%llu, score=%s type=%d: %s",
 						offset, scorestr(score), (int)type, (n < 0) ? strerror(errno) : "end of file");
 				}
 				if(n != dh->size) {
 					*errmsg = "disklookup: short read for data";
-					syslog(LOG_WARNING, "short read for data for block at offset=%llu, have=%d, score=%s type=%d",
+					syslog_r(LOG_WARNING, &sdata, "short read for data for block at offset=%llu, have=%d, score=%s type=%d",
 						offset, n, scorestr(score), (int)type);
 				}
 			} else {
 			sha1(diskscore, data, dh->size);
 			if(memcmp(diskscore, score, Scoresize) != 0) {
 				*errmsg = "score on disk invalid";
-				syslog(LOG_ALERT, "disklookup: datafile %s has wrong score (has %s, claims %s) in block at offset=%llu size=%d type=%d",
+				syslog_r(LOG_ALERT, &sdata, "disklookup: datafile %s has wrong score (has %s, claims %s) in block at offset=%llu size=%d type=%d",
 					datafile, scorestr(diskscore), scorestr(dh->score), offset, (int)dh->size, (int)dh->type);
 				return ~0ULL;
 			}
 		snprintf(errmsg, sizeof errmsg,
 			"indexstore: writing header to indexfile %s at offset=%llu for datafile block at offset=%llu: %s",
 			indexfile, indexfilesize, ih->offset, (n < 0) ? strerror(errno) : "end of file");
-		syslog(LOG_ALERT, "%s", errmsg);
+		syslog_r(LOG_ALERT, &sdata, "%s", errmsg);
 		return errmsg;
 	}
 	if(n != sizeof ihbuf) {
 			"indexstore: short write for header to indexfile %s at offset=%llu for datafile block at offset=%llu, "
 			"dangling bytes at end of datafile %s",
 			indexfile, indexfilesize, ih->offset, datafile);
-		syslog(LOG_ALERT, "%s", errmsg);
+		syslog_r(LOG_ALERT, &sdata, "%s", errmsg);
 		return errmsg;
 	}
 	return nil;
 
 	n = pwrite(datafd, buf, sizeof buf, offset);
 	if(n <= 0) {
-		syslog(LOG_ALERT, "store: writing header to datafile %s, block at offset=%llu, %s: %s",
+		syslog_r(LOG_ALERT, &sdata, "store: writing header to datafile %s, block at offset=%llu, %s: %s",
 			datafile, offset, dheaderfmt(dh), (n < 0) ? strerror(errno) : "end of file");
 		return ~0ULL;
 	}
 	if(n != sizeof buf) {
-		syslog(LOG_ALERT, "store: short write for header, %d dangling bytes at end of datafile %s, block at offset=%llu, %s",
+		syslog_r(LOG_ALERT, &sdata, "store: short write for header, %d dangling bytes at end of datafile %s, block at offset=%llu, %s",
 			n, datafile, offset, dheaderfmt(dh));
 		return ~0ULL;
 	}
 
 	n = pwrite(datafd, data, dh->size, offset+Diskdheadersize);
 	if(n <= 0) {
-		syslog(LOG_ALERT, "store: writing data to datafile %s, block at offset=%llu, %s: %s",
+		syslog_r(LOG_ALERT, &sdata, "store: writing data to datafile %s, block at offset=%llu, %s: %s",
 			datafile, offset, dheaderfmt(dh), (n < 0) ? strerror(errno) : "end of file");
 		return ~0ULL;
 	}
 	if(n != dh->size) {
-		syslog(LOG_ALERT, "store: short write for data, %d dangling bytes at end of datafile %s, "
+		syslog_r(LOG_ALERT, &sdata, "store: short write for data, %d dangling bytes at end of datafile %s, "
 			"block at offset=%llu, %s, header for partly written block remains at end of file!",
 			n+Diskdheadersize, datafile, offset, dheaderfmt(dh));
 		return ~0ULL;
 		dataread += Diskdheadersize+dh.size;
 		nindexadded++;
 	}
-	syslog(LOG_NOTICE, "added %llu entries from datafile (%llu bytes in datafile) to indexfile, in %.3fs",
+	syslog_r(LOG_NOTICE, &sdata, "added %llu entries from datafile (%llu bytes in datafile) to indexfile, in %.3fs",
 		nindexadded, dataread, (msec()-start)/1000.0);
 	nblocks = indexfilesize / Diskiheadersize;
 
 			errxsyslog(1, "error inserting in memory for indexfile offset=%llu", off);
 		off += sizeof ihbuf;
 	}
-	syslog(LOG_NOTICE, "init done, %llu bytes for heads, read %llu bytes in %.3fs from index, entire startup in %.3fs",
+	syslog_r(LOG_NOTICE, &sdata, "init done, %llu bytes for heads, read %llu bytes in %.3fs from index, entire startup in %.3fs",
 		len, indexfilesize, (msec()-start)/1000.0, (msec()-totalstart)/1000.0);
 
 	for(i = 0; i < nelem(diskhisto); i++)
 
 		switch(in.op) {
 		case Thello:
-			syslog(LOG_INFO, "read Thello after handshake");
+			syslog_r(LOG_INFO, &sdata, "read Thello after handshake");
 			goto done;
 			break;
 		case Tread:
 				if(out.data == nil) {
 					out.op = Rerror;
 					out.msg = "out of memory";
-					syslog(LOG_WARNING, "connproc: out of memory for read of size %u", (uint)dh.size);
+					syslog_r(LOG_WARNING, &sdata, "connproc: out of memory for read of size %u", (uint)dh.size);
 					break;
 				}
 				memcpy(out.data, databuf, dh.size);
 				stateset(Sdegraded);
 				out.op = Rerror;
 				out.msg = "error writing block";
-				syslog(LOG_WARNING, "connproc: error writing data, degraded to read-only mode");
+				syslog_r(LOG_WARNING, &sdata, "connproc: error writing data, degraded to read-only mode");
 				break;
 			}
 			if(okhdr == 0) {
 				stateset(Sdegraded);
 				out.op = Rerror;
 				out.msg = "out of memory";
-				syslog(LOG_WARNING, "connproc: out of memory for storing index entry, "
+				syslog_r(LOG_WARNING, &sdata, "connproc: out of memory for storing index entry, "
 					"data file was written, degraded to read-only mode");
 				break;
 			}
 				safe_sync();
 			goto done;
 		default:
-			syslog(LOG_NOTICE, "invalid op %d", in.op);
+			syslog_r(LOG_NOTICE, &sdata, "invalid op %d", in.op);
 			goto done;
 			break;
 		}
 
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, nil);
 
-	syslog(LOG_NOTICE, "listenproc: accepting connections...");
+	syslog_r(LOG_NOTICE, &sdata, "listenproc: accepting connections...");
 	for(;;) {
 		fd = accept(listenfd, (struct sockaddr *)&addr, &len);
 		if(fd < 0)
 			free(args->buf);
 		free(args);
 		free(thread);
-		syslog(LOG_WARNING, "listenproc: could not create process: %s", strerror(errno));
+		syslog_r(LOG_WARNING, &sdata, "listenproc: could not create process: %s", strerror(errno));
 	}
 	return nil;
 }
 	for(;;) {
 		sig = 0;
 		if(sigwait(&mask, &sig) != 0)
-			syslog(LOG_NOTICE, "sigwait returned an error, sig=%d: %s", sig, strerror(sig));
+			syslog_r(LOG_NOTICE, &sdata, "sigwait returned an error, sig=%d: %s", sig, strerror(sig));
 
 		switch(sig) {
 		case SIGUSR1:
 		case SIGINT:
 		case SIGTERM:
 			stateset(Sclosing);
-			syslog(LOG_INFO, "closing down");
+			syslog_r(LOG_INFO, &sdata, "closing down");
 			for(i = 0; i < nreadlistens; i++)
 				pthread_cancel(readlistenthread[i]);
 			for(i = 0; i < nwritelistens; i++)
 			pthread_cancel(syncprocthread);
 			fsync(datafd);
 			fsync(indexfd);
-			syslog(LOG_NOTICE, "data and index flushed, exiting...");
+			syslog_r(LOG_NOTICE, &sdata, "data and index flushed, exiting...");
 			exit(0);
 			break;
 		default:
-			syslog(LOG_NOTICE, "unexpected signal (%d)", sig);
+			syslog_r(LOG_NOTICE, &sdata, "unexpected signal (%d)", sig);
 		}
 	}
 }
 		nwriteaddrs++;
 	}
 
-	openlog("memventi", LOG_CONS|(fflag ? LOG_PERROR : 0), LOG_DAEMON);
+	openlog_r("memventi", LOG_CONS|(fflag ? LOG_PERROR : 0), LOG_DAEMON, &sdata);
 	setlogmask(LOG_UPTO(vflag ? LOG_DEBUG : LOG_NOTICE));
 
 	nreadlistens = nwritelistens = 0;
 		return nil;
 	alignedp = (void*)(((uintptr_t)p + pagesize - 1)&~(pagesize-1));
 	if(mlock(alignedp, len) != 0 && mlockwarn == 0) {
-		syslog(LOG_WARNING, "mlock failed on memory of len=%lu", len);
+		syslog_r(LOG_WARNING, &sdata, "mlock failed on memory of len=%lu", len);
 		mlockwarn++;
 	}
 	debug(LOG_DEBUG, "lockedmalloc, %lu bytes allocated", len);
 		p = msg+len;
 		snprintf(p, sizeof msg-len, ": %s", strerror(errno));
 	}
-	syslog(LOG_ERR, "%s", msg);
+	syslog_r(LOG_ERR, &sdata, "%s", msg);
 	exit(eval);
 }
 
 	va_list ap;
 
 	va_start(ap, fmt);
-	vsyslog(LOG_ERR, fmt, ap);
+	vsyslog_r(LOG_ERR, &sdata, fmt, ap);
 	va_end(ap);
 	exit(eval);
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.