Skip to content

Commit 378447f

Browse files
ichizokbrammool
authored andcommitted
patch 9.0.1544: recent glibc marks sigset() as a deprecated
Problem: Recent glibc marks sigset() as a deprecated. Solution: Use sigaction() in mch_signal() if possible. (Ozaki Kiichi, closes vim#12373)
1 parent 5d01f86 commit 378447f

12 files changed

+137
-75
lines changed

src/gui_haiku.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,8 @@ VimApp::ReadyToRun()
785785
* Apparently signals are inherited by the created thread -
786786
* disable the most annoying ones.
787787
*/
788-
signal(SIGINT, SIG_IGN);
789-
signal(SIGQUIT, SIG_IGN);
788+
mch_signal(SIGINT, SIG_IGN);
789+
mch_signal(SIGQUIT, SIG_IGN);
790790
}
791791

792792
void
@@ -1067,8 +1067,8 @@ VimFormView::AllAttached()
10671067
* Apparently signals are inherited by the created thread -
10681068
* disable the most annoying ones.
10691069
*/
1070-
signal(SIGINT, SIG_IGN);
1071-
signal(SIGQUIT, SIG_IGN);
1070+
mch_signal(SIGINT, SIG_IGN);
1071+
mch_signal(SIGQUIT, SIG_IGN);
10721072

