Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Message-Id: <4.3.1.2.20010227131655.015fd3c8@pop.ma.ultranet.com> X-Sender: lhall AT pop DOT ma DOT ultranet DOT com X-Mailer: QUALCOMM Windows Eudora Version 4.3.1 Date: Tue, 27 Feb 2001 13:24:26 -0500 To: "Alex Tang" , cygwin AT sources DOT redhat DOT com From: "Larry Hall (RFK Partners, Inc)" Subject: Re: dhcpd? In-Reply-To: <3A9BE672.567EA62@airflash.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" At 12:40 PM 2/27/2001, Alex Tang wrote: >Hi folks. > >I was wondering, has anyone tried porting the ISC dchpd (version 2) to >cygwin? > >If someone has this working, please let me know and ignore the rest of >this message. :-) > >I retrieved the dhcpd source from their CVS server (cvs co -r RELEASE_2 >DHCP from their server), and made some minor modifications to it to >remove the winsock stuff and make it use "normal" networking code. The >compilation works fine (diffs are included below), however when the app >is trying to do a rename(), it ALWSAYS gets a "permission denied". > >I am using the cygwin 1.1.8 DLL. > >The code chunk is included below: > > void new_lease_file () > { > char newfname [512]; > char backfname [512]; > TIME t; > int db_fd; > > /* If we already have an open database, close it. */ > if (db_file) { > fclose (db_file); > } > > /* Make a temporary lease file... */ > GET_TIME (&t); > sprintf (newfname, "%s.%d", path_dhcpd_db, (int)t); > db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT, 0664); > if (db_fd < 0) { > error ("Can't create new lease file: %m"); > } > if ((db_file = fdopen (db_fd, "w")) == NULL) { > error ("Can't fdopen new lease file!"); > } > > /* Write an introduction so people don't complain about time > being off. */ > fprintf (db_file, "# All times in this file are in UTC (GMT), not %s", > "your local timezone. This is\n"); > fprintf (db_file, "# not a bug, so please don't ask about it. %s", > "There is no portable way to\n"); > fprintf (db_file, "# store leases in the local timezone, so please %s", > "don't request this as a\n"); > fprintf (db_file, "# feature. If this is inconvenient or %s", > "confusing to you, we sincerely\n"); > fprintf (db_file, "# apologize. Seriously, though - don't ask.\n"); > fprintf (db_file, "# The format of this file is documented in the %s", > "dhcpd.leases(5) manual page.\n\n"); > > /* Write out all the leases that we know of... */ > counting = 0; > write_leases (); > > /* Get the old database out of the way... */ > sprintf (backfname, "%s~", path_dhcpd_db); > if (unlink (backfname) < 0 && errno != ENOENT) > error ("Can't remove old lease database backup %s: %m", > backfname); > if (link (path_dhcpd_db, backfname) < 0) > error ("Can't backup lease database %s to %s: %m", > path_dhcpd_db, backfname); > > /* Move in the new file... */ > if (rename (newfname, path_dhcpd_db) < 0) > error ("Can't install new lease database %s to %s: %m", > newfname, path_dhcpd_db); > > counting = 1; > } > >The last block (after "Move in the new file") always returns a -1 and >the errno is EACCES. > >If i try to manually move the files from the shell, it works fine. The >permissions on all of the directories look fine (all directories are >owned by me, and I'm running the dhcpd as me.) > >This is probably something butt-stupid that I'm doing. however I can't >see it. > >Does anyone have any insights? Looks to me like newfname is open (db_fd). Windows won't let you rename an open file in general. Larry Hall lhall AT rfk DOT com RFK Partners, Inc. http://www.rfk.com 118 Washington Street (508) 893-9779 - RFK Office Holliston, MA 01746 (508) 893-9889 - FAX -- Want to unsubscribe from this list? Check out: http://cygwin.com/ml/#unsubscribe-simple