2 * ========================================================================
3 * Copyright 2006-2007 University of Washington
4 * Copyright 2013-2022 Eduardo Chappa
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
18 #include "../headers.h"
20 #include "../../pith/charconv/filesys.h"
27 /* internal prototypes */
29 RETSIGTYPE
do_hup_signal(int);
34 * picosigs - Install any handlers for the signals we're interested
41 signal(SIGHUP
, do_hup_signal
); /* deal with SIGHUP */
42 signal(SIGTERM
, do_hup_signal
); /* deal with SIGTERM */
44 signal(SIGTSTP
, SIG_DFL
);
46 #if defined(SIGWINCH) && defined(TIOCGWINSZ)
47 signal(SIGWINCH
, winch_handler
); /* window size changes */
49 #endif /* !_WINDOWS */
57 * do_hup_signal - jump back in the stack to where we can handle this
60 do_hup_signal(int sig
)
62 signal(SIGHUP
, SIG_IGN
); /* ignore further SIGHUP's */
63 signal(SIGTERM
, SIG_IGN
); /* ignore further SIGTERM's */
65 extern jmp_buf finstate
;
67 longjmp(finstate
, COMP_GOTHUP
);
71 * if we've been interrupted and the buffer is changed,
74 if(anycb() == TRUE
){ /* time to save */
75 if(curbp
->b_fname
[0] == '\0'){ /* name it */
76 strncpy(curbp
->b_fname
, "pico.save", sizeof(curbp
->b_fname
));
77 curbp
->b_fname
[sizeof(curbp
->b_fname
)-1] = '\0';
80 strncat(curbp
->b_fname
, ".save", sizeof(curbp
->b_fname
)-strlen(curbp
->b_fname
)-1);
81 curbp
->b_fname
[sizeof(curbp
->b_fname
)-1] = '\0';
84 our_unlink(curbp
->b_fname
);
85 writeout(curbp
->b_fname
, TRUE
);
92 #endif /* !_WINDOWS */
95 #if defined(SIGWINCH) && defined(TIOCGWINSZ)
97 * winch_handler - handle window change signal
100 winch_handler(int sig
)
103 signal(SIGWINCH
, winch_handler
);
107 i
= Pmaster
->arm_winch_cleanup
;
108 Pmaster
->arm_winch_cleanup
= 1;
110 if(Pmaster
&& Pmaster
->winch_cleanup
&& Pmaster
->arm_winch_cleanup
)
111 (*Pmaster
->winch_cleanup
)();
112 if(wheadp
== NULL
&& Pmaster
!= NULL
)
113 Pmaster
->arm_winch_cleanup
= i
;
115 #endif /* SIGWINCH and friends */
120 /*----------------------------------------------------------------------
121 Reset signals after critical imap code
124 (*posix_signal(int sig_num
, RETSIGTYPE (*action
)(int)))(int)
126 struct sigaction new_action
, old_action
;
128 memset((void *)&new_action
, 0, sizeof(struct sigaction
));
129 sigemptyset (&new_action
.sa_mask
);
130 new_action
.sa_handler
= action
;
132 new_action
.sa_flags
= SA_RESTART
;
134 new_action
.sa_flags
= 0;
136 sigaction(sig_num
, &new_action
, &old_action
);
137 return(old_action
.sa_handler
);
141 posix_sigunblock(int mask
)
145 sigemptyset(&sig_mask
);
146 sigaddset(&sig_mask
, mask
);
148 # define sigprocmask pthread_sigmask
150 return(sigprocmask(SIG_UNBLOCK
, &sig_mask
, NULL
));
152 #endif /* POSIX_SIGNALS */
155 #if defined(sv3) || defined(ct)
156 /* Placed by rll to handle the rename function not found in AT&T */
158 rename(char *oldname
, char *newname
)
163 strncpy(b
, fname_to_locale(oldname
), sizeof(b
));
164 b
[sizeof(b
)-1] = '\0';
166 if ((rtn
= link(b
, fname_to_locale(newname
))) != 0) {
167 perror("Was not able to rename file.");
171 if ((rtn
= our_unlink(b
)) != 0)
172 perror("Was not able to unlink file.");