1998-08-08 09:53:42 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Objective Caml */
|
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
|
|
|
/* Copyright 1998 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../../LICENSE. */
|
1998-08-08 09:53:42 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include <alloc.h>
|
|
|
|
#include <memory.h>
|
|
|
|
#include <mlvalues.h>
|
1998-08-13 08:58:08 -07:00
|
|
|
#include <signals.h>
|
1998-08-08 09:53:42 -07:00
|
|
|
#include "unixsupport.h"
|
|
|
|
|
2000-03-17 08:45:18 -08:00
|
|
|
#ifndef NSIG
|
|
|
|
#define NSIG 32
|
|
|
|
#endif
|
|
|
|
|
1999-06-05 05:02:48 -07:00
|
|
|
#ifdef POSIX_SIGNALS
|
|
|
|
|
1998-08-08 09:53:42 -07:00
|
|
|
static void decode_sigset(value vset, sigset_t * set)
|
|
|
|
{
|
|
|
|
sigemptyset(set);
|
|
|
|
while (vset != Val_int(0)) {
|
1998-08-13 08:58:08 -07:00
|
|
|
int sig = convert_signal_number(Int_val(Field(vset, 0)));
|
|
|
|
sigaddset(set, sig);
|
1998-08-08 09:53:42 -07:00
|
|
|
vset = Field(vset, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static value encode_sigset(sigset_t * set)
|
|
|
|
{
|
|
|
|
value res = Val_int(0);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
Begin_root(res)
|
|
|
|
for (i = 1; i < NSIG; i++)
|
|
|
|
if (sigismember(set, i)) {
|
1998-10-26 11:19:32 -08:00
|
|
|
value newcons = alloc_small(2, 0);
|
1998-08-08 09:53:42 -07:00
|
|
|
Field(newcons, 0) = Val_int(i);
|
|
|
|
Field(newcons, 1) = res;
|
|
|
|
res = newcons;
|
|
|
|
}
|
|
|
|
End_roots();
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sigprocmask_cmd[3] = { SIG_SETMASK, SIG_BLOCK, SIG_UNBLOCK };
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_sigprocmask(value vaction, value vset)
|
1998-08-08 09:53:42 -07:00
|
|
|
{
|
|
|
|
int how;
|
|
|
|
sigset_t set, oldset;
|
1999-06-05 06:27:54 -07:00
|
|
|
int retcode;
|
1998-08-08 09:53:42 -07:00
|
|
|
|
|
|
|
how = sigprocmask_cmd[Int_val(vaction)];
|
|
|
|
decode_sigset(vset, &set);
|
1999-06-05 06:27:54 -07:00
|
|
|
enter_blocking_section();
|
|
|
|
retcode = sigprocmask(how, &set, &oldset);
|
|
|
|
leave_blocking_section();
|
|
|
|
if (retcode == -1) uerror("sigprocmask", Nothing);
|
1998-08-08 09:53:42 -07:00
|
|
|
return encode_sigset(&oldset);
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_sigpending(value unit)
|
1998-08-08 09:53:42 -07:00
|
|
|
{
|
|
|
|
sigset_t pending;
|
|
|
|
if (sigpending(&pending) == -1) uerror("sigpending", Nothing);
|
|
|
|
return encode_sigset(&pending);
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_sigsuspend(value vset)
|
1998-08-08 09:53:42 -07:00
|
|
|
{
|
|
|
|
sigset_t set;
|
1999-06-05 06:27:54 -07:00
|
|
|
int retcode;
|
1998-08-08 09:53:42 -07:00
|
|
|
decode_sigset(vset, &set);
|
1999-06-05 06:27:54 -07:00
|
|
|
enter_blocking_section();
|
|
|
|
retcode = sigsuspend(&set);
|
|
|
|
leave_blocking_section();
|
|
|
|
if (retcode == -1 && errno != EINTR) uerror("sigsuspend", Nothing);
|
1998-08-08 09:53:42 -07:00
|
|
|
return Val_unit;
|
|
|
|
}
|
1999-06-05 05:02:48 -07:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_sigprocmask(value vaction, value vset)
|
1999-06-05 05:02:48 -07:00
|
|
|
{ invalid_argument("Unix.sigprocmask not available"); }
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_sigpending(value unit)
|
1999-06-05 05:02:48 -07:00
|
|
|
{ invalid_argument("Unix.sigpending not available"); }
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_sigsuspend(value vset)
|
1999-06-05 05:02:48 -07:00
|
|
|
{ invalid_argument("Unix.sigsuspend not available"); }
|
|
|
|
|
|
|
|
#endif
|