10731073
if (menuBar && textArea) {
10741074
/*

src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ getout_preserve_modified(int exitval)
15571557
// Ignore SIGHUP, because a dropped connection causes a read error, which
15581558
// makes Vim exit and then handling SIGHUP causes various reentrance
15591559
// problems.
1560-
signal(SIGHUP, SIG_IGN);
1560+
mch_signal(SIGHUP, SIG_IGN);
15611561
# endif
15621562

15631563
ml_close_notmod(); // close all not-modified buffers

src/misc1.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2208,7 +2208,7 @@ prepare_to_exit(void)
22082208
// Ignore SIGHUP, because a dropped connection causes a read error, which
22092209
// makes Vim exit and then handling SIGHUP causes various reentrance
22102210
// problems.
2211-
signal(SIGHUP, SIG_IGN);
2211+
mch_signal(SIGHUP, SIG_IGN);
22122212
#endif
22132213

22142214
#ifdef FEAT_GUI

src/os_unix.c

+92-33
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,10 @@ static int have_dollars(int, char_u **);
214214
static int save_patterns(int num_pat, char_u **pat, int *num_file, char_u ***file);
215215

216216
#ifndef SIG_ERR
217-
# define SIG_ERR ((void (*)())-1)
217+
# define SIG_ERR ((sighandler_T)-1)
218+
#endif
219+
#ifndef SIG_HOLD
220+
# define SIG_HOLD ((sighandler_T)-2)
218221
#endif
219222

220223
// volatile because it is used in signal handler sig_winch().
@@ -340,6 +343,62 @@ static struct signalinfo
340343
{-1, "Unknown!", FALSE}
341344
};
342345

346+
sighandler_T
347+
mch_signal(int sig, sighandler_T func)
348+
{
349+
#if defined(HAVE_SIGACTION) && defined(HAVE_SIGPROCMASK)
350+
// Modern implementation: use sigaction().
351+
struct sigaction sa, old;
352+
sigset_t curset;
353+
int blocked;
354+
355+
if (sigprocmask(SIG_BLOCK, NULL, &curset) == -1)
356+
return SIG_ERR;
357+
358+
blocked = sigismember(&curset, sig);
359+
360+
if (func == SIG_HOLD)
361+
{
362+
if (blocked)
363+
return SIG_HOLD;
364+
365+
sigemptyset(&curset);
366+
sigaddset(&curset, sig);
367+
368+
if (sigaction(sig, NULL, &old) == -1
369+
|| sigprocmask(SIG_BLOCK, &curset, NULL) == -1)
370+
return SIG_ERR;
371+
return old.sa_handler;
372+
}
373+
374+
if (blocked)
375+
{
376+
sigemptyset(&curset);
377+
sigaddset(&curset, sig);
378+
379+
if (sigprocmask(SIG_UNBLOCK, &curset, NULL) == -1)
380+
return SIG_ERR;
381+
}
382+
383+
sa.sa_handler = func;
384+
sigemptyset(&sa.sa_mask);
385+
# ifdef SA_RESTART
386+
sa.sa_flags = SA_RESTART;
387+
# else
388+
sa.sa_flags = 0;
389+
# endif
390+
if (sigaction(sig, &sa, &old) == -1)
391+
return SIG_ERR;
392+
return blocked ? SIG_HOLD: old.sa_handler;
393+
#elif defined(HAVE_SIGSET)
394+
// Using sigset() is preferred above signal().
395+
return sigset(sig, func);
396+
#else
397+
// Oldest and most compatible solution.
398+
return signal(sig, func);
399+
#endif
400+
}
401+
343402
int
344403
mch_chdir(char *path)
345404
{
@@ -349,11 +408,11 @@ mch_chdir(char *path)
349408
smsg("chdir(%s)", path);
350409
verbose_leave();
351410
}
352-
# ifdef VMS
411+
#ifdef VMS
353412
return chdir(vms_fixfilename(path));
354-
# else
413+
#else
355414
return chdir(path);
356-
# endif
415+
#endif
357416
}
358417

359418
// Why is NeXT excluded here (and not in os_unixx.h)?
@@ -869,7 +928,7 @@ init_signal_stack(void)
869928
sig_winch SIGDEFARG(sigarg)
870929
{
871930
// this is not required on all systems, but it doesn't hurt anybody
872-
signal(SIGWINCH, (void (*)(int))sig_winch);
931+
mch_signal(SIGWINCH, sig_winch);
873932
do_resize = TRUE;
874933
}
875934
#endif
@@ -881,7 +940,7 @@ sig_tstp SIGDEFARG(sigarg)
881940
// Second time we get called we actually need to suspend
882941
if (in_mch_suspend)
883942
{
884-
signal(SIGTSTP, ignore_sigtstp ? SIG_IGN : SIG_DFL);
943+
mch_signal(SIGTSTP, ignore_sigtstp ? SIG_IGN : SIG_DFL);
885944
raise(sigarg);
886945
}
887946
else
@@ -890,7 +949,7 @@ sig_tstp SIGDEFARG(sigarg)
890949
#if !defined(__ANDROID__) && !defined(__OpenBSD__) && !defined(__DragonFly__)
891950
// This is not required on all systems. On some systems (at least Android,
892951
// OpenBSD, and DragonFlyBSD) this breaks suspending with CTRL-Z.
893-
signal(SIGTSTP, (void (*)(int))sig_tstp);
952+
mch_signal(SIGTSTP, sig_tstp);
894953
#endif
895954
}
896955
#endif
@@ -900,7 +959,7 @@ sig_tstp SIGDEFARG(sigarg)
900959
catch_sigint SIGDEFARG(sigarg)
901960
{
902961
// this is not required on all systems, but it doesn't hurt anybody
903-
signal(SIGINT, (void (*)(int))catch_sigint);
962+
mch_signal(SIGINT, catch_sigint);
904963
got_int = TRUE;
905964
}
906965
#endif
@@ -910,7 +969,7 @@ catch_sigint SIGDEFARG(sigarg)
910969
catch_sigusr1 SIGDEFARG(sigarg)
911970
{
912971
// this is not required on all systems, but it doesn't hurt anybody
913-
signal(SIGUSR1, (void (*)(int))catch_sigusr1);
972+
mch_signal(SIGUSR1, catch_sigusr1);
914973
got_sigusr1 = TRUE;
915974
}
916975
#endif
@@ -920,7 +979,7 @@ catch_sigusr1 SIGDEFARG(sigarg)
920979
catch_sigpwr SIGDEFARG(sigarg)
921980
{
922981
// this is not required on all systems, but it doesn't hurt anybody
923-
signal(SIGPWR, (void (*)())catch_sigpwr);
982+
mch_signal(SIGPWR, catch_sigpwr);
924983
/*
925984
* I'm not sure we get the SIGPWR signal when the system is really going
926985
* down or when the batteries are almost empty. Just preserve the swap
@@ -1364,7 +1423,7 @@ mch_init(void)
13641423
// that indicates the shell (or program) that launched us does not support
13651424
// tty job control and thus we should ignore that signal. If invoked as a
13661425
// restricted editor (e.g., as "rvim") SIGTSTP is always ignored.
1367-
ignore_sigtstp = restricted || SIG_IGN == signal(SIGTSTP, SIG_ERR);
1426+
ignore_sigtstp = restricted || SIG_IGN == mch_signal(SIGTSTP, SIG_ERR);
13681427
#endif
13691428
set_signals();
13701429

@@ -1383,28 +1442,28 @@ set_signals(void)
13831442
/*
13841443
* WINDOW CHANGE signal is handled with sig_winch().
13851444
*/
1386-
signal(SIGWINCH, (void (*)(int))sig_winch);
1445+
mch_signal(SIGWINCH, sig_winch);
13871446
#endif
13881447

13891448
#ifdef SIGTSTP
13901449
// See mch_init() for the conditions under which we ignore SIGTSTP.
13911450
// In the GUI default TSTP processing is OK.
13921451
// Checking both gui.in_use and gui.starting because gui.in_use is not set
13931452
// at this point (set after menus are displayed), but gui.starting is set.
1394-
signal(SIGTSTP, ignore_sigtstp ? SIG_IGN
1453+
mch_signal(SIGTSTP, ignore_sigtstp ? SIG_IGN
13951454
# ifdef FEAT_GUI
13961455
: gui.in_use || gui.starting ? SIG_DFL
13971456
# endif
1398-
: (void (*)(int))sig_tstp);
1457+
: sig_tstp);
13991458
#endif
14001459
#if defined(SIGCONT)
1401-
signal(SIGCONT, sigcont_handler);
1460+
mch_signal(SIGCONT, sigcont_handler);
14021461
#endif
14031462
#ifdef SIGPIPE
14041463
/*
14051464
* We want to ignore breaking of PIPEs.
14061465
*/
1407-
signal(SIGPIPE, SIG_IGN);
1466+
mch_signal(SIGPIPE, SIG_IGN);
14081467
#endif
14091468

14101469
#ifdef SIGINT
@@ -1415,22 +1474,22 @@ set_signals(void)
14151474
/*
14161475
* Call user's handler on SIGUSR1
14171476
*/
1418-
signal(SIGUSR1, (void (*)(int))catch_sigusr1);
1477+
mch_signal(SIGUSR1, catch_sigusr1);
14191478
#endif
14201479

14211480
/*
14221481
* Ignore alarm signals (Perl's alarm() generates it).
14231482
*/
14241483
#ifdef SIGALRM
1425-
signal(SIGALRM, SIG_IGN);
1484+
mch_signal(SIGALRM, SIG_IGN);
14261485
#endif
14271486

14281487
#ifdef SIGPWR
14291488
/*
14301489
* Catch SIGPWR (power failure?) to preserve the swap files, so that no
14311490
* work will be lost.
14321491
*/
1433-
signal(SIGPWR, (void (*)())catch_sigpwr);
1492+
mch_signal(SIGPWR, catch_sigpwr);
14341493
#endif
14351494

14361495
/*
@@ -1443,7 +1502,7 @@ set_signals(void)
14431502
* When the GUI is running, ignore the hangup signal.
14441503
*/
14451504
if (gui.in_use)
1446-
signal(SIGHUP, SIG_IGN);
1505+
mch_signal(SIGHUP, SIG_IGN);
14471506
#endif
14481507
}
14491508

