1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: signals.c 769 2007-10-24 00:15:40Z hubert@u.washington.edu $";
6 * ========================================================================
7 * Copyright 2006-2007 University of Washington
8 * Copyright 2013-2018 Eduardo Chappa
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
22 #include "../headers.h"
24 #include "../../pith/charconv/filesys.h"
31 /* internal prototypes */
33 RETSIGTYPE
do_hup_signal(int);
38 * picosigs - Install any handlers for the signals we're interested
45 signal(SIGHUP
, do_hup_signal
); /* deal with SIGHUP */
46 signal(SIGTERM
, do_hup_signal
); /* deal with SIGTERM */
48 signal(SIGTSTP
, SIG_DFL
);
50 #if defined(SIGWINCH) && defined(TIOCGWINSZ)
51 signal(SIGWINCH
, winch_handler
); /* window size changes */
53 #endif /* !_WINDOWS */
61 * do_hup_signal - jump back in the stack to where we can handle this
64 do_hup_signal(int sig
)
66 signal(SIGHUP
, SIG_IGN
); /* ignore further SIGHUP's */
67 signal(SIGTERM
, SIG_IGN
); /* ignore further SIGTERM's */
69 extern jmp_buf finstate
;
71 longjmp(finstate
, COMP_GOTHUP
);
75 * if we've been interrupted and the buffer is changed,
78 if(anycb() == TRUE
){ /* time to save */
79 if(curbp
->b_fname
[0] == '\0'){ /* name it */
80 strncpy(curbp
->b_fname
, "pico.save", sizeof(curbp
->b_fname
));
81 curbp
->b_fname
[sizeof(curbp
->b_fname
)-1] = '\0';
84 strncat(curbp
->b_fname
, ".save", sizeof(curbp
->b_fname
)-strlen(curbp
->b_fname
)-1);
85 curbp
->b_fname
[sizeof(curbp
->b_fname
)-1] = '\0';
88 our_unlink(curbp
->b_fname
);
89 writeout(curbp
->b_fname
, TRUE
);
96 #endif /* !_WINDOWS */
99 #if defined(SIGWINCH) && defined(TIOCGWINSZ)
101 * winch_handler - handle window change signal
104 winch_handler(int sig
)
107 signal(SIGWINCH
, winch_handler
);
111 i
= Pmaster
->arm_winch_cleanup
;
112 Pmaster
->arm_winch_cleanup
= 1;
114 if(Pmaster
&& Pmaster
->winch_cleanup
&& Pmaster
->arm_winch_cleanup
)
115 (*Pmaster
->winch_cleanup
)();
116 if(wheadp
== NULL
&& Pmaster
!= NULL
)
117 Pmaster
->arm_winch_cleanup
= i
;
119 #endif /* SIGWINCH and friends */
124 /*----------------------------------------------------------------------
125 Reset signals after critical imap code
128 (*posix_signal(int sig_num
, RETSIGTYPE (*action
)(int)))(int)
130 struct sigaction new_action
, old_action
;
132 memset((void *)&new_action
, 0, sizeof(struct sigaction
));
133 sigemptyset (&new_action
.sa_mask
);
134 new_action
.sa_handler
= action
;
136 new_action
.sa_flags
= SA_RESTART
;
138 new_action
.sa_flags
= 0;
140 sigaction(sig_num
, &new_action
, &old_action
);
141 return(old_action
.sa_handler
);
145 posix_sigunblock(int mask
)
149 sigemptyset(&sig_mask
);
150 sigaddset(&sig_mask
, mask
);
152 # define sigprocmask pthread_sigmask
154 return(sigprocmask(SIG_UNBLOCK
, &sig_mask
, NULL
));
156 #endif /* POSIX_SIGNALS */
159 #if defined(sv3) || defined(ct)
160 /* Placed by rll to handle the rename function not found in AT&T */
162 rename(char *oldname
, char *newname
)
167 strncpy(b
, fname_to_locale(oldname
), sizeof(b
));
168 b
[sizeof(b
)-1] = '\0';
170 if ((rtn
= link(b
, fname_to_locale(newname
))) != 0) {
171 perror("Was not able to rename file.");
175 if ((rtn
= our_unlink(b
)) != 0)
176 perror("Was not able to unlink file.");