Two tough questions

Two tough questions

Post by Michel » Wed, 16 Dec 1998 04:00:00



Hi there,

I have 2 easy( or at least I hope so) questions for you.

#1: I need to load two drivers and make a program run in batch mode at
boot time,say when everything is up and ready for login command.Where do
I put these instructions or what I have to do?

#2: I need,from a C program,to make Linux reboot when something weird is
happening.WHat call I need to do within the program?

Thanks in advance.

Michele

 
 
 

Two tough questions

Post by Simon Paradi » Wed, 16 Dec 1998 04:00:00



> Hi there,

> I have 2 easy( or at least I hope so) questions for you.

> #1: I need to load two drivers and make a program run in batch mode at
> boot time,say when everything is up and ready for login command.Where do
> I put these instructions or what I have to do?

Put your stuff in /etc/rc.d/rc.local (assuming you have Slackware, these
files
are probably different under other distributions)

Commands inside this file get executed last just before the system can
accept
logins. For exemple, in this file, I put a command which outputs the
time and date to /etc/motd. That way each time I login, I know when I
last
rebooted my system.

Quote:> #2: I need,from a C program,to make Linux reboot when something weird is
> happening.WHat call I need to do within the program?

system("reboot");

This is not elegant but it might work.

--

/-------------------------+-----------------------------------------\
|      Simon Paradis      |Try Net Timer Pro, an internet timer for |

|                         |     http://www.microtec.net/~ntpdev     |
\-------------------------+-----------------------------------------/

 
 
 

Two tough questions

Post by Peter Samuels » Wed, 16 Dec 1998 04:00:00



Quote:> I have 2 easy( or at least I hope so) questions for you.

Yup.

Quote:> #1: I need to load two drivers and make a program run in batch mode
> at boot time,say when everything is up and ready for login
> command.Where do I put these instructions or what I have to do?

Depends on your version of `init'.  Which probably depends on your
distribution of Linux.  In Debian (which uses sysvinit), for example,
just add the necessary script or a symbolic link to same to /etc/rc2.d/
or whichever runlevel you want this to happen in.  For more info read
up on `init'.

Quote:> #2: I need,from a C program,to make Linux reboot when something weird
> is happening.WHat call I need to do within the program?

You could call the reboot syscall directly but the cleanest way to do
this is probably through a watchdog timer.  Configure your kernel with
"softdog" support (in the "character devices" section) and read up on
it.  Basically this is a file in /dev which your program opens and
periodically writes to.  If it closes the file or doesn't write to it
for a certain amount of time, Linux will assume that something has hung
or otherwise gone wrong and will reboot.

--
Peter Samuelson
<sampo.creighton.edu!psamuels>

 
 
 

Two tough questions

Post by Juergen Hein » Wed, 16 Dec 1998 04:00:00



>Hi there,

Cheers,
[...]

Quote:>#1: I need to load two drivers and make a program run in batch mode at
>boot time,say when everything is up and ready for login command.Where do
>I put these instructions or what I have to do?

in one of your init scripts, but it depends on you init setup whether
you've something like /etc/rc.local (BSD'ish) or a SYSV init compatible
installation (like here, where there are /etc/rc0.d ... /etc/rc6.d
directories for the different runlevels).

Quote:>#2: I need,from a C program,to make Linux reboot when something weird is
>happening.WHat call I need to do within the program?

It depends on how hard you want to bring the machine down, see the source for
sysvinit for more (esp. since it depends on whether you have libc5 or libc6).

Much better of course is to make a clean shutdown and to fork() / exec()
/sbin/shutdown [args] or /sbin/telinit [runlevel] instead of using reboot()
which is a system call. You're talking straight to the kernel here, no
umount, nothing.

You can even set up a special runlevel for a "panic" shutdown (say, you might
disable all logins *right now*, send a message to your pager and such).

Bye,
Juergen

--
\ Real name     : Jrgen Heinzl                 \       no flames      /

  \ Phone Private : +44 181-332 0750              \                  /

 
 
 

Two tough questions

