Plan 9 from Bell Labs’s /usr/web/sources/contrib/aiju/netconsole.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <thread.h>

int s;

void
keyproc(void*)
{
	while(1) {
		char buf[512];
		int n = read(0, buf, 511);
		if(n < 0) sysfatal("read: %r");
		buf[n] = 0;
		if(strchr(buf, 127)) threadexitsall(0);
		if(write(s, buf, n) < 0) sysfatal("write: %r");
	}
}

void
threadmain(int argc, char** argv)
{
	if(argc != 2 && argc != 3) {
		print("usage: %s target-ip [port]\n", argv[0]);
		exits("usage");
	}
	char *target = argv[1];
	char *port = argv[2] ? argv[2] : "6666";
	char devdir[128];
	s = dial(netmkaddr(target, "udp", port), port, devdir, 0);
	if(s < 0) sysfatal("dial: %r");
	strcat(devdir, "/ctl");
	int udpctl = open(devdir, OWRITE);
	if(udpctl >= 0)
		write(udpctl, "ignoreadvice", 13);
	int consctl = open("/dev/consctl", OWRITE);
	if(consctl < 0) sysfatal("open consctl: %r");
	if(write(consctl, "rawon", 5) < 0) sysfatal("write to consctl: %r");
	proccreate(keyproc, 0, 8000);
	while(1) {
		char buf[512];
		int n = read(s, buf, 511);
		if(n < 0) sysfatal("read: %r");
		if(write(1, buf, n) < 0) sysfatal("write: %r");
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].