unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* smtpmail on Windows native Emacs with gnutls-cli from Cygwin freeze.
@ 2011-10-23 21:53 Oleksandr Gavenko
  2011-10-23 22:40 ` Oleksandr Gavenko
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Oleksandr Gavenko @ 2011-10-23 21:53 UTC (permalink / raw)
  To: emacs-devel

I like use native Emacs with Cygwin toolset. It does not
hard to friend then. But from time to time I discover some issues.

Now time I finally try setup Emacs to work with mail.

GMail SMTP require TLS connection. As usual this done by
'gnus/starttls.el'.

After configuring smtpmail (send-mail-function==smtpmail-send-it)
I try compose mail:

   C-x m bla-bla-bla C-c C-c

Emacs freeze! Try same in Cygwin Emacs and all OK!

After debug I found root of evil:

   (defun starttls-open-stream-gnutls (name buffer host port)
          ...
	 (process (apply #'start-process name buffer
			 starttls-gnutls-program "-s" host
			 "-p" (if (integerp port)
				  (int-to-string port)
				port)
			 starttls-extra-arguments))
         ...)))))

   (defun starttls-negotiate-gnutls (process)
    ...
	;; XXX How to remove/extract the TLS negotiation junk?
	(signal-process (process-id process) 'SIGALRM)
         ...
	(save-excursion
	  (setq old-max (goto-char (point-max)))
	  (signal-process (process-id process) 'SIGALRM)
	  (while (and (processp process)
		      (eq (process-status process) 'run)
		      (save-excursion
			(goto-char old-max)
			(not (or (setq done-ok (re-search-forward
					starttls-success nil t))
				 (setq done-bad (re-search-forward
					 starttls-failure nil t))))))
	    (accept-process-output process 1 100)
	    (sit-for 0.1))
           ...

So 'gnutls-cli' called with '-s' option. From man page:

        -s, --starttls
               Connect, establish a plain session and start TLS
               when EOF or a SIGALRM is received.

and 'signal-process' call do nothing for SIGALRM. More correctly
return error. Look to 'src/w32proc.c':

   int
   sys_kill (int pid, int sig)
   {
     ...
     /* Only handle signals that will result in the process dying */
     if (sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP)
       {
         errno = EINVAL;
         return -1;
       }

So 'gnutls-cli' don't send anything and 'while' loop can not match
'starttls-failure', 'starttls-success', etc...

I easy make workaround. Just replace 'signal-process' with Cygwin
'kill.exe':

  (shell-command (format "kill.exe -s SIGALRM %d" (process-id process)))

Conclusion from this story: check return codes... and don't use
unsupported configuration!

But I think Emacs 'gnus/starttls.el' code can be rewritten to be able
work with Cygwin gnutls-cli without signals...

As emacs-jabber package work fine with Cygwin! I successfully use
it for 2 years with Google GTalk over TLS...




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: smtpmail on Windows native Emacs with gnutls-cli from Cygwin freeze.
  2011-10-23 21:53 smtpmail on Windows native Emacs with gnutls-cli from Cygwin freeze Oleksandr Gavenko
@ 2011-10-23 22:40 ` Oleksandr Gavenko
  2013-06-09  0:15   ` l1dge
  2011-10-23 23:56 ` Lars Magne Ingebrigtsen
  2011-10-24  7:15 ` Eli Zaretskii
  2 siblings, 1 reply; 8+ messages in thread
From: Oleksandr Gavenko @ 2011-10-23 22:40 UTC (permalink / raw)
  To: emacs-devel

24.10.2011 0:53, Oleksandr Gavenko пишет:
> I like use native Emacs with Cygwin toolset. It does not
> hard to friend then. But from time to time I discover some issues.
>
> Now time I finally try setup Emacs to work with mail.
>
> GMail SMTP require TLS connection. As usual this done by
> 'gnus/starttls.el'.
>
> After configuring smtpmail (send-mail-function==smtpmail-send-it)
> I try compose mail:
>
> C-x m bla-bla-bla C-c C-c
>
> Emacs freeze! Try same in Cygwin Emacs and all OK!
>
> After debug I found root of evil:
>
> (defun starttls-open-stream-gnutls (name buffer host port)
> ...
> (process (apply #'start-process name buffer
> starttls-gnutls-program "-s" host
> "-p" (if (integerp port)
> (int-to-string port)
> port)
> starttls-extra-arguments))
> ...)))))
>
> (defun starttls-negotiate-gnutls (process)
> ...
> ;; XXX How to remove/extract the TLS negotiation junk?
> (signal-process (process-id process) 'SIGALRM)
> ...
> (save-excursion
> (setq old-max (goto-char (point-max)))
> (signal-process (process-id process) 'SIGALRM)
> (while (and (processp process)
> (eq (process-status process) 'run)
> (save-excursion
> (goto-char old-max)
> (not (or (setq done-ok (re-search-forward
> starttls-success nil t))
> (setq done-bad (re-search-forward
> starttls-failure nil t))))))
> (accept-process-output process 1 100)
> (sit-for 0.1))
> ...
>
> So 'gnutls-cli' called with '-s' option. From man page:
>
> -s, --starttls
> Connect, establish a plain session and start TLS
> when EOF or a SIGALRM is received.
>
> and 'signal-process' call do nothing for SIGALRM. More correctly
> return error. Look to 'src/w32proc.c':
>
> int
> sys_kill (int pid, int sig)
> {
> ...
> /* Only handle signals that will result in the process dying */
> if (sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP)
> {
> errno = EINVAL;
> return -1;
> }
>
> So 'gnutls-cli' don't send anything and 'while' loop can not match
> 'starttls-failure', 'starttls-success', etc...
>
> I easy make workaround. Just replace 'signal-process' with Cygwin
> 'kill.exe':
>
> (shell-command (format "kill.exe -s SIGALRM %d" (process-id process)))
>
Solution that prevent modify any existing lisp code:

(defadvice signal-process (around cygwin (process sigcode))
   "Use 'kill.exe' instead build-in Emacs 'kill'."
   (if (eq sigcode 'SIGALRM)
       (shell-command
        (format "kill.exe -s SIGALRM %d"
                (if (processp process) (process-id process) process)))
     ad-do-it
     ))
(ad-activate 'signal-process)

-- 
Happy hacking!




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: smtpmail on Windows native Emacs with gnutls-cli from Cygwin freeze.
  2011-10-23 21:53 smtpmail on Windows native Emacs with gnutls-cli from Cygwin freeze Oleksandr Gavenko
  2011-10-23 22:40 ` Oleksandr Gavenko
