source: rtems/cpukit/posix/src/sigaction.c @ 44ed384

5
Last change on this file since 44ed384 was 44ed384, checked in by Sebastian Huber <sebastian.huber@…>, on 04/05/16 at 14:23:39

posix: Use proper lock for sigaction()

Update #2555.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/**
2 * @file
3 *
4 * @brief Allows calling process to examine action of a Specific Signal
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  3.3.4 Examine and Change Signal Action, P1003.1b-1993, p. 70
10 *
11 *  COPYRIGHT (c) 1989-1999.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <pthread.h>
24#include <signal.h>
25#include <errno.h>
26
27#include <rtems/posix/psignalimpl.h>
28#include <rtems/seterr.h>
29
30int sigaction(
31  int                     sig,
32  const struct sigaction *__restrict act,
33  struct sigaction       *__restrict oact
34)
35{
36  ISR_lock_Context lock_context;
37
38  if ( !sig )
39    rtems_set_errno_and_return_minus_one( EINVAL );
40
41  if ( !is_valid_signo(sig) )
42    rtems_set_errno_and_return_minus_one( EINVAL );
43
44  /*
45   *  Some signals cannot be ignored (P1003.1b-1993, pp. 70-72 and references.
46   *
47   *  NOTE: Solaris documentation claims to "silently enforce" this which
48   *        contradicts the POSIX specification.
49   */
50
51  if ( sig == SIGKILL )
52    rtems_set_errno_and_return_minus_one( EINVAL );
53
54  _POSIX_signals_Acquire( &lock_context );
55
56  if ( oact )
57    *oact = _POSIX_signals_Vectors[ sig ];
58
59  /*
60   *  Evaluate the new action structure and set the global signal vector
61   *  appropriately.
62   */
63
64  if ( act ) {
65
66    /*
67     *  Unless the user is installing the default signal actions, then
68     *  we can just copy the provided sigaction structure into the vectors.
69     */
70
71    if ( act->sa_handler == SIG_DFL ) {
72      _POSIX_signals_Vectors[ sig ] = _POSIX_signals_Default_vectors[ sig ];
73    } else {
74       _POSIX_signals_Clear_process_signals( sig );
75       _POSIX_signals_Vectors[ sig ] = *act;
76    }
77  }
78
79  _POSIX_signals_Release( &lock_context );
80
81  return 0;
82}
Note: See TracBrowser for help on using the repository browser.