LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-29-2009, 01:31 AM   #1
Kenarkies
Member
 
Registered: Nov 2007
Location: South Australia
Distribution: Ubuntu 11.10
Posts: 81

Rep: Reputation: 23
C programming problem, fopen() cannot find existing file


Hi All

In a related post (http://www.linuxquestions.org/questi...d.php?t=739985) I started offering advice to someone having trouble compiling a program called symon (system monitoring). This program was ported over from BSD and the makefiles are written for pmake (which we had to scrounge). It looks in some /proc files to grab various information and statistics. We got it to compile but when run it complained that it could not open any files, such as /proc/stat, /proc/meminfo, returning the error "No such file or directory".

The program is written in C and the original program uses what looks like a very basic code segment, for example from the platform/Linux/sm_mem.c file:

Code:
   int fd;
   if ((fd = open("/proc/meminfo", O_RDONLY)) < 0) {
        warning("cannot access /proc/meminfo: %.200s", strerror(errno));
   }
The open() function is not ANSI standard so I tried things like

Code:
    FILE * fd;
    char * filename;
    filename = "/proc/meminfo";
    if ((fd = fopen(filename, "r")) == NULL) {
        warning("sm:mem: cannot access %.200s: %.200s", filename, strerror(errno));
    }
I also tried real files in various directories. The source is readily available from the Symon site.

After pmake install, it is run under root with

Code:
symon -d
It needs a config file /etc/symon.conf such as

Code:
     monitor { cpu(0),  mem
            } stream to 127.0.0.1 2100
I'm not versed in C and basically I'm completely stuck. Can anyone offer some guidance as to what might be going on here.

Many thanks
Ken
 
Old 07-29-2009, 02:04 AM   #2
Kenarkies
Member
 
Registered: Nov 2007
Location: South Australia
Distribution: Ubuntu 11.10
Posts: 81

Original Poster
Rep: Reputation: 23
Some more info: pmake version is pmake-1.45-16 found as a Centos4 rpm. src rpms are available but we didn't try compiling it. We have tried this process on Fedora 10 x86_64 and Centos 5.3 i386.

Ken
 
Old 07-30-2009, 02:59 AM   #3
Kenarkies
Member
 
Registered: Nov 2007
Location: South Australia
Distribution: Ubuntu 11.10
Posts: 81

Original Poster
Rep: Reputation: 23
Problem "solved", I think. The program moved to a chroot jail. Being ported from FreeBSD it appears that chroot in that environment is different to that in Linux, and reproduces the /proc directories.

If I'm wrong, please let me know.

Ken
 
  


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
my c programming crashes on call of fopen amolgupta Programming 2 12-28-2008 12:35 PM
fopen 2 gb file schneidz Programming 5 10-26-2007 11:24 AM
fopen a file in home directory Four Programming 2 04-07-2007 05:52 PM
fopen: No such file or directory CatBreath Linux - Software 4 03-27-2005 07:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:08 AM.

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