David,
I’ve implemented your suggestion and it does reboot the system. Only one thing bothers me, and that’s a message from Dev32 saying
it’s had a SIGSEGV at: 006d:00017d2
I’d like to know if I need to sync() the filesystem myself or does Fsys do that for me? Also, how long do I need to wait at each
stage?
Any help would be greatly appreciated.
Here’s my code:
void
reboot_system(void)
{
int countdown = 5;
sigset_t bits;
union _shutdown_msg_tag
{
struct _proc_shutdown s;
struct _proc_shutdown_reply r;
} msg;
pid_t pid;
syslog(LOG_CRIT, “rebooting system”);
sync();
sleep(5);
/* block all signals */
bits = ~0L;
sigprocmask(SIG_BLOCK, &bits, 0);
/* tell Proc to send a shutdown (SIGPWR) signal to everyone */
msg.s.type = _PROC_SHUTDOWN;
msg.s.signum = SIGPWR;
Send(PROC_PID, &msg.s, &msg.r, sizeof(msg.s), sizeof(msg.r));
/* wait for things to shutdown */
sleep(4);
/* send SIGTERM to Fsys, waiting for it to die */
while (–countdown)
{
pid = qnx_name_locate( 0, “qnx/fsys32”, 1024, NULL );
if (pid == -1) break;
kill( pid, SIGTERM );
sleep(1);
}
/* shutdown the system */
msg.s.type = _PROC_SHUTDOWN;
msg.s.signum = -1;
Send(PROC_PID, &msg.s, &msg.r, sizeof(msg.s), sizeof(msg.r));
}
David Gibbs wrote:
Jim Parnell <> jparnell@wgate.com> > wrote:
Hello,
I am developing a watchdog program in ‘C’ under QNX4.25 for a
mission-critical application. In order to survive a memory leak, the
program must be able to perform a system shutdown without using ‘exec’ or
‘system’ calls that invoke a shell. (shell invocations fail due to
insufficient memory)
I’ve tried to find approaches in the documentation with no luck. I also
tried (naively) sending a _PROC_SHUTDOWN message to Proc32. This, as it
turns out, is an excellent way to lock up the system, if you’re so
inclined.
If anyone knows the secret handshake, won’t you please let me know?
Sending _PROC_SHUTDOWN to Proc32 is the proper way to shutdown – but
you have to build the message properly.
Basic code is:
/* block all signals */
bits = ~0L;
sigprocmask(SIG_BLOCK, &bits, 0);
/* tell Proc to send a shutdown (SIGPWR) signal to everyone */
msg.s.type = _PROC_SHUTDOWN;
msg.s.signum = SIGPWR;
Send(PROC_PID, &msg.s, &msg.r, sizeof(msg.s), sizeof(msg.r));
/* wait for things to shutdown */
sleep(whatever);
/* send SIGTERM to Fsys /
pid = qnx_name_locate( node, “qnx/fsys32”, 1024, NULL );
kill( pid, SIGTERM );
/ if you want, wait for Fsys to shut down /
/ either loop checking to see if it is still there, or sleep() */
/* shutdown the system */
msg.s.type = _PROC_SHUTDOWN;
msg.s.signum = -1;
Send(PROC_PID, &msg.s, &msg.r, sizeof(msg.s), sizeof(msg.r));
Oh ya, you need to be root to do this. > 
-David