Skip to content

guix.scm: Reap 'git'.

Oleg Pykhalov requested to merge (removed):reap-git into master
  • guix.scm (git-output): Call 'close-pipe' in favor of 'close-port'.

Hi.

I wrote an infinite loop which calls git-output like procedure. 1500 zombies spawned after some time. The reason is close-port which should be close-pipe to wait a process. E.g. example from https://git.savannah.gnu.org/cgit/guile.git/tree/test-suite/tests/ports.test?h=master#n661

;;; Run a command, send some output to it, and see if it worked.
(let* ((filename (test-file))
       (pipe (open-pipe (string-append "grep Mommy > " filename) "w")))
  ;;...
  (close-pipe pipe)
  #;...)

The following code block spawns zombies.

(use-modules
 (ice-9 popen)
 (ice-9 rdelim)
 (guix build utils)
 (guix gexp)
 (guix git-download)
 (guix packages)
 (gnu packages autotools)
 (gnu packages emacs)
 (gnu packages pkg-config)
 (gnu packages texinfo))

(define %source-dir (dirname (current-filename)))

(define (git-output . args)
  "Execute 'git ARGS ...' command and return its output without trailing
newspace."
  (with-directory-excursion %source-dir
    (let* ((port   (apply open-pipe* OPEN_READ "git" args))
           (output (read-string port)))
      (close-port port)
      (string-trim-right output #\newline))))

(define (current-commit)
  (git-output "log" "-n" "1" "--pretty=format:%H"))

(while #t
  (display (current-commit))
  (newline)
  (sleep 5))

The current implementation doesn't cause much troubles, but somebody could use it as example too.

Merge request reports