Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Cluster Development (http://www.linux-archive.org/cluster-development/)
-   -   cman_tool: don't use envp from main (http://www.linux-archive.org/cluster-development/601631-cman_tool-dont-use-envp-main.html)

"Fabio M. Di Nitto" 11-23-2011 09:15 AM

cman_tool: don't use envp from main
 
according to wikipedia it is a microsoft extensions. Use __environ
directly from unistd.h

Spotted by Coverity Scan

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
---
:100644 100644 60091c9... 6c5744e... M cman/cman_tool/cman_tool.h
:100644 100644 872528b... b92090c... M cman/cman_tool/join.c
:100644 100644 a336c42... 6d8a1eb... M cman/cman_tool/main.c
cman/cman_tool/cman_tool.h | 3 +--
cman/cman_tool/join.c | 13 +++++++------
cman/cman_tool/main.c | 10 +++++-----
3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/cman/cman_tool/cman_tool.h b/cman/cman_tool/cman_tool.h
index 60091c9..6c5744e 100644
--- a/cman/cman_tool/cman_tool.h
+++ b/cman/cman_tool/cman_tool.h
@@ -19,7 +19,6 @@
#include <fcntl.h>
#include <netdb.h>
#include <limits.h>
-#include <unistd.h>

extern char *prog_name;

@@ -105,6 +104,6 @@ struct commandline
};
typedef struct commandline commandline_t;

-int join(commandline_t *comline, char *envp[]);
+int join(commandline_t *comline);

#endif /* __CMAN_TOOL_DOT_H__ */
diff --git a/cman/cman_tool/join.c b/cman/cman_tool/join.c
index 872528b..b92090c 100644
--- a/cman/cman_tool/join.c
+++ b/cman/cman_tool/join.c
@@ -1,4 +1,5 @@
#include <errno.h>
+#include <unistd.h>
#include <sys/wait.h>
#include <stdint.h>
#include <signal.h>
@@ -119,7 +120,7 @@ static int check_corosync_status(pid_t pid)
return status;
}

-int join(commandline_t *comline, char *main_envp[])
+int join(commandline_t *comline)
{
int i, err;
int envptr = 0;
@@ -205,9 +206,9 @@ int join(commandline_t *comline, char *main_envp[])

/* Copy any COROSYNC_* env variables to the new daemon */
i=0;
- while (i < MAX_ARGS && main_envp[i]) {
- if (strncmp(main_envp[i], "COROSYNC_", 9) == 0)
- envp[envptr++] = main_envp[i];
+ while (i < MAX_ARGS && __environ[i]) {
+ if (strncmp(__environ[i], "COROSYNC_", 9) == 0)
+ envp[envptr++] = __environ[i];
i++;
}

@@ -363,7 +364,7 @@ int join(commandline_t *comline, char *main_envp[])
res = confdb_object_create(confdb_handle, OBJECT_PARENT_HANDLE, "cman_private", strlen("cman_private"), &object_handle);
if (res == CS_OK) {
int envnum = 0;
- const char *envvar = main_envp[envnum];
+ const char *envvar = __environ[envnum];
const char *equal;
char envname[PATH_MAX];

@@ -381,7 +382,7 @@ int join(commandline_t *comline, char *main_envp[])
}
}
}
- envvar = main_envp[++envnum];
+ envvar = __environ[++envnum];
}
}
res = confdb_key_create_typed(confdb_handle, object_handle,
diff --git a/cman/cman_tool/main.c b/cman/cman_tool/main.c
index a336c42..6d8a1eb 100644
--- a/cman/cman_tool/main.c
+++ b/cman/cman_tool/main.c
@@ -1190,7 +1190,7 @@ static void check_arguments(commandline_t *comline)
}


-static void do_join(commandline_t *comline, char *envp[])
+static void do_join(commandline_t *comline)
{
int ret;

@@ -1212,18 +1212,18 @@ static void do_join(commandline_t *comline, char *envp[])
die("Not joining, configuration is not valid
");
}

- join(comline, envp);
+ join(comline);
if (comline->wait_opt || comline->wait_quorate_opt) {
do {
ret = cluster_wait(comline);
if (ret == ENOTCONN)
- join(comline, envp);
+ join(comline);

} while (ret == ENOTCONN);
}
}

