Skip to content

Commit

Permalink
Merge pull request #1111 from veremenko-y/netd
Browse files Browse the repository at this point in the history
netd: cleanup on termination
  • Loading branch information
EtchedPixels authored Nov 8, 2024
2 parents 70e093a + 07e25eb commit 60db44d
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions Applications/netd/netd.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static uint8_t ringbuf[BMEM_SIZE];
static uint8_t *bmem = ringbuf;
#else
int bfd; /* fd of data backing file */
#define NETD_RINGBUF_FILE "/tmp/net.back"
#endif
int knet; /* fd of kernel's network inface */
int rc; /* fd of rc file */
Expand Down Expand Up @@ -967,17 +968,37 @@ int parse_rcfile( void ){
return 0;
}


void cleanup(int sig)
{
#ifndef NETD_RINGBUF_IN_MEMORY
if ( bfd >= 0 ){
close(bfd);
bfd = -1;
unlink(NETD_RINGBUF_FILE);
}
#endif
if ( knet >= 0 ){
close(knet);
knet = -1;
}
if ( sig != 0 ){
exit(128 + sig);
}
exit(0);
}

int main( int argc, char *argv[] )
{
int ret;
uip_ipaddr_t ipaddr;
uip_eth_addr ethaddr; /* mac address buffer */

signal(SIGHUP, cleanup);
signal(SIGINT, cleanup);
signal(SIGTERM, cleanup);
#ifndef NETD_RINGBUF_IN_MEMORY
/* where should backing file go? /var, /tmp, other? */
bfd = open( "/tmp/net.back", O_RDWR|O_CREAT, 0644 );
bfd = open( NETD_RINGBUF_FILE, O_RDWR|O_CREAT, 0644 );
if ( bfd < 0 ){
exit_err( "cannot open backing file\n");
}
Expand Down Expand Up @@ -1057,4 +1078,5 @@ int main( int argc, char *argv[] )
if( ! (a || b) )
_pause(3);
}
cleanup(0);
}

0 comments on commit 60db44d

Please sign in to comment.