Ejemplo n.º 1
0
Archivo: yaft.c Proyecto: saitoha/yaft
void tty_init()
{
	extern struct tty_state tty; /* global var */
	struct sigaction sigact;
	struct vt_mode vtm;
	char *env;

	memset(&sigact, 0, sizeof(struct sigaction));
	sigact.sa_handler = handler;
	sigact.sa_flags = SA_RESTART;
	esigaction(SIGCHLD, &sigact, NULL);
	esigaction(SIGUSR1, &sigact, NULL);

	vtm.mode = VT_PROCESS;
	vtm.waitv = 0;
	vtm.relsig = vtm.acqsig = vtm.frsig = SIGUSR1;
	if (ioctl(STDIN_FILENO, VT_SETMODE, &vtm))
		fatal("ioctl: VT_SETMODE failed (maybe here is not console)");
	if (ioctl(STDIN_FILENO, KDSETMODE, KD_GRAPHICS) < 0)
		fatal("ioctl: KDSETMODE failed (maybe here is not console)");

	tty.save_tm = (struct termios *) emalloc(sizeof(struct termios));
	set_rawmode(STDIN_FILENO, tty.save_tm);
	ewrite(STDIN_FILENO, "\033[?25l", 6); /* make cusor invisible */

	if ((env = getenv("YAFT")) != NULL) {
		if (strstr(env, "background") != NULL)
			tty.background_draw = true;
		if (strstr(env, "lazy") != NULL)
			tty.lazy_draw = true;
	}
}
Ejemplo n.º 2
0
/*
 * call-seq:
 *   io.raw!
 *
 * Enables raw mode.
 *
 * If the terminal mode needs to be back, use io.raw { ... }.
 */
static VALUE
console_set_raw(VALUE io)
{
    conmode t;
    rb_io_t *fptr;
    int fd;

    GetOpenFile(io, fptr);
    fd = GetReadFD(fptr);
    if (!getattr(fd, &t)) rb_sys_fail(0);
    set_rawmode(&t);
    if (!setattr(fd, &t)) rb_sys_fail(0);
    return io;
}
Ejemplo n.º 3
0
/*
 * call-seq:
 *   io.raw!(min: nil, time: nil)
 *
 * Enables raw mode.
 *
 * If the terminal mode needs to be back, use io.raw { ... }.
 *
 * You must require 'io/console' to use this method.
 */
