Re: [PATCHv2 5/9] add generic terminal prompt function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



peff@xxxxxxxx wrote on Sat, 10 Dec 2011 05:41 -0500:
> +static struct termios old_term;
> +
> +static void restore_term(void)
> +{
> +	if (term_fd < 0)
> +		return;
> +
> +	tcsetattr(term_fd, TCSAFLUSH, &old_term);
> +	term_fd = -1;
> +}

Restores from static old_term.

> +char *git_terminal_prompt(const char *prompt, int echo)
> +{
> +	static struct strbuf buf = STRBUF_INIT;
> +	int r;
> +	FILE *fh;
> +
> +	fh = fopen("/dev/tty", "w+");
> +	if (!fh)
> +		return NULL;
> +
> +	if (!echo) {
> +		struct termios t;
> +
> +		if (tcgetattr(fileno(fh), &t) < 0) {
> +			fclose(fh);
> +			return NULL;
> +		}
> +
> +		old_term = t;

Which is only saved if echo is true.

> +		term_fd = fileno(fh);
> +		sigchain_push_common(restore_term_on_signal);
> +
> +		t.c_lflag &= ~ECHO;
> +		if (tcsetattr(fileno(fh), TCSAFLUSH, &t) < 0) {
> +			term_fd = -1;
> +			fclose(fh);
> +			return NULL;
> +		}
> +	}
> +
> +	fputs(prompt, fh);
> +	fflush(fh);
> +
> +	r = strbuf_getline(&buf, fh, '\n');
> +	if (!echo) {
> +		putc('\n', fh);
> +		fflush(fh);
> +	}
> +
> +	restore_term();

Perhaps this line should go in !echo.

And why no sigchain_pop() for the signal handler?

		-- Pete
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]