Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Remember single value across restarts?

2 views
Skip to first unread message

jerry...@gmail.com

unread,
Apr 26, 2006, 9:09:27 AM4/26/06
to
Hi,
I have a tcl daemon that watches interupts and puts my laptop to
sleep after a suitable period of inactivity.

I have a "client" that talks to the daemon via a socket and
can adjust the "maxidletime".

I would like to be able to "remember" the maxidletime so that
when the daemon restarts it will use the last maxidletime.

Is there a way to do this *without* a "rc" file or getting into
tclkits?

I guess it might come down to the question of can persistence
data be stored within the daemon...

Thanks

Jerry

suchenwi

unread,
Apr 26, 2006, 9:44:43 AM4/26/06
to
It's possible what you want, by writing self-modifying code of the
second degree :-)
When a script is sourced, its name is available from [info script].
When it runs (after it has been sourced), and is not write-protected,
there's nothing to stop it from reading itself, changing the lines
setting the variables you want, and write it back under the same name.

suchenwi

unread,
Apr 26, 2006, 10:22:13 AM4/26/06
to
As I had some waiting time, I hacked up an example implementation:

"Self-rewriting code", http://wiki.tcl.tk/15837

Andreas Leitgeb

unread,
Apr 26, 2006, 11:32:30 AM4/26/06
to
suchenwi <richard.suchenw...@siemens.com> wrote:
> As I had some waiting time, I hacked up an example implementation:
> "Self-rewriting code", http://wiki.tcl.tk/15837

The caveats for such an approach obviously have been added
to the site as well.

To the thread-originator:
Why not simply write the variables to some extra file like:
/etc/mydaemon.conf (I remember you also wrote about avoiding
"rc"-stuff, but *why*?)

jerry...@gmail.com

unread,
Apr 26, 2006, 1:03:13 PM4/26/06
to
Some care needs to be used since the "client" program can direct the
server to "set" a new value, I don't want to clobber the wrong set
statement.

Seems like something like Perls __DATA__ construct might
be useful....

Jerry

Donal K. Fellows

unread,
Apr 26, 2006, 5:46:39 PM4/26/06
to
jerry...@gmail.com wrote:
> Seems like something like Perls __DATA__ construct might
> be useful....

That produces a writable filehandle? I didn't think Perl was *that*
brain-dead...

Donal.

Adrian Ho

unread,
Apr 26, 2006, 10:41:27 PM4/26/06
to
On 2006-04-26, jerry...@gmail.com <jerry...@gmail.com> wrote:
> Some care needs to be used since the "client" program can direct the
> server to "set" a new value, I don't want to clobber the wrong set
> statement.

See <http://wiki.tcl.tk/15837> again. I've modified Richard's code (as
"lexfiend") to address this concern.

- Adrian

jerry...@gmail.com

unread,
Apr 27, 2006, 1:27:31 PM4/27/06
to
I adopted an intermediate stance between Richards and Adrians
solutions.

I marked the special variables like so:

set maxIdleTime 1200 ;# volatile

and modified Richards solution to look for the
volatile string.

Details at : http://wiki.tcl.tk/15837

Thanks for the suggestions ( and I agree that it
is a technique to be used sparingly ;)

Jerry

0 new messages