public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* User/kernelspace stuff to set/get kernel variables
@ 2001-12-13 15:54 DevilKin
  2001-12-13 16:03 ` Daniel Freedman
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: DevilKin @ 2001-12-13 15:54 UTC (permalink / raw)
  To: linux-kernel

Hello

I've been looking on the web, and couldn't really find what i would want...

Basically: is it possible to - one way or another - set variables at kernel boot and read those using userspace utilities?

for instance: i boot my kernel (using any old bootmanager that accepts kernel params)


LILO: linux network=dhcp


and later, in the init scripts, i check the value of this variable using some sort of userspace program, and if it happends to be 'dhcp' i'll invoke the dhcp client. 
Otherwise i'd just give a static address.

I have other uses for this, for instance, you want your disks to be FSCK'ed, but don't wanna boot first, or, don't wanna go in single user mode


LILO: linux dofsck=true


Does something like this exist? Is it implementable in an easy way? (I know a few programming languages, but only little C(++)....)

Thanks


DK

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: User/kernelspace stuff to set/get kernel variables
  2001-12-13 15:54 User/kernelspace stuff to set/get kernel variables DevilKin
@ 2001-12-13 16:03 ` Daniel Freedman
  2001-12-13 16:07 ` Richard B. Johnson
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Daniel Freedman @ 2001-12-13 16:03 UTC (permalink / raw)
  To: linux-kernel

On Thu, Dec 13, 2001, DevilKin wrote:
> Hello
> 
> I've been looking on the web, and couldn't really find what i would want...
> 
> Basically: is it possible to - one way or another - set variables at kernel boot and read those using userspace utilities?

Sorry, I don't know, but see below for possible solution to your problem anyway.

> for instance: i boot my kernel (using any old bootmanager that accepts kernel params)
> 
> 
> LILO: linux network=dhcp

You might want to familiarize yourself with the following kernel parameter:

"ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>"

where most options are obvious, and you'll probably want device to be
"eth0" and autoconf to be "dhcp".

HTH,

Daniel


> and later, in the init scripts, i check the value of this variable using some sort of userspace program, and if it happends to be 'dhcp' i'll invoke the dhcp client. 
> Otherwise i'd just give a static address.
> 
> I have other uses for this, for instance, you want your disks to be FSCK'ed, but don't wanna boot first, or, don't wanna go in single user mode
> 
> 
> LILO: linux dofsck=true
> 
> 
> Does something like this exist? Is it implementable in an easy way? (I know a few programming languages, but only little C(++)....)
> 
> Thanks
> 
> 
> DK
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
Daniel A. Freedman
Laboratory for Atomic and Solid State Physics
Department of Physics
Cornell University

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: User/kernelspace stuff to set/get kernel variables
  2001-12-13 15:54 User/kernelspace stuff to set/get kernel variables DevilKin
  2001-12-13 16:03 ` Daniel Freedman
@ 2001-12-13 16:07 ` Richard B. Johnson
  2001-12-13 16:11 ` Yann E. MORIN
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Richard B. Johnson @ 2001-12-13 16:07 UTC (permalink / raw)
  To: DevilKin; +Cc: linux-kernel

On Thu, 13 Dec 2001, DevilKin wrote:

> Hello
> 
> I've been looking on the web, and couldn't really find what i would want...
> 
> Basically: is it possible to - one way or another - set variables at kernel boot and read those using userspace utilities?
> 
> for instance: i boot my kernel (using any old bootmanager that accepts kernel params)
> 
> 
> LILO: linux network=dhcp
> 

Is this what you want?

`cat /proc/cmdline`


Cheers,
Dick Johnson

Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips).
 Santa Claus is coming to town...
          He knows if you've been sleeping,
             He knows if you're awake;
          He knows if you've been bad or good,
             So he must be Attorney General Ashcroft.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: User/kernelspace stuff to set/get kernel variables
  2001-12-13 15:54 User/kernelspace stuff to set/get kernel variables DevilKin
  2001-12-13 16:03 ` Daniel Freedman
  2001-12-13 16:07 ` Richard B. Johnson
@ 2001-12-13 16:11 ` Yann E. MORIN
  2001-12-13 16:20 ` Jan Janak
  2001-12-13 20:34 ` H. Peter Anvin
  4 siblings, 0 replies; 8+ messages in thread
From: Yann E. MORIN @ 2001-12-13 16:11 UTC (permalink / raw)
  To: DevilKin; +Cc: lkml

Hi DK.

> Basically: is it possible to - one way or another - set variables at
> kernel boot and read those using userspace utilities?
> for instance: i boot my kernel (using any old bootmanager that
> accepts kernel params)
> LILO: linux network=dhcp
> and later, in the init scripts, i check the value of this variable
> using some sort of userspace program, and if it happends to be
> 'dhcp' i'll invoke the dhcp client.
[--8<--SNIP--8<--]

You'll at least find that in /proc/1/environ

It's a null-terminated list of strings that consist of what you want.
You'll see it as well while dumping the kernel log (dmesg) at the
begining. For my machine, I have:

--8<--
Kernel command line: auto BOOT_IMAGE=linux root=806 devfs=mount idebus=33
--8<--

Regards,
Yann.

--
.---------------------------.----------------------.------------------.
|       Yann E. MORIN       |  Real-Time Embedded  | ASCII RIBBON /"\ |
| phone (+33/0) 299 055 231 |  Software  Designer  |   CAMPAIGN   \ / |
|   fax (+33/0) 299 055 221 °----------------------:   AGAINST     X  |
| yann.morin@atosorigin.com    www.atosorigin.com  |  HTML MAIL   / \ |
°--------------------------------------------------°------------------°



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: User/kernelspace stuff to set/get kernel variables
  2001-12-13 15:54 User/kernelspace stuff to set/get kernel variables DevilKin
                   ` (2 preceding siblings ...)
  2001-12-13 16:11 ` Yann E. MORIN
@ 2001-12-13 16:20 ` Jan Janak
  2001-12-13 16:58   ` Russell King
  2001-12-13 20:34 ` H. Peter Anvin
  4 siblings, 1 reply; 8+ messages in thread
