This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: nscd paranoia mode restart functionality


On 25 Feb 2015 13:45, Florian Weimer wrote:
> Does anybody know what's going on in the restart function in
> nscd/connections.c?
> 
>   /* First determine the parameters.  We do not use the parameters
>      passed to main() since in case nscd is started by running the
>      dynamic linker this will not work.  Yes, this is not the usual
>      case but nscd is part of glibc and we occasionally do this.  */
>   size_t buflen = 1024;
>   char *buf = alloca (buflen);
>   size_t readlen = 0;
>   int fd = open ("/proc/self/cmdline", O_RDONLY);
> â
>   /* Parse the command line.  Worst case scenario: every two
>      characters form one parameter (one character plus NUL).  */
>   char **argv = alloca ((readlen / 2 + 1) * sizeof (argv[0]));
>   int argc = 0;
> 
> Can we get rid of the code instead pass around the argv vector?

i think the comments are misleading.  it's not that the argc/argv main() sees 
can't be used, it's that the full argc/argv that the process was launched with 
are unavailable.  so if you ran nscd:
	./elf/ld.so --library-path "$PWD:$PWD/nptl" ./nscd/nscd ...

main would only see the ..., but the restart needs the full ./elf/ld.so ... 
stuff to fully re-exec itself.  it can't simply run `nscd` from $PATH.

if you passed down the argc/argv from main, that wouldn't really help as you'd 
still need logic to extract the leading parts of the argv, and you'd have to add 
logic to figure out when to stop parsing, and add logic to merge the two argv.
-mike

Attachment: signature.asc
Description: Digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]