At_exit for http daemon

Dear experts,

I have a webserver that is basically copied from joeblog’s https://github.com/roblaing/swipl-webapp-howto. On startup, a few computationally expensive things are prepared and stored in temporary files (tmp_file_stream & Co). I noticed that these temporary files are immediately deleted after the webserver changes to daemon mode, you know, :- use_module(library(http/http_unix_daemon)). And then everything is lost.

I thought I would be smarter than swipl by deleting and recreating the tempfiles and deleting them myself in a hook from at_exit, but this hook also seems to be invoked when the server switches to deamon mode. Is this behavior intended? Or might it make sense to have something like the broadcast events http(pre_server_start) and http(post_server_start) - not for the start but for the end of the server (i.e., when I kill it)?

My current workaround is to save the files in the local folder.

Best wishes,

Matthias

If you deamonize, the process forks and apparently (and logically) the dying parent calls its process exit handlers. Using one of the hooks that runs in the child is probably the way to go. My typical design pattern is to use lazy creation of such resources, i.e., just have a test they are there, else create them. You do need to use a mutex to avoid a race in that case though.

All right, I’ll see if I find the hooks that run in the child and then connect to them.

Best wishes,

Matthias