Discussion:
[redis-db] Confused about setproctitle
v***@gmail.com
2018-10-18 06:50:51 UTC
Permalink
In setproctitle.c

Function spt_init(int argc, char *argv[]) wrote like this

void spt_init(int argc, char *argv[]) {
char **envp = environ;
char *base, *end, *nul, *tmp;
int i, error;

if (!(base = argv[0]))
return;

nul = &base[strlen(base)];
end = nul + 1;

for (i = 0; i < argc || (i >= argc && argv[i]); i++) {
if (!argv[i] || argv[i] < end)
continue;

end = argv[i] + strlen(argv[i]) + 1;
}

for (i = 0; envp[i]; i++) {
if (envp[i] < end)
continue;

end = envp[i] + strlen(envp[i]) + 1;
}

Why there are "i >= argc && argv[i]"?
I think that if i>=argc, then the argv[i] will have index out of array
problem.
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+***@googlegroups.com.
To post to this group, send email to redis-***@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
v***@gmail.com
2018-10-19 08:44:24 UTC
Permalink
I have wrote a test program to print the memory of argv and envrion.
And figured out the reason of the code.
The memory of argv and envrion are like this:
----------------------------------------------------------------------------------------------------------
| argv[0] | argv[1] | ...| argv[argc-1] | NULL | envrion[0] | ... |
envrion[last] | NULL |
----------------------------------------------------------------------------------------------------------
The argv[i] will not have index out of array problem,
and make SPT.base->argv[0], SPT.end->envrion[last].
So that setproctitle can work properly.
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+***@googlegroups.com.
To post to this group, send email to redis-***@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
Loading...