[gnutls-dev] Re: gnutls-cli -s triggered by SIGALRM too?

Simon Josefsson simon+gnutls-dev at josefsson.org
Fri Oct 3 00:49:01 CEST 2003


Nikos Mavroyanopoulos <nmav at gnutls.org> writes:

> On Sun, Sep 21, 2003 at 03:08:58AM +0200, Simon Josefsson wrote:
>
>> Hello, I'm working on a STARTTLS interface for Emacs using GNUTLS,
>> since the current Emacs solution uses a non-standard command line
>> application based on OpenSSL, so moving to gnutls-cli seems better.
>> 
>> However, triggering the STARTTLS negotiation by EOF seem slightly
>> problematic to do in a portable way from Emacs.  The old starttls
>> application triggered the STARTTLS negotiation by SIGALRM.  Would it
>> be possible to support this as well, in gnutls-cli?  Suggested patch
>> attached.
> I've just applied it in the cvs version. Thanks.

Thanks.  I've started to use it and I discovered two more problems:

* The FD_ZERO is not called after select() has called.

* Buffered IO (i.e., fgets()) doesn't work well with select().  The
  problem is that fgets() may fill the IO buffer with data to read,
  but only return one line (the remaining lines in the buffer will be
  returned by later calls to f* functions).  One solution is to
  rewrite the code to use read() instead of fgets(), but this would
  complicate the 'crlf' handling harder.  The following just disable
  the buffering instead.

2003-10-03  Simon Josefsson  <jas at extundo.com>

	* src/cli.c (main): Disable buffering.  Clear FD set.

Index: cli.c
===================================================================
RCS file: /cvs/gnutls/gnutls/src/cli.c,v
retrieving revision 2.214
diff -u -p -u -w -r2.214 cli.c
--- cli.c	2 Oct 2003 15:02:31 -0000	2.214
+++ cli.c	2 Oct 2003 22:43:26 -0000
@@ -378,8 +378,13 @@ int main(int argc, char **argv)
 
 	signal (SIGALRM, &starttls_alarm);
 
-	FD_ZERO(&rset);
+	/* do not buffer */
+	setbuf(stdin, NULL);
+	setbuf(stdout, NULL);
+	setbuf(stderr, NULL);
+
 	for (;;) {
+		FD_ZERO(&rset);
 		FD_SET(fileno(stdin), &rset);
 		FD_SET(sd, &rset);
 





More information about the Gnutls-devel mailing list