-int main(int argc, char *argv[], char *envp[])
+int main(int argc, char *argv[])
{
commandline_t comline;

@@ -1235,7 +1235,7 @@ int main(int argc, char *argv[], char *envp[])

switch (comline.operation) {
case OP_JOIN:
- do_join(&comline, envp);
+ do_join(&comline);
break;

case OP_LEAVE:
--
1.7.4.4

Steven Whitehouse 11-23-2011 09:28 AM

cman_tool: don't use envp from main
 
Hi,

On Wed, 2011-11-23 at 11:15 +0100, Fabio M. Di Nitto wrote:
> according to wikipedia it is a microsoft extensions. Use __environ
> directly from unistd.h
>
> Spotted by Coverity Scan
>
> Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
> ---
> :100644 100644 60091c9... 6c5744e... M cman/cman_tool/cman_tool.h
> :100644 100644 872528b... b92090c... M cman/cman_tool/join.c
> :100644 100644 a336c42... 6d8a1eb... M cman/cman_tool/main.c
> cman/cman_tool/cman_tool.h | 3 +--
> cman/cman_tool/join.c | 13 +++++++------
> cman/cman_tool/main.c | 10 +++++-----
> 3 files changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/cman/cman_tool/cman_tool.h b/cman/cman_tool/cman_tool.h
> index 60091c9..6c5744e 100644
> --- a/cman/cman_tool/cman_tool.h
> +++ b/cman/cman_tool/cman_tool.h
> @@ -19,7 +19,6 @@
> #include <fcntl.h>
> #include <netdb.h>
> #include <limits.h>
> -#include <unistd.h>
>
> extern char *prog_name;
>
> @@ -105,6 +104,6 @@ struct commandline
> };
> typedef struct commandline commandline_t;
>
> -int join(commandline_t *comline, char *envp[]);
> +int join(commandline_t *comline);
>
> #endif /* __CMAN_TOOL_DOT_H__ */
> diff --git a/cman/cman_tool/join.c b/cman/cman_tool/join.c
> index 872528b..b92090c 100644
> --- a/cman/cman_tool/join.c
> +++ b/cman/cman_tool/join.c
> @@ -1,4 +1,5 @@
> #include <errno.h>
> +#include <unistd.h>
> #include <sys/wait.h>
> #include <stdint.h>
> #include <signal.h>
> @@ -119,7 +120,7 @@ static int check_corosync_status(pid_t pid)
> return status;
> }
>
> -int join(commandline_t *comline, char *main_envp[])
> +int join(commandline_t *comline)
> {
> int i, err;
> int envptr = 0;
> @@ -205,9 +206,9 @@ int join(commandline_t *comline, char *main_envp[])
>
> /* Copy any COROSYNC_* env variables to the new daemon */
> i=0;
> - while (i < MAX_ARGS && main_envp[i]) {
> - if (strncmp(main_envp[i], "COROSYNC_", 9) == 0)
> - envp[envptr++] = main_envp[i];
> + while (i < MAX_ARGS && __environ[i]) {
> + if (strncmp(__environ[i], "COROSYNC_", 9) == 0)
> + envp[envptr++] = __environ[i];
> i++;
> }
Why not just use getenv() ?

Steve.

"Fabio M. Di Nitto" 11-23-2011 09:45 AM

cman_tool: don't use envp from main
 
On 11/23/2011 11:28 AM, Steven Whitehouse wrote:
> Hi,
>
> On Wed, 2011-11-23 at 11:15 +0100, Fabio M. Di Nitto wrote:
>> according to wikipedia it is a microsoft extensions. Use __environ
>> directly from unistd.h
>>
>> Spotted by Coverity Scan
>>
>> Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
>> ---
>> :100644 100644 60091c9... 6c5744e... M cman/cman_tool/cman_tool.h
>> :100644 100644 872528b... b92090c... M cman/cman_tool/join.c
>> :100644 100644 a336c42... 6d8a1eb... M cman/cman_tool/main.c
>> cman/cman_tool/cman_tool.h | 3 +--
>> cman/cman_tool/join.c | 13 +++++++------
>> cman/cman_tool/main.c | 10 +++++-----
>> 3 files changed, 13 insertions(+), 13 deletions(-)
>>
>> diff --git a/cman/cman_tool/cman_tool.h b/cman/cman_tool/cman_tool.h
>> index 60091c9..6c5744e 100644
>> --- a/cman/cman_tool/cman_tool.h
>> +++ b/cman/cman_tool/cman_tool.h
>> @@ -19,7 +19,6 @@
>> #include <fcntl.h>
>> #include <netdb.h>
>> #include <limits.h>
>> -#include <unistd.h>
>>
>> extern char *prog_name;
>>
>> @@ -105,6 +104,6 @@ struct commandline
>> };
>> typedef struct commandline commandline_t;
>>
>> -int join(commandline_t *comline, char *envp[]);
>> +int join(commandline_t *comline);
>>
>> #endif /* __CMAN_TOOL_DOT_H__ */
>> diff --git a/cman/cman_tool/join.c b/cman/cman_tool/join.c
>> index 872528b..b92090c 100644
>> --- a/cman/cman_tool/join.c
>> +++ b/cman/cman_tool/join.c
>> @@ -1,4 +1,5 @@
>> #include <errno.h>
>> +#include <unistd.h>
>> #include <sys/wait.h>
>> #include <stdint.h>
>> #include <signal.h>
>> @@ -119,7 +120,7 @@ static int check_corosync_status(pid_t pid)
>> return status;
>> }
>>
>> -int join(commandline_t *comline, char *main_envp[])
>> +int join(commandline_t *comline)
>> {
>> int i, err;
>> int envptr = 0;
>> @@ -205,9 +206,9 @@ int join(commandline_t *comline, char *main_envp[])
>>
>> /* Copy any COROSYNC_* env variables to the new daemon */
>> i=0;
>> - while (i < MAX_ARGS && main_envp[i]) {
>> - if (strncmp(main_envp[i], "COROSYNC_", 9) == 0)
>> - envp[envptr++] = main_envp[i];
>> + while (i < MAX_ARGS && __environ[i]) {
>> + if (strncmp(__environ[i], "COROSYNC_", 9) == 0)
>> + envp[envptr++] = __environ[i];
>> i++;
>> }
> Why not just use getenv() ?

getenv implies that you know the values you are looking for.

This function is generic and look for everything that starts with
COROSYNC_ in the environment.

Fabio


All times are GMT. The time now is 04:43 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.