<br><br>Is it possible for me to spin off my own thread to do background work separate from individual requests in a module? I am trying to start a thread from the instantiate call and then rejoin on the detach, this seems to work when I run radius -X, but something is happening when radius is not in debug so that it gets stuck or killed somehow, the log statement is only logged once.<br>
<br>All I have is a while loop with a log and sleep statement in it as shown below. It is not getting stuck in the log call as even without that, sending a sigterm to the process still hangs.<br><br><br><br><br><br><br><br>
<br><br>#include <freeradius/ident.h><br>RCSID("$Id$")<br><br>#include <stdio.h><br>#include <stdlib.h><br>#include <unistd.h><br>#include <pthread.h><br><br><br>#include <freeradius-devel/radiusd.h><br>
#include <freeradius-devel/modules.h><br><br><br><br><br><br><br><br><br>typedef struct rlm_gwis_t {<br> int shutdown;<br> pthread_t p_thread;<br>} gw_config;<br><br><br><br><br><br><br><br>const CONF_PARSER module_config[] = {<br>
{ NULL, -1, 0, NULL, NULL } /* end the list */<br>};<br><br><br><br><br><br><br><br><br><br><br>void *gwis__background__start(void *data) {<br> gw_config *gwd = data;<br><br> if(!gwd)<br> return NULL;<br>
<br> while(!gwd->shutdown) {<br> radlog(L_ERR, "Background process, shutdown %d", gwd->shutdown);<br> sleep(1);<br> }<br><br> return NULL;<br>}<br><br><br><br><br><br><br><br>static int gwis_detach(void *gwd) {<br>
<br> if(gwd) {<br> ((gw_config *)gwd)->shutdown = 1;<br><br> pthread_join(((gw_config *)gwd)->p_thread, NULL);<br> free(gwd);<br> }<br><br> return RLM_MODULE_OK;<br>}<br><br><br><br><br><br><br><br><br><br>
static int gwis_instantiate(CONF_SECTION *conf, void **gwd) {<br> gw_config *tmp_gwd;<br><br> tmp_gwd = rad_malloc(sizeof(gw_config));<br> if(!tmp_gwd) {<br> return RLM_MODULE_FAIL;<br> }<br> memset(tmp_gwd, 0, sizeof(gw_config));<br>
<br> if(cf_section_parse(conf, tmp_gwd, module_config) < 0) {<br> free(tmp_gwd);<br> return RLM_MODULE_FAIL;<br> }<br><br> tmp_gwd->shutdown = 0;<br> if(pthread_create(&tmp_gwd->p_thread, NULL, gwis__background__start, tmp_gwd)) {<br>
gwis_detach(tmp_gwd);<br> return -1;<br> }<br><br> *gwd = tmp_gwd;<br><br> return RLM_MODULE_OK;<br>}<br><br><br><br><br><br><br><br><br>static int gwis_preacct(void *gwd, REQUEST *request) {<br> return RLM_MODULE_OK;<br>
}<br><br><br><br><br><br><br><br>module_t rlm_gwis = {<br> RLM_MODULE_INIT,<br> "gwis",<br> RLM_TYPE_THREAD_SAFE,<br> gwis_instantiate,<br> gwis_detach,<br> {<br> NULL,<br> NULL,<br> gwis_preacct,<br>
NULL,<br> NULL,<br> NULL,<br> NULL,<br> NULL<br> },<br>};<br><br><br><br><br><br><br><br><br>