~stgraber/+junk/nm-ofono

« back to all changes in this revision

Viewing changes to src/posix-signals/nm-posix-signals.c

  • Committer: Stéphane Graber
  • Date: 2013-03-15 18:27:57 UTC
  • Revision ID: stgraber@ubuntu.com-20130315182757-7bcjymubsn3lsshs
Import of NM 0.9.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
 
2
/* NetworkManager -- Network link manager
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License along
 
15
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
17
 *
 
18
 * Copyright (C) 2012 Red Hat, Inc.
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <signal.h>
 
24
 
 
25
#include "nm-posix-signals.h"
 
26
 
 
27
 
 
28
/* Stores the original signal mask of NetworkManager process */
 
29
static sigset_t nm_original_signal_mask;
 
30
 
 
31
void
 
32
nm_save_original_signal_mask (sigset_t sig_mask)
 
33
{
 
34
        nm_original_signal_mask = sig_mask;
 
35
}
 
36
 
 
37
const sigset_t *
 
38
nm_get_original_signal_mask (void)
 
39
{
 
40
        return &nm_original_signal_mask;
 
41
}
 
42
 
 
43
/* 
 
44
 * Unblock signals.
 
45
 * If a signal set is passed, those signals are unblocked. If user_data is NULL
 
46
 * the process' signal mask is set to the saved original mask.
 
47
 * Note: This function can be used in g_spawn_* as GSpawnChildSetupFunc()
 
48
 *       callback.
 
49
 */
 
50
void
 
51
nm_unblock_posix_signals (gpointer user_data)
 
52
{
 
53
        sigset_t *user_sigset = (sigset_t *) user_data;
 
54
 
 
55
        if (user_sigset != NULL) {
 
56
                pthread_sigmask (SIG_UNBLOCK, user_sigset, NULL);
 
57
        } else {
 
58
                const sigset_t *orig_sig_mask = nm_get_original_signal_mask ();
 
59
                pthread_sigmask (SIG_SETMASK, orig_sig_mask, NULL);
 
60
        }
 
61
}
 
62