From: Jan Janak @ 2001-12-13 16:20 UTC (permalink / raw)
  To: linux-kernel

On Thu, Dec 13, 2001 at 04:54:05PM +0100, DevilKin wrote:
> Hello
> 
> I've been looking on the web, and couldn't really find what i would want...
> 
> Basically: is it possible to - one way or another - set variables at kernel boot and read those using userspace utilities?
> 
> for instance: i boot my kernel (using any old bootmanager that accepts kernel params)
> 
> 
> LILO: linux network=dhcp
> 
> 
> and later, in the init scripts, i check the value of this variable using some sort of userspace program, and if it happends to be 'dhcp' i'll invoke the dhcp client. 
> Otherwise i'd just give a static address.
> 
> I have other uses for this, for instance, you want your disks to be FSCK'ed, but don't wanna boot first, or, don't wanna go in single user mode
> 
> 
> LILO: linux dofsck=true
> 
> 
> Does something like this exist? Is it implementable in an easy way? (I know a few programming languages, but only little C(++)....)
> 

    If you pass a parameter that is not recognized by the kernel, it will be passed to init as environment variable,
 so all you need to do is check for the variable in your init scripts ($network in your example).

   regards, Jan.

> Thanks
> 
> 
> DK
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: User/kernelspace stuff to set/get kernel variables
  2001-12-13 16:20 ` Jan Janak
@ 2001-12-13 16:58   ` Russell King
  2001-12-13 19:48     ` Jan Janak
  0 siblings, 1 reply; 8+ messages in thread
From: Russell King @ 2001-12-13 16:58 UTC (permalink / raw)
  To: Jan Janak; +Cc: linux-kernel

On Thu, Dec 13, 2001 at 05:20:37PM +0100, Jan Janak wrote:
> If you pass a parameter that is not recognized by the kernel, it will be
> passed to init as environment variable, so all you need to do is check
> for the variable in your init scripts ($network in your example).

IIRC, Red Hat scripts grab them from /proc/cmdline

--
Russell King (rmk@arm.linux.org.uk)                The developer of ARM Linux
             http://www.arm.linux.org.uk/personal/aboutme.html


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: User/kernelspace stuff to set/get kernel variables
  2001-12-13 16:58   ` Russell King
@ 2001-12-13 19:48     ` Jan Janak
  0 siblings, 0 replies; 8+ messages in thread
From: Jan Janak @ 2001-12-13 19:48 UTC (permalink / raw)
  To: Russell King; +Cc: linux-kernel

On Thu, Dec 13, 2001 at 04:58:05PM +0000, Russell King wrote:
> On Thu, Dec 13, 2001 at 05:20:37PM +0100, Jan Janak wrote:
> > If you pass a parameter that is not recognized by the kernel, it will be
> > passed to init as environment variable, so all you need to do is check
> > for the variable in your init scripts ($network in your example).
> 
> IIRC, Red Hat scripts grab them from /proc/cmdline

  Only parameters of the form foo=bar will be set as environment variables (if not
recognized by the kernel).
  AFAIK Red Hat scripts grab parameters of different form from /proc/cmdline.

  But parameter of the form network=dhcp will be set as environment variable and
 this is IMHO the easiest way how to get the parameter value in startup scripts.

  regards, Jan.

> 
> --
> Russell King (rmk@arm.linux.org.uk)                The developer of ARM Linux
>              http://www.arm.linux.org.uk/personal/aboutme.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: User/kernelspace stuff to set/get kernel variables
  2001-12-13 15:54 User/kernelspace stuff to set/get kernel variables DevilKin
                   ` (3 preceding siblings ...)
  2001-12-13 16:20 ` Jan Janak
@ 2001-12-13 20:34 ` H. Peter Anvin
  4 siblings, 0 replies; 8+ messages in thread
From: H. Peter Anvin @ 2001-12-13 20:34 UTC (permalink / raw)
  To: linux-kernel

Followup to:  <20011213155532Z284289-18284+114@vger.kernel.org>
By author:    DevilKin <devilkin@gmx.net>
In newsgroup: linux.dev.kernel
>
> Hello
> 
> I've been looking on the web, and couldn't really find what i would want...
> 
> Basically: is it possible to - one way or another - set variables at
> kernel boot and read those using userspace utilities?
> 

The entire kernel command line is quoted verbatim in /proc/cmdline.

Additionally, items of the form foo=bar that are not recognized by the
kernel become environment variables to init, and items not of that
form *sometimes* become command-line options to init...

	-hpa
-- 
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt	<amsp@zytor.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-12-13 20:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-12-13 15:54 User/kernelspace stuff to set/get kernel variables DevilKin
2001-12-13 16:03 ` Daniel Freedman
2001-12-13 16:07 ` Richard B. Johnson
2001-12-13 16:11 ` Yann E. MORIN
2001-12-13 16:20 ` Jan Janak
2001-12-13 16:58   ` Russell King
2001-12-13 19:48     ` Jan Janak
2001-12-13 20:34 ` H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox