I got a segmentation violation from guile 1.3.4 a few minutes ago.  I
haven't yet isolated the envelope, but the code I was using is
sufficiently short that it shouldn't be hard for somebody who knows
Guile better than I do.

Here's the file testspeeds.scm (the name has nothing to do with the
code here).  If you like, and happen to have an account on totoro,
this is also in there in ~joelh.  (This has the added benefit that the
problem is definately reproducable on totoro.)  Please, I know the
code is terrible, but it may help to show a bug that happens in
correct code.  :-)  I've marked the line where the sigsegv occurs.

-----cut here-----
(use-modules (ice-9 slib))
(require 'format)
(require 'qp)

(define (spawn-child path . args)
  (define to-child (pipe))
  (define from-child (pipe))
  (define pid #f)
  (flush-all-ports)
  (set! pid (primitive-fork))
  (if (= pid 0)
      (catch #t
             (lambda ()
               (let ((stdin (car to-child))
                     (stdout (cdr from-child))
                     (stderr #f))
                 (flush-all-ports)
                 (set-current-input-port stdin)
                 (set-current-output-port stdout)
                 (set-current-error-port stdout)
                 (setvbuf stdin _IONBF)
                 (move->fdes stdin 0)
                 (setvbuf stdout _IONBF)
                 (move->fdes stdout 1)
                 (set! stderr (dup->port stdout "w0" 2))
                 (set-current-error-port stderr)
                 (close-all-ports-except stdin stdout )
                 (apply execlp path args)
                 (exit)))
             (lambda (key . args)
               (display "error caught: ")
               (write key)
               (newline)
               (write args)
               (newline)
               (quit))))
  (close-port (car to-child))
  (close-port (cdr from-child))
  (setvbuf (cdr to-child) _IONBF)
  (setvbuf (car from-child) _IONBF)
  ;; FIXME Should this be the other way around for consitency with pipe?
  (cons pid (cons (cdr to-child) (car from-child))))

(define (call-with-mail-to address subject thunk)
  (define mail-child (spawn-child "sendmail" "sendmail" "-U" "-v" address))
  (format (cadr mail-child) "To: ~A~%Subject: ~A~%~%" address subject)
  (display mail-child)  (newline)
  (thunk (cadr mail-child))
  (display mail-child)  (newline)  ; Here's where the sigsegv occurs.
  (close-output-port (cadr mail-child))
  (display mail-child)  (newline)
  (with-output-to-string
    (lambda ()
      (let ((write-all-lines
             (lambda ()
               (define cur-line (read-line (cddr mail-child)))
               (if (not (eof-object? cur-line))
                   (write-all-lines)))))))))

(define (send-mail address subject thunk)
  (define old-output-port (current-output-port))
  (define output #f)
  (set! output
        (catch #t 
               (lambda ()
                 (call-with-mail-to address subject
                                    (lambda (outport)
                                      (set-current-output-port outport)
                                      (thunk))))
               (lambda args
                 (set-current-output-port old-output-port)
                 (display args)
                 (apply throw args))))
  (set-current-output-port old-output-port)
  output)
-----cut here-----

The command that caused the segv was
  (send-mail "joelh" "test" (lambda () (display "Yow!")))

Cheers,
joelh

-- 
Joel Ray Holveck - [EMAIL PROTECTED]
   Fourth law of programming:
   Anything that can go wrong wi
sendmail: segmentation violation - core dumped

Reply via email to