Skip to content

Commit

Permalink
[usb-moded] Put udhcpd conf file in /var Fixes:JB#25911
Browse files Browse the repository at this point in the history
Since files in /tmp can sometimes get cleaned up it is safer to put
the temporary config in /var/run/usb-moded/

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Mar 9, 2015
1 parent d036f86 commit 78d37ad
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/usb_moded-network.c
Expand Up @@ -294,6 +294,20 @@ static int resolv_conf_dns(struct ipforward_data *ipforward)
}
#endif

static int checklink(void)
{
char *dest = NULL;
readlink("/etc/udhcpd.conf", dest, 32);
if(dest != NULL)
{
strcpy(&dest[31], "\0");
return(strcmp(dest, "/var/run/usb-moded/udhcpd.conf"));
}
else
return 0;

}

/**
* Write udhcpd.conf
* @ipforward : NULL if we want a simple config, otherwise include dns info etc...
Expand All @@ -306,8 +320,9 @@ static int write_udhcpd_conf(struct ipforward_data *ipforward, struct mode_list_
int dot = 0, i = 0, test;
struct stat st;

/* /tmp is often tmpfs, so we avoid writing to flash */
conffile = fopen("/tmp/udhcpd.conf", "w");
/* /tmp and /var is often tmpfs, so we avoid writing to flash */
mkdir("/var/run/usb-moded", 0664);
conffile = fopen("/var/run/usb-moded/udhcpd.conf", "w");
if(conffile == NULL)
{
log_debug("Error creating /etc/udhcpd.conf!\n");
Expand Down Expand Up @@ -371,16 +386,16 @@ static int write_udhcpd_conf(struct ipforward_data *ipforward, struct mode_list_
/* if stat fails there is no file or link */
if(test == -1)
goto link;
/* if it is not a link we remove it, else we expect the right link to be there */
if((st.st_mode & S_IFMT) != S_IFLNK)
/* if it is not a link, or points to the wrong place we remove it */
if(((st.st_mode & S_IFMT) != S_IFLNK) || !checklink())
{
unlink("/etc/udhcpd.conf");
}
else
goto end;

link:
symlink("/tmp/udhcpd.conf", "/etc/udhcpd.conf");
symlink("/var/run/usb-moded/udhcpd.conf", "/etc/udhcpd.conf");

end:

Expand Down

0 comments on commit 78d37ad

Please sign in to comment.