Unix/Linux

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • argv getting corrupt because of getenv issues?

    2 answers - 1549 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hello,
    Trying to debug a weird problem here. When I run this program many
    times over, at some point argc gets corrupted and I get the error that
    enough number of arguments are not provided. It definitely seems to
    have something to do with the env. variable being set and used because
    the previous version of this code did not have that variable and did
    not have this problem. I am running this on linux on a powerpc based
    hardware. stdlib.h is included.
    My condition is that if this env variable does not exist at all or if
    it exisits and it is set to 1, I want to <D STUFFand if it exisits
    and is set to 0, <D NT D STUFF>
    Here is the relevant portion of the program I am trying to debug. .
    int main(int argc, char** argv) {
    char* status = 0;
    if(argc < 2)
    {
    fprintf(stderr, " Not enough arguments.\n");
    fflush(stderr);
    }
    while(1)
    {
    status = getenv("TIMER_STATUS");
    if((status == 0) || ((status != 0) && (atoi(status) != 1)))
    {
    <Do STUFF>
    }
    else
    {
    <D NT STUFF>
    }
    }
    In MST cases, the program runs just fine. But after about 10-15 times
    of running repeatedly, i will always get the error that there are not
    enough arguments. If I reboot the entire board that will restart the
    kernel and everything, all is well once again until we get into that
    restarting many times scenario.
    Any ideas of where I might start to debug this?
    Thanks much,
    Vinod
  • No.1 | | 1972 bytes | |

    anuragmenon@gmail.com wrote:
    Hello,

    Trying to debug a weird problem here. When I run this program many
    times over, at some point argc gets corrupted and I get the error that
    enough number of arguments are not provided. It definitely seems to
    have something to do with the env. variable being set and used because
    the previous version of this code did not have that variable and did
    not have this problem. I am running this on linux on a powerpc based
    hardware. stdlib.h is included.
    --
    My condition is that if this env variable does not exist at all or if
    it exisits and it is set to 1, I want to <D STUFFand if it exisits
    and is set to 0, <D NT D STUFF>
    --
    Here is the relevant portion of the program I am trying to debug. .
    --
    int main(int argc, char** argv) {
    --
    char* status = 0;
    --
    if(argc < 2)
    {
    fprintf(stderr, " Not enough arguments.\n");
    fflush(stderr);
    }
    --
    while(1)
    {
    --
    status = getenv("TIMER_STATUS");
    if((status == 0) || ((status != 0) && (atoi(status) != 1)))
    {
    <Do STUFF>
    }
    else
    {
    <D NT STUFF>
    --
    }
    >
    >
    >

    }
    --
    In MST cases, the program runs just fine. But after about 10-15 times
    of running repeatedly, i will always get the error that there are not
    enough arguments. If I reboot the entire board that will restart the
    kernel and everything, all is well once again until we get into that
    restarting many times scenario.

    Any ideas of where I might start to debug this?
    --
    Thanks much,
    Vinod

    I'd add

    #DEBUG
    #ifdef DEBUG
    int k;
    printf("argc=%d\n",argc)
    for (k=0;k<argc;k++)
    {
    printf(" %s",argv[k]);
    }
    printf ("\n");
    #endif

    :-)

    As a startsince your code seems to check argc before doing anything
    nasty, it seems unlikeley you're are crashing the stack
  • No.2 | | 1333 bytes | |

    anuragmenon@gmail.com writes:

    Hello,

    Trying to debug a weird problem here. When I run this program many
    times over, at some point argc gets corrupted and I get the error that
    enough number of arguments are not provided. It definitely seems to
    have something to do with the env. variable being set and used because
    the previous version of this code did not have that variable and did
    not have this problem. I am running this on linux on a powerpc based
    hardware. stdlib.h is included.

    My condition is that if this env variable does not exist at all or if
    it exisits and it is set to 1, I want to <D STUFFand if it exisits
    and is set to 0, <D NT D STUFF>
    --
    Here is the relevant portion of the program I am trying to debug. .

    int main(int argc, char** argv) {
    char* status = 0;
    if(argc < 2)
    {
    fprintf(stderr, " Not enough arguments.\n");
    fflush(stderr);
    }
    while(1)
    {

    I'm mystified.

    Why are you showing us stuff about a getenv when your problem
    is a program being invoked with too few arguments?

    You say nothing about how this program is invoked.
    You also tell us stdlib is included but the program you
    show doesn't have it.
    Nor do you show how the program is compiled and linked.

Re: argv getting corrupt because of getenv issues?


max 4000 letters.
Your nickname that display:
In order to stop the spam: 6 + 6 =
QUESTION ON "Unix/Linux"

EMSDN.COM