~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to ftsh/src/cancel.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
 
3
Copyright (C) 2005- The University of Notre Dame
 
4
This software is distributed under the GNU General Public License.
 
5
See the file COPYING for details.
 
6
*/
 
7
 
 
8
#include <signal.h>
 
9
#include <unistd.h>
 
10
#include <sys/time.h>
 
11
#include <time.h>
 
12
 
 
13
#include "ftsh_error.h"
 
14
#include "stringtools.h"
 
15
 
 
16
struct sigaction old_int_handler;
 
17
struct sigaction old_hup_handler;
 
18
struct sigaction old_quit_handler;
 
19
struct sigaction old_term_handler;
 
20
 
 
21
static int cancel_signal = 0;
 
22
 
 
23
static void cancel_handler( int sig )
 
24
{
 
25
        ftsh_error(FTSH_ERROR_PROCESS,0,"received signal %d",sig);
 
26
        cancel_signal = sig;
 
27
}
 
28
 
 
29
void cancel_hold()
 
30
{
 
31
        struct sigaction sa;
 
32
        sigset_t ss;
 
33
 
 
34
        sigemptyset(&ss);
 
35
        sa.sa_handler = cancel_handler;
 
36
        sa.sa_mask = ss;
 
37
        sa.sa_flags = 0;
 
38
 
 
39
        sigaction(SIGINT,&sa,&old_int_handler);
 
40
        sigaction(SIGHUP,&sa,&old_hup_handler);
 
41
        sigaction(SIGQUIT,&sa,&old_quit_handler);
 
42
        sigaction(SIGTERM,&sa,&old_term_handler);
 
43
}
 
44
 
 
45
void cancel_release()
 
46
{
 
47
        sigaction(SIGINT,&old_int_handler,0);
 
48
        sigaction(SIGHUP,&old_int_handler,0);
 
49
        sigaction(SIGQUIT,&old_int_handler,0);
 
50
        sigaction(SIGTERM,&old_int_handler,0);
 
51
        if(cancel_signal!=0) kill(getpid(),cancel_signal);
 
52
}
 
53
 
 
54
int cancel_pending()
 
55
{
 
56
        return cancel_signal!=0;
 
57
}
 
58
 
 
59
void cancel_reset()
 
60
{
 
61
        cancel_signal = 0;
 
62
}