jingfei li(deleted)
|
HAM doesn't work on daemon process based on RM
|
jingfei li(deleted)
10/13/2017 1:00 AM
post118100
|
HAM doesn't work on daemon process based on RM
Version: QNX7.0
I'd like to monitor a daemon process based on RM, it needs have capability to restart itself once terminate.
Unfortunatel, I found it random failed to restart, whereas a simple process could retart every time.
I'm not sure whether HAM support this kind of process, and I'm appreciate if you could help check my codes.
Remove debug info and error check, source code are attached also.
ham service:
-----------------
ham_connect(0);
ehdl = ham_attach(p_info->name, 0, p_info->pid, bin_path, 0);
chdl_death = ham_condition(ehdl, CONDDEATH, "death", HREARMAFTERRESTART|HCONDINDEPENDENT);
ahdl = ham_action_restart(chdl_death, "restart", bin_path, HREARMAFTERRESTART);
ham_disconnect(0);
Process to be monitored:
---------------------------------
const char* service_name = "/dev/test_ham";
int start_resmgr()
{
resmgr_connect_funcs_t connect_funcs;
resmgr_attr_t resmgr_attr;
resmgr_io_funcs_t io_funcs;
dispatch_t *dpp;
dispatch_context_t *ctp;
iofunc_attr_t attr;
iofunc_funcs_t ocb_funcs = { _IOFUNC_NFUNCS, NULL, NULL };
iofunc_mount_t mount = { 0, 0, 0, 0, &ocb_funcs };
if((dpp = dispatch_create()) == NULL) {
printf("unable to allocate dispatch handle\n");
return EXIT_FAILURE;
}
memset(&resmgr_attr, 0, sizeof resmgr_attr);
resmgr_attr.nparts_max = 1;
resmgr_attr.msg_max_size = 2048;
iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs,
_RESMGR_IO_NFUNCS, &io_funcs);
iofunc_attr_init (&attr, S_IFCHR | 0660, NULL, NULL);
attr.mount = &mount;
if(resmgr_attach(dpp, &resmgr_attr, service_name, _FTYPE_ANY, 0,
&connect_funcs, &io_funcs, (RESMGR_HANDLE_T *)&attr) == -1) {
printf("resmgr_attach failed\n");
return EXIT_FAILURE;
}
ctp = dispatch_context_alloc(dpp);
if(ctp == NULL)
{
printf("dispatch_context_alloc failed\n");
return EXIT_FAILURE;
}
while(1) {
if((ctp = dispatch_block(ctp)) == NULL) {
printf("dispatch_block error\n");
return EXIT_FAILURE;
}
dispatch_handler(ctp);
}
}
int main (int argc, char *argv[])
{
printf("process running...\n");
procmgr_daemon(EOK, PROCMGR_DAEMON_KEEPUMASK);
start_resmgr(); //random failed to restart
//while(1); //always success
return 0;
}
Test result:
--------------
******** process based on RM ********
# ./var/test_ham
process running...
#
# pidin -p test_ham thread
pid tid name thread name STATE Blocked
679968 1 ./var/test_ham 1 RECEIVE 1
#
# ham_service test 679968
ham: entity-test pid-679968 path-/./var/test_ham
49.085000000s: Ham: Attach Other Entity Request: test
49.085000000s: Ham: Attached Other Entity: test
49.086000000s: Ham: Condition Add Request: test/death
49.086000000s: Ham: Condition Added: test/death
49.086000000s: Ham: Action Restart Add Request: test/death/restart
49.087000000s: Ham: Action Restart Added: test/death/restart
#
# slay test_ham
# 54.040000000s: Ham: Entity "test" with pid: 679968 died
54.043000000s: Ham: Restarted: /./var/test_ham
process running...
# slay test_ham
# 62.376000000s: Ham: Entity "test" with pid: 811040 died
62.377000000s: Ham: Restart Failed: /./var/test_ham
62.378000000s: Ham: Deleting test
# slay test_ham
slay: Unable to find process 'test_ham'
******** process using while loop ********
# ./var/test_ham
process running...
#
# pidin -p test_ham thread
pid tid name thread name STATE Blocked
835616 1 ./var/test_ham 1 RUNNING
#
# ham_service test 835616
ham: entity-test pid-835616...
View Full Message
|
|
|