Ask a Question related to UNIX Programming, Design and Development.
-
William Ahern #1
initialize all signals to SIG_DFL
is there a way to initialize all signals to SIG_DFL? the only way i can
think of is to loop thru all possible signals and install the SIG_DFL
handler, but how do i get a list of *all* signals (portably)?
also, for good measure, is there a way to close all file descriptors on
execve() (such as a trick to globally set close-on-exec for all current
descriptors)?
fwiw, i'm creating a popenl() function, like popen() but w/ execl
semantics. and so while i'm at it i'd like to add some useful features.
tia,
Bill
William Ahern Guest
-
Net::Telnet, fork and signals..
Hello, I've been trying to figure this out for the past couple of days but am hitting a wall. I am using Net::Telnet 3.03 with a modification... -
Signals and Net::Telnet::command
Hello, I had a question regarding signals and Net::Telnet and was wondering if someone had an insight into it. My script looks like:... -
More on 5.8 and signals
Hi, I am pretty desparate to get this working, and if anyone wants to earn some cash helping me fix things PLEASE call me at 250 655-9513. ... -
Signals and recvfrom() behavior
Hello, I have a program which is waiting for data on a socket in recvfrom(). If a signal (SIGTERM) is sent to the program, should recvfrom()... -
Usable signals for own needs
On 22 Jul 2003, Peteris Krumins wrote: Not portably. BTW, SIGHUP is the usual "reload config" signal. Maybe you need to rethink your... -
William Ahern #2
Re: initialize all signals to SIG_DFL
Paul Pluzhnikov <ppluzhnikov@earthlink.net> wrote:
well, obviously ;) however, i was hoping that there were some other tricks> William Ahern <william@wilbur.25thandClement.com> writes:
>>>> but how do i get a list of *all* signals (portably)?
> You don't need to. Just do it:
>
> for (i = 1; i < 2048; i++)
> signal(i, SIG_DFL);
>>>> also, for good measure, is there a way to close all file descriptors on
>> execve()
> Sure. Same as above ...
of the trade (i read about F_CLOSEM fcntl() flag somewhere). toying around
in Linux i remembered that /dev/fd lists all the open descriptors (including
sockets, i hope). openbsd also has a /dev/fd, altho it lists all integers up
to the max open limit (which puts us back to using getdtablesize() or
getrlimit(), but not any worse). so maybe it's reasonable to assume that if
opendir("/dev/fd") succeeds then its safe to read the descriptors from it,
otherwise fall back to getdtablesize().
- Bill
William Ahern Guest
-
Casper H.S. Dik #3
Re: initialize all signals to SIG_DFL
William Ahern <william@wilbur.25thandClement.com> writes:
>well, obviously ;) however, i was hoping that there were some other tricks
>of the trade (i read about F_CLOSEM fcntl() flag somewhere). toying around
>in Linux i remembered that /dev/fd lists all the open descriptors (including
>sockets, i hope). openbsd also has a /dev/fd, altho it lists all integers up
>to the max open limit (which puts us back to using getdtablesize() or
>getrlimit(), but not any worse). so maybe it's reasonable to assume that if
>opendir("/dev/fd") succeeds then its safe to read the descriptors from it,
>otherwise fall back to getdtablesize().
Solaris has /dev/fd but it may have too many entries; /proc/self/fd
is actually better (has the exact list of fds in use).
Solaris 9 and later have "closefrom()" which does what you want.
[url]http://docs.sun.com/db/doc/816-0213/6m6ne37rj?q=%22linkers%22&a=view[/url]
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
Casper H.S. Dik Guest
-
Casper H.S. Dik #4
Re: initialize all signals to SIG_DFL
Marc Rochkind <rochkind@basepath.com> writes:
If you can assume that signals are complete, then this might work:>There are only a few (around 28, if memory serves me) portable signals, so
>those are the ones to set. There are more realtime signals, so make sure
>you check the appropriate feature-test macros for them, and set them, too,
>if they're there.
for (sig = sysconf(_SC_SIGRT_MAX); sig > 0; sig--)
signal(sig, SIG_DFL);
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
Casper H.S. Dik Guest
-
William Ahern #5
Re: initialize all signals to SIG_DFL
Casper H.S. Dik <Casper.Dik@sun.com> wrote:
Other people have suggested in the past that one could use dup2() to get a> Richard Kettlewell <invalid@invalid.invalid> writes:
>>>>The question is how to establish an upper bound on open file
>>descriptors (preferrably a better one than INT_MAX).
> If you don't have /dev/fd or /proc/self/fd that's going to be really
> hard.
>
> getrlimit() will tell you what the highest *currently* allowed fd is;
> but open fds might have higher numbers.
descriptor higher than .rlim_cur or .rlim_max. However, FWIW, on OpenBSD 3.3
and on Linux-2.4.20 (glibc 2.3.1) this doesn't seem to work.
This would fail:
fd = dup2(STDIN_FILENO,getdtablesize());
While this would work:
fd = dup2(STDIN_FILENO,getdtablesize()-1);
Would this behavior be fairly consistent across most implementations?
- Bill
William Ahern Guest
-
Casper H.S. Dik #6
Re: initialize all signals to SIG_DFL
William Ahern <william@wilbur.25thandClement.com> writes:
>Other people have suggested in the past that one could use dup2() to get a
>descriptor higher than .rlim_cur or .rlim_max. However, FWIW, on OpenBSD 3.3
>and on Linux-2.4.20 (glibc 2.3.1) this doesn't seem to work.>This would fail:> fd = dup2(STDIN_FILENO,getdtablesize());>While this would work:> fd = dup2(STDIN_FILENO,getdtablesize()-1);I'd say that an OS in which the first statement doesn't fail>Would this behavior be fairly consistent across most implementations?
is broken. But you can always lower the limit after the first
one.
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
Casper H.S. Dik Guest
-
Geoff Clare #7
Re: initialize all signals to SIG_DFL
Michael Kerrisk <michael.kerrisk@freenet.de> writes:
NSIG is not only "not standardised in SUSv3", it's forbidden by SUSv3,> many, though not all implementetations define the
>constant NSIG (not standardised in SUSv3) as the maximum signal
>number.
since it is not in the namespace reserved for the implementation.
(The same applies for SUSv2, SUSv1 and XPG4, but it was allowed by
XPG3 and required by XPG2).
Modern systems that define it only do so for non-standards-compliant
compilation environments.
Also, it is usually the maximum signal number *plus one*.
--
Geoff Clare <nospam@gclare.org.uk>
Geoff Clare Guest



Reply With Quote

