monit-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: configuration patch - final version


From: Martin Pala
Subject: Re: configuration patch - final version
Date: Tue, 11 Feb 2003 23:23:27 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021226 Debian/1.2.1-9

Jan-Henrik Haukeland wrote:

Elaborations (I'm on windows right now, and cannot try, this is more thinking
aloud)


Write:

 1) first write the timestamp:

 time_t now;

 fwrite(time(&now), 1, sizeof (time_t), binaryfile);

 2) Then the length of the process list

    int length= get_process_list_length();

 fwrite(length, 1, sizeof (int), binaryfile);

 2) Then the list:

 for(p= processlist; p; p= p->next)
        fwrite(p, 1, sizeof *(p), binaryfile);


Read:

1) Get state file timestamp

  time_t stamp;

  fread(now, 1, sizeof (time_t), binaryfile);

2) Get length

  int length;
  fread(length, 1, sizeof (int), binaryfile);

Process_T new;
Process_T temp= NEW(temp);

for(i=0; i<length; i++) {

if(fread(temp, 1, sizeof *(temp), binaryfile) != sizeof *(temp))
  error_exit;
}
if((new= get_process(temp->name))
  copy temp.do_validate to new.do_validate;
}


Simple and effective (if it works that is :)


Jan-Henrik


Sounds good. The BER rules uses the same princip - it defines tag for each data type + length + data part length. There's also support for structures, etc. (primitive and constructed types, support for user-defined data type classes), is possible to validate the stored data in the parser as well. Problem is, that it is little bit more complicated. We can use some parser that is ready for use (for example OpenLDAP is distributed with libber, but i don't like that parser - when i went through this code i found few "not-very-nice" chunks of code).






reply via email to

[Prev in Thread] Current Thread [Next in Thread]