+2006-04-25  Daiki Ueno  <ueno@unixuser.org>
+
+       * epg.el (epg-process-sentinel): New function; set 'error if gpg
+       process exited abnormally, but we have not received an error
+       response from it.
+
 2006-04-22  Daiki Ueno  <ueno@unixuser.org>
 
        * epa.el (epa-key-widget-value-create): Decode DN.
 
                       args)))
       (set-default-file-modes orig-mode))
     (set-process-filter process #'epg-process-filter)
+    (set-process-filter process #'epg-process-sentinel)
     (epg-context-set-process context process)))
 
 (defun epg-process-filter (process input)
          (forward-line))
        (setq epg-read-point (point)))))
 
+(defun epg-process-sentinel (process status)
+  (if (and (buffer-live-p (process-buffer process))
+          (not (equal status "finished\n")))
+      (save-excursion
+       (set-buffer (process-buffer process))
+       ;; gpg process exited abnormally, but we have not received an
+       ;; error response from it.
+       (unless (epg-context-result-for epg-context 'error)
+         (if (string-match "\\`exited abnormally with code \\(.*\\)\n" status)
+             (epg-context-result-for
+              epg-context 'error
+              (list (cons 'exit (string-to-number (match-string 1 status)))))
+           (epg-context-result-for epg-context 'error
+                                   (list (cons 'signal status))))))))
+
 (defun epg-read-output (context)
   (with-temp-buffer
     (if (fboundp 'set-buffer-multibyte)