Post by Laurent Martell » Wed, 16 Dec 1998 04:00:00


    Michele> Hi there, I have 2 easy( or at least I hope so) questions
    Michele> for you.

    Michele> #2: I need,from a C program,to make Linux reboot when
    Michele> something weird is happening.WHat call I need to do
    Michele> within the program?

The simplest is probably to run reboot from you program with
exec. (man exec)

 
 
 

Two tough questions

Post by Gordon Sco » Thu, 17 Dec 1998 04:00:00


: #2: I need,from a C program,to make Linux reboot when something weird is
: happening.WHat call I need to do within the program?

I have to suggest you ask yourself if you're really sure you need to do
this. As a rule, Linux is robust enough that things rarely go 'weird',
so the need to self-reboot should may not really exist unless you're
doing something unusual and quite deep within the system.

Most application and peer-machine problems can be dealt with without
the need to reboot. There are various ways to auto-restart applications
if they break.

G.
--
Gordon Scott             Opinions expressed are my own.


Linux  ...............   Because I like to _get_ there today.

 
 
 

Two tough questions

Post by Pawel Sakows » Wed, 23 Dec 1998 04:00:00


Quote:>> #2: I need,from a C program,to make Linux reboot when something weird is
>> happening.WHat call I need to do within the program?

>system("reboot");

>This is not elegant but it might work.

I'd rather suggest

system("/sbin/init 6");

--
"We are different"


 
 
 

Two tough questions

Post by Jorge Delgado Mendoz » Wed, 30 Dec 1998 04:00:00



> Hi there,

> I have 2 easy( or at least I hope so) questions for you.

> #1: I need to load two drivers and make a program run in batch mode at
> boot time,say when everything is up and ready for login command.Where do
> I put these instructions or what I have to do?

Add it to /etc/rc.d/rc.local

Quote:

> #2: I need,from a C program,to make Linux reboot when something weird is
> happening.WHat call I need to do within the program?

1.- Setuid the program as 'root' (ie. has root privileges)
2.- whenever you want (in the code) issue the system call 'system'

                if ( reboot_condition)
                        system ( "reboot" );

man system, man execve....

Quote:

> Thanks in advance.

> Michele

--

|Jorge Delgado Mendoza|whatever the hell they want to, whenever they feel like|
|CONVEX Supercomputer |it. Thus all the rest  should be called 'Co-Operating  |
|SPAIN                |Systems'                                               |
|+34-91-531-00-95     |        As seen in comp.os.linux.*                     |
 
 
 

Two tough questions

Post by Jürgen Exne » Tue, 05 Jan 1999 04:00:00



>Hi there,

>I have 2 easy( or at least I hope so) questions for you.

>#1: I need to load two drivers and make a program run in batch mode at
>boot time,say when everything is up and ready for login command.Where do
>I put these instructions or what I have to do?

Check out /etc/rc.d.
/etc/rc.d/local.rc might be a good place for starters

Quote:>#2: I need,from a C program,to make Linux reboot when something weird is
>happening.WHat call I need to do within the program?

What about using e.g. "exec" with "/sbin/shutdown -r now"?
Of course somehow you will need root permissions to reboot.

jue
--
Jrgen Exner; microsoft.com, UID: jurgenex
Sorry for this anti-spam inconvenience

 
 
 

1. Tough one: two accts & domains, one box

Hi!  Thanks for reading this.  I have a tough one here and need any and
all help I can get.  I am setting up a server for an ISP and am
required to support two (or more) domains on the same box, and allow
the same login name to be used in each domain without conflict.  Can
this be done?  Would anyone out there be kind enough to point me to a
document about it, or offer some suggestions?

I am running Redhat Linux 5.2.  I have the web server and IP aliasing
working for the two domains, but need some guidance on how to map the
passwd file.

Thanks,

Dave Peterson

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

2. Opening ports/Mandrake 8 ICS prob

3. Tough Arp Problem - two subnets, one switch

4. grafik-adapter for xfree

5. A tough one: RH 6.0 innstall fails on "second stage image"

6. looking for INFORMATION

7. Printcap Help. Tough question, need a hand

8. Patch Remove Question

9. Tough Question About Linux

10. Block mode? A tough question

11. Tough DNS question -- any idea ?

12. A tough question

13. Tough Question About Linux