caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Sys.command is broken on MacOS X
@ 2002-08-01  9:26 Sébastien Carlier
  0 siblings, 0 replies; only message in thread
From: Sébastien Carlier @ 2002-08-01  9:26 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 680 bytes --]


The system(3) C library function is seriously broken on MacOS X.
It may return with an Interrupted System Call error before the child
process has finished its execution, leaving a zombie process.

The Ocaml function Sys.command uses the system(3) function,
and thus is broken too.  Active DVI is one of the applications greatly
impacted by this bug, but there may be others.

The attached patch, to be applied to the Ocaml compiler, provides a
working implementation of the system(3) function.  If an Ocaml
application uses Sys.command, and unexpectedly fails on MacOS X
with "Interrupted System Call" errors, you should apply this patch.

--
Sébastien Carlier


[-- Attachment #2: ocaml-macosx-system.patch --]
[-- Type: application/octet-stream, Size: 1251 bytes --]

Index: byterun/sys.c
===================================================================
RCS file: /caml/ocaml/byterun/sys.c,v
retrieving revision 1.59
diff -r1.59 sys.c
256a257,298
> #if defined(SYS_rhapsody)
> int rhapsody_system(const char *string) {
>     int old_sigmask;
>     pid_t pid;
> 
>     if (string == 0)
> 	return 1;
>     old_sigmask = sigblock(sigmask(SIGQUIT));
>     pid = vfork();
>     if (pid < 0) {
> 	/* vfork failed */
> 	sigsetmask(old_sigmask);
> 	return -1;
>     } else if (pid == 0) {
> 	/* We are in the child process */
> 	sigsetmask(old_sigmask);
> 	execl("/bin/sh", "sh", "-c", string, 0);
> 	_exit(127);
> 	return -1;
>     } else {
> 	/* We are in the parent process */
> 	int status = 0;
> 	void* old_sigint;
> 	void* old_sigquit;
> 	int result;
> 
> 	old_sigint = signal(SIGINT, 0);
> 	old_sigquit = signal(SIGQUIT, 0);
> 	do {
> 	    result = waitpid(pid, &status, 0);
> 	} while (result < 0 && errno == EINTR);
> 	signal(SIGINT, old_sigint);
> 	signal(SIGQUIT, old_sigquit);
> 	sigsetmask(old_sigmask);
> 	if (result < 0)
> 	    return -1;
> 	else
> 	    return status;
>     }
> }
> #endif
> 
262a305,307
> #if defined(SYS_rhapsody)
>   status = rhapsody_system(String_val(command));
> #else
263a309
> #endif

[-- Attachment #3: Type: text/plain, Size: 1 bytes --]



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-08-01  9:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-01  9:26 [Caml-list] Sys.command is broken on MacOS X Sébastien Carlier

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 NNTP newsgroup(s).