August 15, 2011 Re: const main args? | ||||
---|---|---|---|---|
| ||||
I seen what sendmail actually changes they arguments of command line for nice output of "ps ax" command. May be it changes his argc/argv for this? |
August 20, 2011 Re: const main args? | ||||
---|---|---|---|---|
| ||||
Posted in reply to mimocrocodil | mimocrocodil <4denizzz@gmail.com> writes: > I seen what sendmail actually changes they arguments of command line for nice output of "ps ax" command. > > May be it changes his argc/argv for this? Yes. Some unix C programs, daemons usually, modify argv to change what ps shows. It works with D too, I tried it (but have to cast away immutable). Here is a quick demo, assuming args[0] has enough room. import std.c.string; import core.thread; void main(string[] args) { auto a = cast(char*)args[0].ptr; strcpy(a, "xyzzy"); // change ps output to list us as xyzzy Thread.sleep(dur!("seconds")(10)); } $ ps PID TTY TIME CMD 355 ttys000 0:00.01 /bin/bash --noediting -i 358 ttys000 0:00.00 xyzzy Since you have to be unsafe anyway, casting to char* from in string would be no worse than string. |
Copyright © 1999-2021 by the D Language Foundation