@ 2011-10-23 23:56 ` Lars Magne Ingebrigtsen
  2011-10-24  6:57   ` Eli Zaretskii
  2011-10-24  7:15 ` Eli Zaretskii
  2 siblings, 1 reply; 8+ messages in thread
From: Lars Magne Ingebrigtsen @ 2011-10-23 23:56 UTC (permalink / raw)
  To: Oleksandr Gavenko; +Cc: emacs-devel

Oleksandr Gavenko <gavenkoa@gmail.com> writes:


[...]

> 	  (signal-process (process-id process) 'SIGALRM)

[...]

> and 'signal-process' call do nothing for SIGALRM. More correctly
> return error. Look to 'src/w32proc.c':
>
>   int
>   sys_kill (int pid, int sig)
>   {
>     ...
>     /* Only handle signals that will result in the process dying */
>     if (sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP)
>       {
>         errno = EINVAL;
>         return -1;
>       }

Isn't that the bug, though?  Why isn't `signal-process' sending the
signal we request on Windows?

-- 
(domestic pets only, the antidote for overdose, milk.)
  bloggy blog http://lars.ingebrigtsen.no/



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: smtpmail on Windows native Emacs with gnutls-cli from Cygwin freeze.
  2011-10-23 23:56 ` Lars Magne Ingebrigtsen
@ 2011-10-24  6:57   ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2011-10-24  6:57 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: emacs-devel, gavenkoa

> From: Lars Magne Ingebrigtsen <larsi@gnus.org>
> Date: Mon, 24 Oct 2011 01:56:34 +0200
> MailScanner-NULL-Check: 1320019000.28138@KSiCUCFVgPG6ekyuuDsfeQ
> Cc: emacs-devel@gnu.org
> 
> Oleksandr Gavenko <gavenkoa@gmail.com> writes:
> 
> 
> [...]
> 
> > 	  (signal-process (process-id process) 'SIGALRM)
> 
> [...]
> 
> > and 'signal-process' call do nothing for SIGALRM. More correctly
> > return error. Look to 'src/w32proc.c':
> >
> >   int
> >   sys_kill (int pid, int sig)
> >   {
> >     ...
> >     /* Only handle signals that will result in the process dying */
> >     if (sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP)
> >       {
> >         errno = EINVAL;
> >         return -1;
> >       }
> 
> Isn't that the bug, though?  Why isn't `signal-process' sending the
> signal we request on Windows?

Because you cannot send a signal to another process on MS-Windows.

Look at the rest of the code in sys_kill, below the above test, and
you will see that it emulates sending the 4 signals mentioned above,
by either (a) sending the equivalent of Ctrl-C to the window of the
sub-process, or (b) by forcefully terminating that process.

Emulating SIGALRM in a similar way is extremely tricky, because it
would involve reading the other process's memory to find out where its
SIGALRM handler is, if any (very non-trivial), and either terminating
it if no handler is found (easy) or calling that handler (hard).
Patches to do that are welcome.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: smtpmail on Windows native Emacs with gnutls-cli from Cygwin freeze.
  2011-10-23 21:53 smtpmail on Windows native Emacs with gnutls-cli from Cygwin freeze Oleksandr Gavenko
  2011-10-23 22:40 ` Oleksandr Gavenko
  2011-10-23 23:56 ` Lars Magne Ingebrigtsen
