Skip to content

Commit

Permalink
Unbreak genid implementation
Browse files Browse the repository at this point in the history
Only worked first time.  If the file already existed the function always
saved the value 0 to mrouted.genid.

Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Sep 29, 2020
1 parent 7dd615a commit d3e9e66
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,33 @@ static FILE *fopen_genid(char *mode)
return fopen(fn, mode);
}

static void init_gendid(void)
static uint32_t rand_genid(void)
{
FILE *fp;

fp = fopen_genid("r");
if (!fp) {
struct timespec tv;

clock_gettime(CLOCK_MONOTONIC, &tv);
dvmrp_genid = (uint32_t)tv.tv_sec; /* for a while after 2038 */
} else {

return (uint32_t)tv.tv_sec; /* for a while after 2038 */
}

static void init_genid(void)
{
FILE *fp;

fp = fopen_genid("r");
if (fp) {
uint32_t prev_genid;
int ret;

ret = fscanf(fp, "%u", &prev_genid);
(void)fclose(fp);

if (ret == 1 && prev_genid == dvmrp_genid)
dvmrp_genid++;
(void)fclose(fp);
}
else
dvmrp_genid = rand_genid();
} else
dvmrp_genid = rand_genid();

fp = fopen_genid("w");
if (fp) {
Expand Down Expand Up @@ -255,7 +263,7 @@ int main(int argc, char *argv[])
/*
* Get generation id
*/
init_gendid();
init_genid();

timer_init();
igmp_init();
Expand Down Expand Up @@ -676,7 +684,7 @@ void restart(void)
/*
* start processing again
*/
init_gendid();
init_genid();

igmp_init();
init_routes();
Expand Down

0 comments on commit d3e9e66

Please sign in to comment.