@@ -1454,7 +1513,7 @@ set_signals(void)
14541513
static void
14551514
catch_int_signal(void)
14561515
{
1457-
signal(SIGINT, (void (*)(int))catch_sigint);
1516+
mch_signal(SIGINT, catch_sigint);
14581517
}
14591518
#endif
14601519

@@ -1464,7 +1523,7 @@ reset_signals(void)
14641523
catch_signals(SIG_DFL, SIG_DFL);
14651524
#if defined(SIGCONT)
14661525
// SIGCONT isn't in the list, because its default action is ignore
1467-
signal(SIGCONT, SIG_DFL);
1526+
mch_signal(SIGCONT, SIG_DFL);
14681527
#endif
14691528
}
14701529

@@ -1506,19 +1565,19 @@ catch_signals(
15061565
sv.sv_flags = SV_ONSTACK;
15071566
sigvec(signal_info[i].sig, &sv, NULL);
15081567
# else
1509-
signal(signal_info[i].sig, func_deadly);
1568+
mch_signal(signal_info[i].sig, func_deadly);
15101569
# endif
15111570
#endif
15121571
}
15131572
else if (func_other != SIG_ERR)
15141573
{
15151574
// Deal with non-deadly signals.
15161575
#ifdef SIGTSTP
1517-
signal(signal_info[i].sig,
1576+
mch_signal(signal_info[i].sig,
15181577
signal_info[i].sig == SIGTSTP && ignore_sigtstp
15191578
? SIG_IGN : func_other);
15201579
#else
1521-
signal(signal_info[i].sig, func_other);
1580+
mch_signal(signal_info[i].sig, func_other);
15221581
#endif
15231582
}
15241583
}
@@ -1923,7 +1982,7 @@ get_x11_windis(void)
19231982
if (x11_window != 0 && x11_display == NULL)
19241983
{
19251984
#ifdef SET_SIG_ALARM
1926-
void (*sig_save)();
1985+
sighandler_T sig_save;
19271986
#endif
19281987
#ifdef ELAPSED_FUNC
19291988
elapsed_T start_tv;
@@ -1938,14 +1997,14 @@ get_x11_windis(void)
19381997
* the network connection is bad. Set an alarm timer to get out.
19391998
*/
19401999
sig_alarm_called = FALSE;
1941-
sig_save = (void (*)())signal(SIGALRM, (void (*)())sig_alarm);
2000+
sig_save = mch_signal(SIGALRM, sig_alarm);
19422001
alarm(2);
19432002
#endif
19442003
x11_display = XOpenDisplay(NULL);
19452004

19462005
#ifdef SET_SIG_ALARM
19472006
alarm(0);
1948-
signal(SIGALRM, (void (*)())sig_save);
2007+
mch_signal(SIGALRM, sig_save);
19492008
if (p_verbose > 0 && sig_alarm_called)
19502009
verb_msg(_("Opening the X display timed out"));
19512010
#endif
@@ -3519,7 +3578,7 @@ may_core_dump(void)
35193578
{
35203579
if (deadly_signal != 0)
35213580
{
3522-
signal(deadly_signal, SIG_DFL);
3581+
mch_signal(deadly_signal, SIG_DFL);
35233582
kill(getpid(), deadly_signal); // Die using the signal we caught
35243583
}
35253584
}
@@ -4828,7 +4887,7 @@ mch_call_shell_fork(
48284887
// will exit and send SIGHUP to all processes in its
48294888
// group, killing the just started process. Ignore SIGHUP
48304889
// to avoid that. (suggested by Simon Schubert)
4831-
signal(SIGHUP, SIG_IGN);
4890+
mch_signal(SIGHUP, SIG_IGN);
48324891
# endif
48334892
}
48344893
# endif
@@ -7283,7 +7342,7 @@ gpm_open(void)
72837342
// we are going to suspend or starting an external process
72847343
// so we shouldn't have problem with this
72857344
# ifdef SIGTSTP
7286-
signal(SIGTSTP, restricted ? SIG_IGN : (void (*)())sig_tstp);
7345+
mch_signal(SIGTSTP, restricted ? SIG_IGN : sig_tstp);
72877346
# endif
72887347
return 1; // succeed
72897348
}
@@ -7415,7 +7474,7 @@ sysmouse_open(void)
74157474
if (ioctl(1, CONS_MOUSECTL, &mouse) == -1)
74167475
return FAIL;
74177476

