Re: Changing argv[0] under Linux.

Richard B. Johnson (root@chaos.analogic.com)
Wed, 15 Jan 2003 11:43:01 -0500 (EST)


This is a MIME-formatted message. If you see this text it means that your
E-mail software does not support MIME-formatted messages.

--=_courier-28561-1042648895-0001-2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Well, I just can't give this up! Here is a procedure plus a test
program that reallocates and copies environment strings so the
process title can be altered. The procedure returns the amount
of space available for the new name so that strncpy() can be
used to prevent damage.

If you don't like me pretending that main() gets the environment
after args[], you can access environ directly anyway with the
same result. Have fun!

If you don't have enough string-space to make a large enough name,
just increase the size of your environment.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.

--=_courier-28561-1042648895-0001-2
Content-Type: text/plain; charset=us-ascii; name="xxx.c"
Content-Transfer-Encoding: base64
Content-ID: <Pine.LNX.3.95.1030115114301.18233B@chaos.analogic.com>
Content-Description:

I2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5jbHVkZSA8c3RyaW5nLmg+DQojaW5j
bHVkZSA8dW5pc3RkLmg+DQojaW5jbHVkZSA8bWFsbG9jLmg+DQoNCmV4dGVy
biBjaGFyICoqZW52aXJvbjsNCg0Kc2l6ZV90IGluaXRfc2V0dGl0bGUoY2hh
ciAqYXJndltdLCBjaGFyICplbnZbXSkNCnsNCiAgIHNpemVfdCBpLCBsZW47
DQogICBjaGFyICpsaW1pdDsNCiAgIGNoYXIgKnZhcjsNCiAgIGkgPSAwOw0K
ICAgd2hpbGUoZW52W2ldICE9IE5VTEwpDQogICB7DQogICAgICAgbGVuID0g
IHN0cmxlbihlbnZbaV0pICsgMTsgICAgICAvKiBSb29tIGZvciB0aGUgJ1ww
JyAgICAqLw0KICAgICAgIHZhciA9ICAoY2hhciAqKSBtYWxsb2MobGVuKTsN
CiAgICAgICBtZW1jcHkodmFyLCBlbnZbaV0sIGxlbik7ICAgICAgIC8qIENv
cHkgdGhlICdcMCcgYWxzbyAgICovDQogICAgICAgbGltaXQgICAgPSBlbnZb
aV07ICAgICAgICAgICAgICAvKiBTdGFydCBvZiBsYXN0IHN0cmluZyAqLw0K
ICAgICAgIGVudltpKytdID0gdmFyOyAgICAgICAgICAgICAgICAgLyogTmV3
IGVudmlyb25tZW50IHB0ciAgKi8NCiAgIH0NCiAgIHdoaWxlKCpsaW1pdCkg
ICAgICAgICAgICAgICAgICAgICAgIC8qIEVuZCBvZiBsYXN0IHN0cmluZyAg
ICovDQogICAgICAgbGltaXQrKzsNCiAgIHJldHVybiAobGltaXQgLSBhcmd2
WzBdKTsgICAgICAgICAgIC8qIFNwYWNlIHdlIGNhbiB1c2UgICAgICovDQp9
DQoNCmludCBtYWluKGludCBjLCBjaGFyICphcmd2W10sIGNoYXIgKmVudltd
KQ0Kew0KICAgIHNpemVfdCBsZW4sIGk7DQogICAgbGVuID0gaW5pdF9zZXR0
aXRsZShhcmd2LCBlbnYpOw0KICAgIGkgPSAwOw0KICAgIHdoaWxlKGVudmly
b25baV0gIT0gTlVMTCkNCiAgICAgICAgcHV0cyhlbnZpcm9uW2krK10pOw0K
ICAgIHByaW50ZigiTGVuZ3RoIGFsbG93ZWQgPSAldVxuIiwgbGVuKTsNCiAg
ICBmZmx1c2goc3Rkb3V0KTsNCiAgICBzdHJuY3B5KGFyZ3ZbMF0sICJBbnRp
ZGVzZXN0YWJsaXNobWVudGFyaWFuaXNtIiwgbGVuKTsNCiAgICBpID0gMDsN
CiAgICB3aGlsZShlbnZpcm9uW2ldICE9IE5VTEwpDQogICAgICAgIHB1dHMo
ZW52aXJvbltpKytdKTsNCiAgICBmZmx1c2goc3Rkb3V0KTsNCiAgICBwYXVz
ZSgpOyANCiAgICByZXR1cm4gMDsNCn0NCg0K
--=_courier-28561-1042648895-0001-2--