Beispiel #1
0
/* Now that you can send ansi sequences, this is much less inportant.. */
void unflash (void)
{
#if !defined(WINNT) && !defined(__EMX__)

#if defined(HARD_UNFLASH) && !defined(CHARSET_CUSTOM)
	fwrite("\033c", 5, 1, current_ftarget);		/* hard reset */
#else
	fwrite("\033)0", 6, 1, current_ftarget);		/* soft reset */
#endif

#if defined(LATIN1)
	charset_lat1();
#elif defined(CHARSET_CUSTOM)
	charset_cst();
#else
	charset_ibmpc();
#endif

#endif
}
Beispiel #2
0
int main(int argc, char *argv[], char *envp[])
{
	char	*channel;

	debug_init();
	srand((unsigned)time(NULL));
	time(&start_time);
	time(&idle_time);
	time(&now);
#ifdef WINNT
	fprintf(stdout, "%s %s\r\n", nap_version, internal_version);
	fprintf(stdout, "%s\r\n", main_version);
#else
	fprintf(stdout, "%s %s\n", nap_version, internal_version);
	fprintf(stdout, "%s\n",  main_version);
#endif
	channel = parse_args(argv, argc, envp);

	FD_ZERO(&readables);
	FD_ZERO(&writables);
	
	if (term_init(NULL))
		_exit(1);

/* 	my_signal(SIGQUIT, SIG_IGN, 0);*/
	my_signal(SIGHUP, irc_exit_old, 0);
	my_signal(SIGTERM, irc_exit_old, 0);
	my_signal(SIGPIPE, SIG_IGN, 0);
	my_signal(SIGINT, cntl_c, 0);
	my_signal(SIGALRM, nothing, 0);
        my_signal(SIGCHLD, child_reap, 0);
	my_signal(SIGCONT, term_cont, 0);
	my_signal(SIGWINCH, sig_refresh_screen, 0);
	my_signal(SIGUSR1, sigusr1, 0);
	        
	if (!init_screen()) 
	{
		create_new_screen();
		new_window(main_screen);
	}

	init_keys();
	init_keys2();
	init_variables();
#ifdef WANT_THREAD
	init_share_mutexes();
#ifdef WANT_NSLOOKUP
	start_dns();
#endif
#ifdef WANT_MP3PLAYER
	start_mp3();
#endif

#ifdef GTK
	start_tgtk();
#endif
#endif
	build_status(current_window, NULL, 0);
	update_input(UPDATE_ALL);

#ifndef WINNT
	charset_ibmpc();
#endif
	load_scripts();
	read_unfinished_list();
	if (auto_connect)
	{
		int serv = 0;
		reload_save(NULL, NULL, NULL, NULL, 0);
		if (starting_server != -1)
			serv = starting_server;
		connect_to_server_by_refnum(serv, -1, create);
		current_window->server = serv;
		xterm_settitle();
	} 
	else
	{
		if (do_get_napigator)
			get_napigator();
		display_server_list();
	}
			
	set_input_prompt(current_window, get_string_var(INPUT_PROMPT_VAR), 0);
	for (;;)
		io("main");
#ifdef GUI1
	gui_exit();
#else
	nappanic("get_line() returned");
#endif
	return (-((int)0xdead));
}
Beispiel #3
0
void
reattach_tty(char *tty, char *password)
{
	int s = -1;
	char *name;
	struct sockaddr_in addr;
	struct hostent *hp;
	int len = 0;
	fd_set rd_fd;
	struct timeval tm = {0};
	char chr_c[] = "\003";

/*
 * this buffer has to be big enough to handle a full screen of
 * information from the detached process.
 */
	unsigned char buffer[6 * BIG_BUFFER_SIZE + 1];
	char *p;
	int port = 0;

#if defined (TIOCGWINSZ)
	struct winsize window;

#endif
	memset(&parm, 0, sizeof(struct param));

	if (!(name = find_detach_socket(socket_path, tty))) {
		fprintf(stderr, "No detached process to attach to.\r\n");
		_exit(1);
	}
	strcpy(parm.cookie, get_cookie(name));
	if (!*parm.cookie)
		_exit(1);
	if ((p = strrchr(name, '/')))
		p++;
	sscanf(p, "%d.%*s.%*s", &port);
	displays = 1;
	if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		displays = 0;
		_exit(1);
	}
	chmod(name, SOCKMODE);
	set_socket_options(s);
	memset(&addr, 0, sizeof(struct sockaddr_in));
	addr.sin_port = htons(port);
	addr.sin_family = AF_INET;
	if ((hp = gethostbyname("localhost")))
		memcpy(&addr.sin_addr, hp->h_addr, hp->h_length);
	else
		inet_aton("127.0.0.1", (struct in_addr *)&addr.sin_addr);
	if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
		fprintf(stderr, "connection refused for %s\r\n", name);
		_exit(1);
	}
	parm.pid = getpid();
	parm.pgrp = getpgrp();
	parm.uid = getuid();
	strcpy(parm.tty, ttyname(0));
	strncpy(parm.termid, getenv("TERM"), 80);
	if (password)
		strncpy(parm.password, password, 60);
	fprintf(stderr, "attempting to wakeup %s\r\n", find_tty_name(name));
#if defined (TIOCGWINSZ)
	if (ioctl(0, TIOCGWINSZ, &window) > -1) {
		parm.cols = window.ws_col;
		parm.rows = window.ws_row;
	} else
#endif
	{
		parm.cols = 79;
		parm.rows = 25;
	}
	write(s, &parm, sizeof(struct param));
	sleep(2);
	alarm(15);
	len = read(s, &parm, sizeof(struct param));
	alarm(0);
	if (len <= 0) {
		fprintf(stderr, "error reconnecting to %s\r\n", find_tty_name(name));
		displays = 0;
		chmod(name, SOCKMODE);
		exit(1);
	}
	unlink(name);

	term_init(parm.termid);
	set_term_eight_bit(1);
	charset_ibmpc();
	term_clear_screen();
	term_resize();
	term_move_cursor(0, 0);

	my_signal(SIGPIPE, handle_pipe, 0);
	my_signal(SIGINT, handle_ctrlc, 0);
	my_signal(SIGHUP, handle_hup, 0);

	/*
	 * according to MHacker we need to set errno to 0 under BSD.
	 * for some reason we get a address in use from a socket
	 *
	 */
	errno = 0;
	while (1) {
		FD_ZERO(&rd_fd);
		FD_SET(0, &rd_fd);
		FD_SET(s, &rd_fd);
		tm.tv_sec = 2;

		switch (select(s + 1, &rd_fd, NULL, NULL, &tm)) {
		case -1:
			if (ctrl_c) {
				write(s, chr_c, 1);
				ctrl_c = 0;
			} else if (errno != EINTR) {
				close(s);
				_exit(1);
			}
			break;
		case 0:
			break;
		default:
		{
			if (FD_ISSET(0, &rd_fd)) {
				len = read(0, buffer, sizeof(buffer) - 1);
				write(s, buffer, len);
			}
			if (FD_ISSET(s, &rd_fd)) {
				len = read(s, buffer, sizeof(buffer) - 1);
				write(1, buffer, len);
			}
		}
		}
	}
	close(s);
	fprintf(stderr, "Never should have got here");
	_exit(1);

	return;                         /* error return */
}