debugging problem

R

Ron Eggler

Hi,

I'm developing software for Linux on my desktop. The software gets compiled
and the binary is downloaded to the target system where i can't install a
debugging system or something.
I've written following code:
#ifdef INIT_REPORT
std::eek:fstream out("/usr/share/NovaxTSP/INITreport.txt", std::ios_base::in |
std::ios_base::eek:ut | std::ios_base::app);
if(!out) { // if out couldn't be opened, print error and exit
std::cout << "Cannot open reportfile:
\"/usr/share/NovaxTSP/INITreport.txt\"." << std::endl;
exit(0);
}
std::string str = newLine + "\n";
out << newLine.c_str() << std::endl;
out.close();
#endif

The problem is, it works just fine on my desktop but it returns
with "/usr/share/NovaxTSP/INITreport.txt" on the target system. I'm root
and i do have write access to /usr/share/NovaxTSP/. I have
tried "touch /usr/share/NovaxTSP/INITreport.txt" but this didn't help
either.
df -h shows that I'm not running out of space either
Does any one have any other idea what could go wrong?

Thanks,
Ron
 
R

red floyd

Ron said:
Hi,

I'm developing software for Linux on my desktop. The software gets compiled
and the binary is downloaded to the target system where i can't install a
debugging system or something.
I've written following code:
#ifdef INIT_REPORT
std::eek:fstream out("/usr/share/NovaxTSP/INITreport.txt", std::ios_base::in |
std::ios_base::eek:ut | std::ios_base::app);

Is this combination of flags legit?
if(!out) { // if out couldn't be opened, print error and exit
std::cout << "Cannot open reportfile:
\"/usr/share/NovaxTSP/INITreport.txt\"." << std::endl;

Odds are good that errno is probably valid here, assuming you're using
gcc. Try adding:

#include <cerrno>
#include <cstdio>

at the top, and adding

std::cout << std::strerror(errno)

in your error message.
 
R

red floyd

Ron said:
Hi,

I'm developing software for Linux on my desktop. The software gets compiled
and the binary is downloaded to the target system where i can't install a
debugging system or something.
I've written following code:
#ifdef INIT_REPORT
std::eek:fstream out("/usr/share/NovaxTSP/INITreport.txt", std::ios_base::in |
std::ios_base::eek:ut | std::ios_base::app);
if(!out) { // if out couldn't be opened, print error and exit
std::cout << "Cannot open reportfile:
\"/usr/share/NovaxTSP/INITreport.txt\"." << std::endl;
exit(0);
}
std::string str = newLine + "\n";
out << newLine.c_str() << std::endl;
out.close();
#endif

The problem is, it works just fine on my desktop but it returns
with "/usr/share/NovaxTSP/INITreport.txt" on the target system. I'm root
and i do have write access to /usr/share/NovaxTSP/. I have
tried "touch /usr/share/NovaxTSP/INITreport.txt" but this didn't help
either.
df -h shows that I'm not running out of space either
Does any one have any other idea what could go wrong?

You may also get better answers in gnu.g++.help, or one of the many
linux programming newsgroups.
 
D

diligent.snail

Hi,

I'm developing software for Linux on my desktop. The software gets compiled
and the binary is downloaded to the target system where i can't install a
debugging system or something.
I've written following code:
#ifdef INIT_REPORT
std::eek:fstream out("/usr/share/NovaxTSP/INITreport.txt", std::ios_base::in |
std::ios_base::eek:ut | std::ios_base::app);
if(!out) { // if out couldn't be opened, print error and exit
std::cout << "Cannot open reportfile:
\"/usr/share/NovaxTSP/INITreport.txt\"." << std::endl;
exit(0);
}
std::string str = newLine + "\n";
out << newLine.c_str() << std::endl;
out.close();
#endif

The problem is, it works just fine on my desktop but it returns
with "/usr/share/NovaxTSP/INITreport.txt" on the target system. I'm root
and i do have write access to /usr/share/NovaxTSP/. I have
tried "touch /usr/share/NovaxTSP/INITreport.txt" but this didn't help
either.
df -h shows that I'm not running out of space either
Does any one have any other idea what could go wrong?

Thanks,
Ron

On your previous posting of the same exact problem, people adviced to
use tools such as 'touch' and 'strace' in order to diagonise your
problem. It would have helped much if you had followed up on that and
not started a new thread. At least people who try to help would know
where they stand.

Regards.
 
R

Ron Eggler

On your previous posting of the same exact problem, people adviced to
use tools such as 'touch' and 'strace' in order to diagonise your
problem. It would have helped much if you had followed up on that and
not started a new thread. At least people who try to help would know
where they stand.

Right, I thought I'd start over again by better explaining my situation with
the target system. I didn't mention this in the other thread. I realized
that I had done it wrongly and started over again.
I'll now follow-up with red floyd's suggestion and will see how far I get
with that. I appreciate every kind of help!

Ron
 
R

Ron Eggler

red floyd wrote:

[snip]
Odds are good that errno is probably valid here, assuming you're using
gcc. Try adding:

#include <cerrno>
#include <cstdio>

at the top, and adding

std::cout << std::strerror(errno)

Hi Floyed,

This helped me alot, i changed my cout line to:
std::cout << "Cannot open reportfile:
\"/usr/share/NovaxTSP/INITreport.txt\". Error #:" << std::strerror(errno)
<< " Out: " << static_cast<bool>(out) << std::endl;
and this is what I got:
"Cannot open reportfile: "/usr/share/NovaxTSP/INITreport.txt". Error
#:Success Out: 0"
So I guess the if should be if (out< 0) to do the expected thing, right?
PS I tried to static cast out to int but it wouldn't compile and since it's
an if i thought I'd cast it to bool instead.

Thanks,
Ron
in your error message.
[snip]
 
R

Ron Eggler

Ron said:
red floyd wrote:

[snip]
Odds are good that errno is probably valid here, assuming you're using
gcc. Try adding:

#include <cerrno>
#include <cstdio>

at the top, and adding

std::cout << std::strerror(errno)

Hi Floyed,

This helped me alot, i changed my cout line to:
std::cout << "Cannot open reportfile:
\"/usr/share/NovaxTSP/INITreport.txt\". Error #:" << std::strerror(errno)
<< " Out: " << static_cast<bool>(out) << std::endl;
and this is what I got:
"Cannot open reportfile: "/usr/share/NovaxTSP/INITreport.txt". Error
#:Success Out: 0"
So I guess the if should be if (out< 0) to do the expected thing, right?
PS I tried to static cast out to int but it wouldn't compile and since
it's an if i thought I'd cast it to bool instead.
No,
not that simnple, I changed the if clause, ran it on the target and what I
get nothing doing a
/var/run/sbin # cat /usr/share/NovaxTSP/INITreport.txt
/var/run/sbin #
even tho it for sure would have written data in the file. Any other help?
I'm pretty onfused here....
Thanks,
Ron
in your error message.
[snip]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top