[DGD] 1.2.30

Par Winzell zell at skotos.net
Sun Sep 9 05:04:39 CEST 2001


 >  > I see a definite need for a wrapper around this to avoid name clashes
 >  > for throw-away objects, but that's easy enough to do. :-)
 > 
 > They don't necessarily ned to be throw-away objects. I think there are
 > conditions where we don't need filename restrictions. For example, the
 > system-level auto object could actually -write- the source in a zero-
 > second callout after the compile: then all upgrade tools would work as
 > usual.

In case somebody wants to save a few moments of thought when catching
their library up with DGD 1.1.30 --

I now mask compile_object() in the System-level auto object and catch
attempts to compile with a source parameter:

----------------------------------------------------------------------
static
object compile_object(string name, varargs string source) {
   string creator, oname;
   object obj;

   if (source) {
      oname = ::object_name(this_object());
----------------------------------------------------------------------

Since compile_object() itself checks for write permission, I simply
normalize the path and make sure the directory exists:

----------------------------------------------------------------------
      oname = ::object_name(this_object());
      creator = DRIVER->creator(oname);
      name = DRIVER->normalize_path(name, oname + "/..", creator);

      /* the directory must exist */
      if (!file_info(name + "/..")) {
	 error("bad object name");
      }

      obj = ::compile_object(name, source);
----------------------------------------------------------------------

We then proceed with the compilation and, if successful, let a daemon
object know about it (since we might be destructed in this very same
thread):

----------------------------------------------------------------------
      obj = ::compile_object(name, source);
      PROGDB->write_source(name, source);
      return obj;
----------------------------------------------------------------------

The daemon cancels any outstanding requests for precisely the same
operation and (re)schedules --

----------------------------------------------------------------------
mapping handles;

atomic
void write_source(string name, string source) {
   if (previous_program() == SYS_AUTO) {
      if (handles[name]) {
	 remove_call_out(handles[name]);
      }
      handles[name] = call_out("do_write_source", 0, name, source);
   }
}
----------------------------------------------------------------------

and then do the write:

----------------------------------------------------------------------
static
void do_write_source(string name, string source) {
   rlimits(0; -1) {
      handles[name] = nil;

      write_file(name + ".tmp", source);
      remove_file(name + ".c");
      rename_file(name + ".tmp", name + ".c");
   }
}
----------------------------------------------------------------------

and we're done! With this trivial system in place, on top of the
kernel library, upgrading works precisely as before, there's LPC
files for all compiled objects (so e.g. precompiling can proceed
as before), and (hopefully) no security has been compromised.

Zell
_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list