Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Write udhcp config to /tmp (which is tmpfs) and link to /etc/ to avoi…
…d spurious writes to flash

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Mar 5, 2014
1 parent 3dab6a4 commit def9622
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/usb_moded-network.c
Expand Up @@ -29,6 +29,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <sys/stat.h>
#include <sys/types.h>

#include <glib.h>

Expand Down Expand Up @@ -255,9 +259,11 @@ static int write_udhcpd_conf(struct ipforward_data *ipforward, struct mode_list_
FILE *conffile;
const char *ip, *interface;
char *ipstart, *ipend;
int dot = 0, i = 0;
int dot = 0, i = 0, test;
struct stat st;

conffile = fopen("/etc/udhcpd.conf", "w");
/* /tmp is often tmpfs, so we avoid writing to flash */
conffile = fopen("/tmp/udhcpd.conf", "w");
if(conffile == NULL)
{
log_debug("Error creating /etc/udhcpd.conf!\n");
Expand Down Expand Up @@ -315,6 +321,25 @@ static int write_udhcpd_conf(struct ipforward_data *ipforward, struct mode_list_
free((char*)interface);
fclose(conffile);
log_debug("/etc/udhcpd.conf written.\n");

/* check if it is a symlink, if not remove and link, create the link if missing */
test = stat("/etc/udhcpd.conf", &st);
/* 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)
{
unlink("/etc/udhcpcd.conf");
}
else
goto end;

link:
symlink("/tmp/udhcpcd.conf", "/etc/udhcpcd.conf");

end:

return(0);
}

Expand Down

0 comments on commit def9622

Please sign in to comment.