This is cool. But it has been posted before.
Can you post the RTP source to shutdown? That would be more usefull to me
now.
–
Bill Caroselli – 1(530) 510-7292
Q-TPS Consulting
QTPS@EarthLink.net
“Hardware Support Account” <> hw@qnx.com> > wrote in message
news:a1mrol$70h$> 2@nntp.qnx.com> …
Source to shutdown (its been posted before):
/*
Copyright 2001, QNX Software Systems Ltd. All Rights Reserved
This source code has been published by QNX Software Systems Ltd. (QSSL).
However, any use, reproduction, modification, distribution or transfer of
this software, or any software which includes or is based upon any of this
code, is only permitted under the terms of the QNX Community License
version
1.0 (see licensing.qnx.com for details) or as otherwise expressly
authorized
by a written license agreement from QSSL. For more information, please
email
licensing@qnx.com> .
*/
#ifdef __USAGE
%C - shut down and reboot the system (QNX)
%C [-f] [-n node]
Options:
-f Shutdown fast. Reboot after only 1 second.
-n Node number to reboot. Default is current node.
-b Shut down but do not reboot. May not be used with -n node.
#endif
#include <stdio.h
#include <signal.h
#include <stdlib.h
#include <unistd.h
#include <string.h
#include <stdarg.h
#include <sys/types.h
#include <sys/kernel.h
#include <sys/proc_msg.h
#include <sys/dev.h
#include <sys/vc.h
#include <sys/sched.h
#include <util/stdutil.h
#if 1
#include <sys/psinfo.h
#include <sys/seginfo.h
#include <sys/name.h
int slay_fsys = 1;
#endif
main(argc, argv)
int argc;
char *argv[];
{
int count = 10, opt;
nid_t node = 0;
pid_t vid = PROC_PID;
sigset_t bits;
int noreboot = 0;
char buf[8];
int count2 = 60;
union {
struct _proc_shutdown s;
struct _proc_shutdown_reply r;
} msg;
while ((opt = getopt(argc, argv, “fbn:”)) != -1) {
switch(opt) {
case ‘b’: noreboot = 1; break;
case ‘f’: count = 1; break;
case ‘n’:
node = strtonid(optarg,NULL);
if (node==-1 || node == 0) {
fprintf(stderr,“Invalid node specified (-n
%s).\n”,optarg);
exit(EXIT_FAILURE);
}
break;
default: exit(EXIT_FAILURE);
}
}
if(node)
if (noreboot) {
fprintf(stderr,“shutdown: -b and -n options may
not be used at the same time\n”);
exit(EXIT_FAILURE);
}
if((vid = qnx_vc_attach(node, PROC_PID, 100, 0)) == -1) {
fprintf(stderr, “Unable to connect to node %s
(%s).\n”,nidtostr(node,NULL,0),strerror(errno));
exit(EXIT_FAILURE);
}
bits = ~0L;
sigprocmask(SIG_BLOCK, &bits, 0);
if(vid == PROC_PID)
putchar(’\f’);
else
printf(“Please wait while remote node %s
reboots…\n”,nidtostr(node,NULL,0));
fflush(stdout);
display_msg(vid, “\n\n\n”); /* Move it down a few lines */
msg.s.type = _PROC_SHUTDOWN;
msg.s.signum = SIGPWR;
errno = 0;
Send(vid, &msg.s, &msg.r, sizeof(msg.s), sizeof(msg.r));
if(errno || (errno = msg.r.status)) {
perror(“Unable to shutdown”);
exit(EXIT_FAILURE);
}
if (!noreboot) {
display_msg(vid, “\fStand by while system reboots\n”);
}
else {
display_msg(vid, “\fStand by while system shuts down\n”);
}
sleep(1);
while(count >= 0) {
sprintf(buf, “%2d \r”, count–);
display_msg(vid, buf);
sleep(1);
}
#if 1
if(slay_fsys) {
pid_t pid;
pid = qnx_name_locate( node, “qnx/fsys32”, 1024, NULL );
if(pid != -1) {
struct _psinfo psdata;
display_msg(vid, “\fStand by while filesystem
shuts down\n”);
kill( pid, SIGTERM );
if(node == 0) {
while( qnx_psinfo( 0, pid, &psdata, 0, 0 )
== 0 && psdata.pid == pid ) {
sprintf(buf, “%2d \r”, count2);
display_msg(vid, buf);
sleep(1);
if(count2-- <= 0)
break;
}
}
}
}
#endif
if (!noreboot) {
msg.s.type = _PROC_SHUTDOWN;
msg.s.signum = -1;
Send(vid, &msg.s, &msg.r, sizeof(msg.s), sizeof(msg.r));
/* This should NOT return */
}
else {
struct sched_param param;
display_msg(vid, “\fshutdown: System may now be powered
down.\n”);
#if 1
if(slay_fsys) {
/*
- Return back to caller
/
exit(EXIT_SUCCESS);
}
#endif
/ set priority way high */
param.sched_priority = PRIO_FIFO_MAX;
sched_setscheduler(0,SCHED_FIFO,¶m);
/* spin */
for(;;);
}
}
void display_msg(vid, text)
pid_t vid;
char *text;
{
union {
struct _proc_display s;
struct _proc_display_reply r;
} msg;
msg.s.subtype = 0;
strcpy(msg.s.text, text);
msg.s.type = _PROC_DISPLAY;
Send(vid, &msg.s, &msg.r, sizeof(msg.s), sizeof(msg.r));
}
This should give you an idea on how to do this and help you with your
code.
Erick.
Jay Hogg <> Jay.Hogg@t-netix.com.r-e-m-o-v-e> > wrote:
exec(), system(), spawn() all suffer from the same potential downfall…
If I’m having to issue a shutdown via SNMP chances are I can’t get on
the
system anyway. Could be memory, process, or any of a number of things
so I consider the only valid way is sending the message to Proc32.
Other things to consider as long as you do it “safe” so you don’t get
blocked indefinately is sending SIGPWR yourself, delaying, then
unmounting
file
systems to make sure it is “clean” - I don’t think Proc32 will make sure
everything
is clean.
Jay
“Adam Mallory” <> amallory@qnx.com> > wrote in message
news:a1hrta$hvt$> 1@nntp.qnx.com> …
You could also exec()
–
Cheers,
Adam
QNX Software Systems Ltd.
[ > amallory@qnx.com > ]
With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <> pschon@baste.magibox.net
“Hardware Support Account” <> hw@qnx.com> > wrote in message
news:a1fmnp$18f$> 1@nntp.qnx.com> …
Ok, I was a tad off with that (David came down and slapped me),
actually you send a message to Proc32 containing:
union {
struct _proc_shutdown s;
struct _proc_shutdown_reply r;
} msg;
msg.s.type = _PROC_SHUTDOWN;
msg.s.signum = SIGPWR;
The SIGPWR is the signal that Proc32 sends to the processes on the
system alerting them that the power is about to go off.
I admit that there are other ways of doing this, so I am a bit guilty
of inflicting my opinion on this issue as I don’t like the other ways
Other ways:
Use the system() function call to call the shutdown command.
Use spawn to launch the shutdown command.
Either way will work just as well, I just don’t think they are as
clean
IMHO.
Erick.
Hardware Support Account <> hw@qnx.com> > wrote:
You could send a SIGPWR? (Gibbs is going to slap me for not
remebering
what the exact SIGnal is) to Proc32, if I remember correctly…
ahh
hold
on let me look at the code…
Time passes
HAHA! I was right, SIGPWR!
Just send the SIGPWR to Proc and Proc takes care of the rest.
E.
.
Chris Minerva <> chrism@vectrad.com> > wrote:
Does anyone know if it is possible to issue a shutdown command to
QNX
4.25
from within a process?
Under certain circumstances, we want our SNMP agent to be able to
cleanly
shutdown and restart QNX independent of our application.
Any help in this area would be appreciated.
-Chris M
\