@ 2011-10-24  7:15 ` Eli Zaretskii
  2011-10-24 20:21   ` Oleksandr Gavenko
  2 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2011-10-24  7:15 UTC (permalink / raw)
  To: Oleksandr Gavenko; +Cc: emacs-devel

> From: Oleksandr Gavenko <gavenkoa@gmail.com>
> Date: Mon, 24 Oct 2011 00:53:12 +0300
> 
> I like use native Emacs with Cygwin toolset. It does not
> hard to friend then. But from time to time I discover some issues.
> 
> Now time I finally try setup Emacs to work with mail.
> 
> GMail SMTP require TLS connection. As usual this done by
> 'gnus/starttls.el'.
> 
> After configuring smtpmail (send-mail-function==smtpmail-send-it)
> I try compose mail:
> 
>    C-x m bla-bla-bla C-c C-c
> 
> Emacs freeze! Try same in Cygwin Emacs and all OK!

Was your native Windows build of Emacs built with GnuTLS support?
See the section in nt/INSTALL about "Optional GnuTLS support", for
the details.  I understand that if you build Emacs with GnuTLS support
and install the GnuTLS binaries from the URL in that section, you will
have gnutls in the native Emacs without any need for the Cygwin gnutls
executable, and without any need to hack Emacs for SIGALRM.

If the GnuTLS configuration described in nt/INSTALL doesn't work,
please submit a bug report.  I'm quite sure several people use that
configuration successfully.

> Conclusion from this story: check return codes... and don't use
> unsupported configuration!

The latter.  Especially if the supported configuration already has
GnuTLS support built into it.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: smtpmail on Windows native Emacs with gnutls-cli from Cygwin freeze.
  2011-10-24  7:15 ` Eli Zaretskii
@ 2011-10-24 20:21   ` Oleksandr Gavenko
  2011-10-24 21:45     ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Oleksandr Gavenko @ 2011-10-24 20:21 UTC (permalink / raw)
  To: emacs-devel

24.10.2011 10:15, Eli Zaretskii пишет:
> Was your native Windows build of Emacs built with GnuTLS support?
> See the section in nt/INSTALL about "Optional GnuTLS support", for
> the details.  I understand that if you build Emacs with GnuTLS support
> and install the GnuTLS binaries from the URL in that section, you will
> have gnutls in the native Emacs without any need for the Cygwin gnutls
> executable, and without any need to hack Emacs for SIGALRM.
>
According to bzr log:

   revno: 104106
   committer: Juanma Barranquero <lekktu@gmail.com>
   branch nick: trunk
   timestamp: Wed 2011-05-04 16:03:16 +0200
   message:
     Implement dynamic loading of GnuTLS on Windows.

   revno: 104262
   committer: Eli Zaretskii <eliz@gnu.org>
   branch nick: trunk
   timestamp: Tue 2011-05-17 21:17:45 +0300
   message:
     nt/README.W32: Add information about GnuTLS libraries.

So support for GnuTLS on Windows recently appear...

I always use official build of Emacs from
ftp://ftp.gnu.org/gnu/emacs/windows/ so have no GnuTLS in
emacs.exe...

Are there any recommended way to get latest or pretest/RC Emacs build?




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: smtpmail on Windows native Emacs with gnutls-cli from Cygwin freeze.
  2011-10-24 20:21   ` Oleksandr Gavenko
@ 2011-10-24 21:45     ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2011-10-24 21:45 UTC (permalink / raw)
  To: Oleksandr Gavenko; +Cc: emacs-devel

> From: Oleksandr Gavenko <gavenkoa@gmail.com>
> Date: Mon, 24 Oct 2011 23:21:49 +0300
> 
> Are there any recommended way to get latest or pretest/RC Emacs build?

You can find the pretest zip files here:

  ftp://alpha.gnu.org/gnu/emacs/pretest/windows/



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: smtpmail on Windows native Emacs with gnutls-cli from Cygwin freeze.
  2011-10-23 22:40 ` Oleksandr Gavenko
@ 2013-06-09  0:15   ` l1dge
  0 siblings, 0 replies; 8+ messages in thread
From: l1dge @ 2013-06-09  0:15 UTC (permalink / raw)
  To: Emacs-devel

Thanks for this tip, I've been looking for a solution all evening and have
finally got gnus to work within emacs!

Cheers
Lee



--
View this message in context: http://emacs.1067599.n5.nabble.com/smtpmail-on-Windows-native-Emacs-with-gnutls-cli-from-Cygwin-freeze-tp185529p288234.html
Sent from the Emacs - Dev mailing list archive at Nabble.com.



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-06-09  0:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-23 21:53 smtpmail on Windows native Emacs with gnutls-cli from Cygwin freeze Oleksandr Gavenko
2011-10-23 22:40 ` Oleksandr Gavenko
2013-06-09  0:15   ` l1dge
2011-10-23 23:56 ` Lars Magne Ingebrigtsen
2011-10-24  6:57   ` Eli Zaretskii
2011-10-24  7:15 ` Eli Zaretskii
2011-10-24 20:21   ` Oleksandr Gavenko
2011-10-24 21:45     ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).