7418-
signal(SIGUSR2, (void (*)())sig_sysmouse);
7477+
mch_signal(SIGUSR2, sig_sysmouse);
74197478
mouse.operation = MOUSE_SHOW;
74207479
ioctl(1, CONS_MOUSECTL, &mouse);
74217480
return OK;
@@ -7430,7 +7489,7 @@ sysmouse_close(void)
74307489
{
74317490
struct mouse_info mouse;
74327491

7433-
signal(SIGUSR2, restricted ? SIG_IGN : SIG_DFL);
7492+
mch_signal(SIGUSR2, restricted ? SIG_IGN : SIG_DFL);
74347493
mouse.operation = MOUSE_MODE;
74357494
mouse.u.mode.mode = 0;
74367495
mouse.u.mode.signal = 0;

src/os_unix.h

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
# define SIGDUMMYARG
9999
#endif
100100

101+
typedef void (*sighandler_T) SIGPROTOARG;
102+
101103
#ifdef HAVE_DIRENT_H
102104
# include <dirent.h>
103105
# ifndef NAMLEN

src/os_unixx.h

+1-8
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@
1010
* os_unixx.h -- include files that are only used in os_unix.c
1111
*/
1212

13-
/*
14-
* Stuff for signals
15-
*/
16-
#if defined(HAVE_SIGSET) && !defined(signal)
17-
# define signal sigset
18-
#endif
19-
20-
// Sun's sys/ioctl.h redefines symbols from termio world
13+
// Sun's sys/ioctl.h redefines symbols from termio world
2114
#if defined(HAVE_SYS_IOCTL_H) && !defined(SUN_SYSTEM)
2215
# include <sys/ioctl.h>
2316
#endif

0 commit comments

Comments
 (0)