static VALUE
console_set_raw(int argc, VALUE *argv, VALUE io)
{
    conmode t;
    rb_io_t *fptr;
    int fd;
    rawmode_arg_t opts, *optp = rawmode_opt(argc, argv, &opts);

    GetOpenFile(io, fptr);
    fd = GetReadFD(fptr);
    if (!getattr(fd, &t)) rb_sys_fail(0);
    set_rawmode(&t, optp);
    if (!setattr(fd, &t)) rb_sys_fail(0);
    return io;
}
Ejemplo n.º 4
0
int
main(int argc, const char **argv)
{
	const char *sysname, *speed;
	char sysfile[FILENAME_MAX];
	char deblogname[FILENAME_MAX];
	FILE *f;
	header_p sys, ich, p;
	int i;

	initlog("call");

	if (0 == strcmp(argv[0], "-h")) usage();
	if (argc < 4 || argc > 5) usage();

	gmodem=-1;
	atexit(cleanup);

	sysname = strlwr( dstrdup( argv[1] ));
	if (!strchr(argv[2], '/'))
		snprintf(tty, sizeof(tty), "/dev/%s", argv[2]);
	else
		strcpy(tty, argv[2]);

	speed = argv[3];

	maxtry = 1;
	if (argc > 4)
		maxtry = atoi(argv[4]);

	minireadstat();
	sprintf(deblogname, "%s/" DEBUGLOG_FILE, logdir);
	if(debuglevel>0) {
		deblogfile = fopen(deblogname, "w");
		if (!deblogfile) {
			printf("Ich kann das Logfile nicht oeffnen. "
				"Probiere /dev/null...\n");
			deblogfile = fopen("/dev/null", "w");
			if (!deblogfile) {
				printf("Hmm... - /dev/null "
					"nicht schreibbar??\n");
				return 10;
			}
		}
	} else {
		deblogfile = fopen("/dev/null", "w");
		if (!deblogfile) {
			printf("Arghl! - kann /dev/null "
				"nicht zum Schreiben oeffnen!\n\n");
			return 10;
		}
	}
	sprintf(sysfile, "%s/%s", systemedir, sysname);
	f = fopen(sysfile, "r");
	if (!f) {
		perror(sysfile);
		newlog(ERRLOG, "File <%s> not readable: %s",
			sysfile, strerror(errno));
		return 1;
	}
	sys = rd_para(f);
	fclose(f);

	ich = get_myself();

	for (i=maxtry; i; i--) {
	   if (lock_device(1, tty)) break;
	   fputs(" ... unser Modem ist belegt\n", stderr);
	   sleep(60);
	}
	if (!i) {
		newlog(ERRLOG, "Cannot lock device: %s", tty);
		return 9;
	}

#ifdef LEAVE_CTRL_TTY
	/*
	 * Bisheriges Controlling-TTY verlassen, damit "modem" das neue
	 * wird.
	 */
#ifdef BSD
	setpgrp(0, getpid());	/* set process group id to process id */
#ifdef SIGTTOU
	signal(SIGTTOU, SIG_IGN);
#endif
#ifdef SIGTTIN
	signal(SIGTTIN, SIG_IGN);
#endif
#ifdef SIGTSTP
	signal(SIGTSTP, SIG_IGN);
#endif
#else	/* !BSD */
#if !defined(USE_SETSID) && !defined(USE_SETPGRP)
#error Controlling TTY kann nicht verlassen werden: definieren Sie eine Methode dazu
#endif /* !BSD und keine SysV-Methode definiert */

#ifdef USE_SETSID
#error	Dies funktioniert nicht!
	setsid();
#endif /* USE_SETSID */
#ifdef USE_SETPGRP
	setpgrp();
#endif /* USE_SETPGRP */
#endif /* !BSD */
#endif /* LEAVE_CTRL_TTY */

	gmodem = open(tty,
#if !defined(__NetBSD__)
			O_RDWR | O_NDELAY
#else
			O_RDWR
#endif
		); DMLOG("open modem");
	if (gmodem < 0) {
		newlog(ERRLOG,
			"Can not access device %s: %s", tty, strerror(errno));
		return 10;
	}
#if !defined(__NetBSD__)
	else {
		/* Nonblock abschalten */
		int n;
		n=fcntl(gmodem, F_GETFL, 0);
		(void)fcntl(gmodem, F_SETFL, n & ~O_NDELAY);
	}
#endif
	save_linesettings(gmodem); DMLOG("saving modem parameters");
	set_rawmode(gmodem); DMLOG("set modem to rawmode");
	set_local(gmodem, 1);
	set_speed(gmodem, speed); DMLOG("set modem speed");
#ifdef TIOCSCTTY
	ioctl(gmodem, TIOCSCTTY, NULL);
#endif

	files = 0;
	online_start = 0;
	fprintf(stderr, "Netcall bei %s [%s]\n", sysname, tty);

	fclose(stdin);
	fclose(stdout);
	dup(gmodem); dup(gmodem); DMLOG("dup modem 2x to stdin and stdout");

	if (setjmp(timeout)) {
		newlog(ERRLOG, "ABBRUCH: Timeout");
		lock_device(0, tty);
		anrufdauer();
		if (files) aufraeumen();

		return 11;
	}
	if (setjmp(nocarrier)) {
		if (!auflegen) {
			newlog(ERRLOG, "ABBRUCH: Gegenstelle hat aufgelegt");
		}
		lock_device(0, tty);
		anrufdauer();
		if (files) aufraeumen();

		return auflegen ? 0 : 12;
	}
	signal(SIGHUP, handle_nocarrier);
	signal(SIGALRM, handle_timeout);
	setup_dial_info(ortsnetz, g_int_prefix, g_ovst, NULL);

	p = find(HD_TEL, sys);
	if (!p) {
		newlog(ERRLOG,
			"Keine Telefonnummer fuer %s gefunden",
			sysname);
		return 2;
	}

	anruf(sys, ich, gmodem, maxtry);

	if (online_start) {
		anrufdauer();
	} else {
		fprintf(stderr, "Keine Verbindung hergestellt.\n");
	}

	lock_device(0, tty);
	/* Device ist freigegeben, aber wir warten noch auf das Ende
	   der Importphase, bevor wir zurueckkehren. */
	wait(NULL);
	return 0;
}