LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-26-2005, 12:47 PM   #1
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Rep: Reputation: 30
getopt_long seg faults!! help plz [SOLVED]


hiho@ll

i try to change the source of cronolog project (cronolog.org)
because i need it for my project

what i want to do:
nearly finished i tried to attach some arguments that cronolog can execute scripts before or after it has logged something depending on a time value or file quota

my problem:
first to say: i compile the code using the same make script which is used by cronolog project

i'm not really expirienced with getopt!
what i did:
---------------
char *short_options = "ad:eop:s:z:H:P:S:l:hVx:T:R:t:";

#ifndef _WIN32
struct option long_options[] =
{
{ "american", no_argument, NULL, 'a' },
{ "european", no_argument, NULL, 'e' },
{ "start-time", required_argument, NULL, 's' },
{ "time-zone", required_argument, NULL, 'z' },
{ "hardlink", required_argument, NULL, 'H' },
{ "symlink", required_argument, NULL, 'S' },
{ "prev-symlink", required_argument, NULL, 'P' },
{ "link", required_argument, NULL, 'l' },
{ "period", required_argument, NULL, 'p' },
{ "delay", required_argument, NULL, 'd' },
{ "once-only", no_argument, NULL, 'o' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ "postexec", required_argument, NULL, 'T' },
{ "preexec", required_argument, NULL, 'R' },
{ "timetoexecute", required_argument, NULL, 't' }
};
#endif

#ifndef _WIN32
while ((ch = getopt_long(argc, argv, short_options, long_options, NULL)) != EOF)
#else
while ((ch = getopt(argc, argv, short_options)) != EOF)
#endif
{


------------------
this is the code i made
i added postexec,preexec and timetoexecute long_options and last three short options

i tried a little debugging with printf (because i haven't a debugger installed)
and it seems that if i do:

printf("%s\n",short_options);
tmp=long_options;
while(tmp!=NULL && tmp->name!=NULL){
printf("%s %d %p %d\n",tmp->name,tmp->has_arg,tmp->flag,tmp->val);
tmp++;
}


makes a segfault
the same happens in the example above without my debug printf
so, what's wrong?
i don't know what could be wrong because, the original code is nearly the same except the new arguments!

thx@ll

Last edited by Thinking; 07-26-2005 at 01:12 PM.
 
Old 07-26-2005, 01:12 PM   #2
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Original Poster
Rep: Reputation: 30
it just bugged somewhere else
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
GCC seg faults benne Linux - Software 5 09-05-2005 01:09 AM
Repeated seg faults Tick Linux - General 5 07-29-2004 07:09 PM
seg faults happening allan_y Linux - General 2 07-25-2004 05:30 AM
bash seg faults Kilka *BSD 4 12-15-2003 01:40 AM
w3m seg faults slakmagik Linux - Software 0 05-04-2003 10:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration