Opening the lease file in append mode in db.c?

Ned W. Rhodes (E-mail) dhcp at softsysgrp.com
Thu Jun 20 22:01:25 UTC 2002



By way of background, I am porting the dhcp server code to an embedded
system which uses flash for permanent storage. In server/db.c (1.63.2.4
2001/06/22) the following code appears to open the leases file in append
mode. It is unclear to me why the file is opened in append mode when there
is a call to new_lease_file at the end of the scope which closes the file
and then writes it anew.

My problem is that the current file system on my embedded system does not
support append mode and so I can either implement it or figure out why the
file is even opened in append mode. I don't believe that the routine
expire_all_pools writes to the lease file and if I look further in the code,
there is a rename operation that calls the failure path if the leases file
cannot be renamed. So, can I assume that the whole point of the open with
append is there to make sure that there is a leases file that can be
renamed?

      if (!testp) {
            db_file = fopen (path_dhcpd_db, "a");
            if (!db_file)
                  log_fatal ("Can't open %s for append.", path_dhcpd_db);
            expire_all_pools ();
#if defined (TRACING)
            if (trace_playback ())
                  write_time = cur_time;
            else
#endif
                  GET_TIME (&write_time);
            new_lease_file ();
      }

The fix for me was to remove the call to fopen entirely and change the
rename code so that it did not fatal error if the file to be renamed was not
there.



More information about the dhcp-hackers mailing list