Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[udhcpd-migration] Fix issue with link replacement
The code worked fine if there was no previous link or
the link was dead, however it did not catch the other cases.
Now it should correctly remove the link when it is not the right one.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Mar 12, 2015
1 parent 347db49 commit e41a719
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/usb_moded-network.c
Expand Up @@ -299,16 +299,18 @@ static int resolv_conf_dns(struct ipforward_data *ipforward)

static int checklink(void)
{
char *dest = NULL;
char *dest = malloc( 32 * sizeof(char)) ;
int ret = 0;

readlink("/etc/udhcpd.conf", dest, 32);
if(dest != NULL)
{
strcpy(&dest[31], "\0");
return(strcmp(dest, "UDHCP_CONFIG_PATH"));
ret = (strcmp(dest, UDHCP_CONFIG_PATH));
}
else
return 0;
free(dest);

return(ret);
}

/**
Expand All @@ -323,7 +325,7 @@ static int write_udhcpd_conf(struct ipforward_data *ipforward, struct mode_list_
int dot = 0, i = 0, test;
struct stat st;

/* /tmp and /var is often tmpfs, so we avoid writing to flash */
/* /tmp and /run is often tmpfs, so we avoid writing to flash */
mkdir(UDHCP_CONFIG_DIR, 0664);
conffile = fopen("UDHCP_CONFIG_PATH", "w");
if(conffile == NULL)
Expand Down Expand Up @@ -390,7 +392,7 @@ static int write_udhcpd_conf(struct ipforward_data *ipforward, struct mode_list_
if(test == -1)
goto link;
/* if it is not a link, or points to the wrong place we remove it */
if(((st.st_mode & S_IFMT) != S_IFLNK) || !checklink())
if(((st.st_mode & S_IFMT) != S_IFLNK) || checklink())
{
unlink("/etc/udhcpd.conf");
}
Expand Down

0 comments on commit e41a719

Please sign in to comment.