Exemple #1
0
int main(int argc, char *argv[])
{
	char *password;
	int port = DEFAULT_LISTEN_PORT;
	parameters_t pars;
	struct sched_param sched_par;

	openlog("tcpconsole", LOG_CONS|LOG_NDELAY|LOG_NOWAIT|LOG_PID, LOG_DAEMON);

	if (getuid())
		error_exit("This program must be invoked with root-rights.");

	password = read_password("/etc/tcpconsole.pw");

	if (signal(SIGTERM, SIG_IGN) == SIG_ERR)
		error_exit("signal(SIGTERM) failed");

	if (signal(SIGHUP,  SIG_IGN) == SIG_ERR)
		error_exit("signal(SIGHUP) failed");

	pars.sysrq_fd = open_file("/proc/sysrq-trigger", O_WRONLY);
	pars.vcsa0_fd = open_file("/dev/vcsa", O_RDONLY);

	if (setpriority(PRIO_PROCESS, 0, -10) == -1)
		error_exit("Setpriority failed");

	if (nice(-20) == -1)
		error_exit("Failed to set nice-value to -20");

	if (mlockall(MCL_CURRENT) == -1 || mlockall(MCL_FUTURE) == -1)
		error_exit("Failed to lock program in core");

	memset(&sched_par, 0x00, sizeof(sched_par));
	sched_par.sched_priority = sched_get_priority_max(SCHED_RR);
	if (sched_setscheduler(0, SCHED_RR, &sched_par) == -1)
		error_exit("Failed to set scheduler properties for this process");

	syslog(LOG_INFO, "tcpconsole started");

	write_pidfile("/var/run/tcpconsole.pid");

	if ((pars.dmesg_buffer_size = klogctl(10, NULL, 0)) == -1)
		error_exit("klogctl(10) failed");
	pars.dmesg_buffer = (char *)malloc(pars.dmesg_buffer_size + 1);
	if (!pars.dmesg_buffer)
		error_exit("malloc failure");

	listen_on_socket(port, &pars, password);

	return 1;
}
Exemple #2
0
connection *comm_connect(char *ipaddress, int connections) {
	int i, port;
	connection *conn;
	
	if (in_thread == NULL) start_threads();
	if (connections < 1) return NULL;
	if (ipaddress == NULL) return NULL;
	
	conn = (connection *) malloc(sizeof(connection));
	
	conn->label = strdup(ipaddress);
	conn->connected = 0;
	conn->sockets = (out_socket *) malloc(connections * sizeof(out_socket));
	conn->num_sockets = connections;
	
	// setup the outgoing connections
	for (i = 0; i < connections; i++) {
		conn->sockets[i].fd = connect_to_socket(ipaddress, SOPHIA_PORT);
		set_non_blocking(conn->sockets[i].fd);
		pthread_mutex_init(&(conn->sockets[i].fd_lock), 0);
		conn->sockets[i].backlog = 0;
		conn->sockets[i].done = 0;
	}
	
	conn->connected = 1;
	
	// setup the rget connection
	conn->rget_settings.buffer = cbuf_new();
	conn->rget_settings.client_fd = -1;
	
	conn->rget_settings.server_fd = -1;
	while( conn->rget_settings.server_fd < 0 ) {
		port = randomise_port();
		conn->rget_settings.server_fd = listen_on_socket(port);
	}
	
	// comm_send(conn, 1, "void", 1, NULL, NULL, "[RGetRegisterClient \"%d\" \"%s\"]", port, "10.0.0.12"); // REMOTE get_local_ip());
	comm_send(conn, 1, "void", 1, NULL, NULL, "[RGetRegisterClient \"%d\" \"%s\"]", port, get_local_ip(conn->sockets[0].fd));
	// wait to accept the rget connection
	while (conn->rget_settings.client_fd < 0) { conn->rget_settings.client_fd = accept(conn->rget_settings.server_fd, NULL, 0); }
	
	// add this connect to the inbound subsystem
	comm_in_add(&(conn->rget_settings));
	
	return conn;
}