permission denied on bind when restart with execl - Unix
This is a discussion on permission denied on bind when restart with execl - Unix ; Then in my application when alert() happen a signal handler start. The
signal handler should restart application, i do it with execl()
function:
void onTimeoutHandler(){
// argv1 & argv2 are two global var that contain argv[1] e argv[2]
execl("application", argv1, ...
-
permission denied on bind when restart with execl
Then in my application when alert() happen a signal handler start. The
signal handler should restart application, i do it with execl()
function:
void onTimeoutHandler(){
// argv1 & argv2 are two global var that contain argv[1] e argv[2]
execl("application", argv1, argv2);
}
The apps really restart but the problem is that it stop itself on bind
time and deny me the permission. this is socket line:
// ....
if((list_fd=socket(PF_INET,SOCK_STREAM,0))<0) /* creo la socket e
controllo eventuali errori */
{
perror("Errore creazione socket\n");
exit(-1);
}
server.sin_family=AF_INET; /* specifico famiglia */
server.sin_port=htons(atoi(argv[1])); /* specifico la porta
su cui il server sarą in ascolto */
server.sin_addr.s_addr=htonl(INADDR_ANY); /* il server sarą in
ascolto su tutti i suoi indirizzi ip */
/* Attivando l'opzione SO_REUSEADDR il kernel non
aspetterą per liberare l'indirizzo */
attivo = 1;
if(setsockopt(list_fd, SOL_SOCKET, SO_REUSEADDR,
&attivo, sizeof(int)) < 0)
{
perror("Errore setsockopt\n");
exit(-1);
}
/* Binding socket-indirizzo */
if(bind(list_fd,(struct sockaddr*)&server,sizeof(server))<0)
{
perror("Errore bind\n");
exit(-1);
}
// ....
-
Re: permission denied on bind when restart with execl
>Then in my application when alert() happen a signal handler start. The
>signal handler should restart application, i do it with execl()
>function:
>void onTimeoutHandler(){
> // argv1 & argv2 are two global var that contain argv[1] e argv[2]
> execl("application", argv1, argv2);
>}
Don't you need to close existing open file descriptors here? (Other than
stdin, stdout, and stderr). Otherwise you're leaking file descriptors
every restart.
>
>The apps really restart but the problem is that it stop itself on bind
>time and deny me the permission. this is socket line:
>// ....
Before trying to open the socket again, close the old one.
>if((list_fd=socket(PF_INET,SOCK_STREAM,0))<0) /* creo la socket e
>controllo eventuali errori */
> {
> perror("Errore creazione socket\n");
> exit(-1);
> }
>
> server.sin_family=AF_INET; /* specifico famiglia */
> server.sin_port=htons(atoi(argv[1])); /* specifico la porta
>su cui il server sarą in ascolto */
> server.sin_addr.s_addr=htonl(INADDR_ANY); /* il server sarą in
>ascolto su tutti i suoi indirizzi ip */
>
> /* Attivando l'opzione SO_REUSEADDR il kernel non
>aspetterą per liberare l'indirizzo */
> attivo = 1;
> if(setsockopt(list_fd, SOL_SOCKET, SO_REUSEADDR,
>&attivo, sizeof(int)) < 0)
> {
> perror("Errore setsockopt\n");
> exit(-1);
> }
>
> /* Binding socket-indirizzo */
> if(bind(list_fd,(struct sockaddr*)&server,sizeof(server))<0)
> {
> perror("Errore bind\n");
> exit(-1);
> }
>// ....
-
Re: permission denied on bind when restart with execl
In article ,
gordonb.kdxvo@burditt.org (Gordon Burditt) wrote:
> >Then in my application when alert() happen a signal handler start. The
> >signal handler should restart application, i do it with execl()
> >function:
> >void onTimeoutHandler(){
> > // argv1 & argv2 are two global var that contain argv[1] e argv[2]
> > execl("application", argv1, argv2);
> >}
>
> Don't you need to close existing open file descriptors here? (Other than
> stdin, stdout, and stderr). Otherwise you're leaking file descriptors
> every restart.
Or set the close-on-exec flag for the descriptors, so they're closed
automatically.
>
> >
> >The apps really restart but the problem is that it stop itself on bind
> >time and deny me the permission. this is socket line:
> >// ....
>
> Before trying to open the socket again, close the old one.
>
> >if((list_fd=socket(PF_INET,SOCK_STREAM,0))<0) /* creo la socket e
> >controllo eventuali errori */
> > {
> > perror("Errore creazione socket\n");
> > exit(-1);
> > }
> >
> > server.sin_family=AF_INET; /* specifico famiglia */
> > server.sin_port=htons(atoi(argv[1])); /* specifico la porta
> >su cui il server sarą in ascolto */
> > server.sin_addr.s_addr=htonl(INADDR_ANY); /* il server sarą in
> >ascolto su tutti i suoi indirizzi ip */
> >
> > /* Attivando l'opzione SO_REUSEADDR il kernel non
> >aspetterą per liberare l'indirizzo */
> > attivo = 1;
> > if(setsockopt(list_fd, SOL_SOCKET, SO_REUSEADDR,
> >&attivo, sizeof(int)) < 0)
> > {
> > perror("Errore setsockopt\n");
> > exit(-1);
> > }
> >
> > /* Binding socket-indirizzo */
> > if(bind(list_fd,(struct sockaddr*)&server,sizeof(server))<0)
> > {
> > perror("Errore bind\n");
> > exit(-1);
> > }
> >// ....
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
-
Re: permission denied on bind when restart with execl
On 28 Ago, 07:25, Barry Margolin wrote:
> In article ,
> *gordonb.kd...@burditt.org (Gordon Burditt) wrote:
>
> > >Then in my application when alert() happen a signal handler start. The
> > >signal handler should restart application, i do it with execl()
> > >function:
> > >void onTimeoutHandler() {
> > > * *// argv1 & argv2 are two global var that contain argv[1] e argv[2]
> > > * *execl("application", argv1, argv2);
> > >}
>
> > Don't you need to close existing open file descriptors here? *(Other than
> > stdin, stdout, and stderr). *Otherwise you're leaking file descriptors
> > every restart.
>
> Or set the close-on-exec flag for the descriptors, so they're closed
> automatically.
>
>
>
>
>
> > >The apps really restart but the problem is that it stop itself on bind
> > >time and deny me the permission. this is socket line:
> > >// ....
>
> > Before trying to open the socket again, close the old one.
>
> > >if((list_fd=socket(PF_INET,SOCK_STREAM,0))<0) * * */* creo la socket e
> > >controllo eventuali errori */
> > > * * * * * * * *{
> > > * * * * * * * * * * * perror("Errore creazione socket\n");
> > > * * * * * * * * * * * exit(-1);
> > > * * * * * * * }
>
> > > * * * * * * * server.sin_family=AF_INET; * * * * * * * * * /* specifico famiglia */
> > > * * * * * * * server.sin_port=htons(atoi(argv[1])); * * * */* specifico la porta
> > >su cui il server sarą in ascolto */
> > > * * * * * * * server.sin_addr.s_addr=htonl(INADDR_ANY); * */* il server sarą in
> > >ascolto su tutti i suoi indirizzi ip */
>
> > > * * * * * * * */* Attivando l'opzione SO_REUSEADDR ilkernel non
> > >aspetterą per liberare l'indirizzo */
> > > * * * * * * * *attivo = 1;
> > > * * * * * * * *if(setsockopt(list_fd, SOL_SOCKET, SO_REUSEADDR,
> > >&attivo, sizeof(int)) < 0)
> > > * * * * * * * *{
> > > * * * * * * * * * *perror("Errore setsockopt\n");
> > > * * * * * * * * * *exit(-1);
> > > * * * * * * * *}
>
> > > * * * * * * * */* Binding socket-indirizzo */
> > > * * * * * * * if(bind(list_fd,(struct sockaddr*)&server,sizeof(server))<0)
> > > * * * * * * * *{
> > > * * * * * * * * * * * perror("Errore bind\n");
> > > * * * * * * * * * * * exit(-1);
> > > * * * * * * * }
> > >// ....
>
> --
> Barry Margolin, bar...@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***
for every descriptor in my program???
In this example where I've to put???
-
Re: permission denied on bind when restart with execl
On Thu, 28 Aug 2008 02:08:29 -0700 (PDT) Mariano wrote:
| for every descriptor in my program???
Sure. Are there any descriptors you want to leave open in the program being
executed? You might want to leave stdin, stdout, and stderr, open. All the
remaining descriptors you might want closed.
--
|WARNING: Due to extreme spam, googlegroups.com is blocked. Due to ignorance |
| by the abuse department, bellsouth.net is blocked. If you post to |
| Usenet from these places, find another Usenet provider ASAP. |
| Phil Howard KA9WGN (email for humans: first name in lower case at ipal.net) |
-
Re: permission denied on bind when restart with execl
>> > Don't you need to close existing open file descriptors here? =A0(Other =
>than
>> > stdin, stdout, and stderr). =A0Otherwise you're leaking file descriptor=
>s
>> > every restart.
>>
>> Or set the close-on-exec flag for the descriptors, so they're closed
>> automatically.
>>
....
>for every descriptor in my program???
Yes, except those you intend to re-use on a restart (stdin, stdout,
and stderr probably qualify for this). You could add arguments to
the command-line on a restart telling it the file descriptors to
re-use and their numbers, but you might want a clean restart including
re-opening these.
>In this example where I've to put???
Sense no parse cannot.
-
Re: permission denied on bind when restart with execl
On 28 Ago, 19:30, gordonb.dk...@burditt.org (Gordon Burditt) wrote:
> >> > Don't you need to close existing open file descriptors here? =A0(Other =
> >than
> >> > stdin, stdout, and stderr). =A0Otherwise you're leaking file descriptor=
> >s
> >> > every restart.
>
> >> Or set the close-on-exec flag for the descriptors, so they're closed
> >> automatically.
>
> ...
> >for every descriptor in my program???
>
> Yes, except those you intend to re-use on a restart (stdin, stdout,
> and stderr probably qualify for this). *You could add arguments to
> the command-line on a restart telling it the file descriptors to
> re-use and their numbers, but you might want a clean restart including
> re-opening these.
>
> >In this example where I've to put???
>
> Sense no parse cannot.
Thank you guys, it's OK now!!!