LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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

Tags used in this thread
Popular LQ Tags ,

Reply
 
Thread Tools
Old 04-23-2009, 04:46 AM   #1
samarthya
LQ Newbie
 
Registered: Apr 2009
Posts: 1
Thanked: 0
Question fopen called in daemon fails on system reboot.


[Log in to get rid of this advertisement]

Hi!
I am facing a unusually simple problem with fopen(). The issue is when my daemon starts up with the machine and is forwarded a request from a client it fails to create a temporary file required to process the request. I located the issue with open with help of SYSLOG, now if i restart this daemon it starts working fine. Has anyone else faced it before?

I have set the permission using UMASK and also ensure the group id and session ID for the daemon.

The daemon tries to write a file under /root, which fails after machine reboot but succeeds when the daemon is explicitly restarted.

- Samarthya.
samarthya is offline  
Tag This Post ,
Reply With Quote
Old 04-23-2009, 08:24 PM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Slackware 12.1
Posts: 449
Thanked: 51
Two questions.
  1. Do you specify the file as, for example,
    Code:
    /root/fred.txt
    or do you specify it as
    Code:
    fred.txt
    expecting the current directory to be
    Code:
    /root
    ?

  2. What is the value of errno after the fopen() failure?
wje_lq is offline     Reply With Quote
Old 04-23-2009, 08:46 PM   #3
voyvf
LQ Newbie
 
Registered: Dec 2008
Distribution: Debian, Gentoo, FreeBSD, OpenBSD, Slackware, CentOS
Posts: 27
Thanked: 1
Posting the daemon section, as well as the fopen section of the code could be helpful, assuming you're not using the int daemon(int nochdir, int noclose); function from unistd.h.
voyvf is offline     Reply With Quote
Old 04-24-2009, 12:31 AM   #4
saurabh777
LQ Newbie
 
Registered: Oct 2003
Location: india...delhi
Distribution: 7.2
Posts: 3
Thanked: 0
Unhappy Absolute path.

I use absolute path
Code:
/root/a.txt
Even if i specify
Code:
./a.txt
is there an issue? because if i use
Code:
getcwd()
I get the /root as the current directory.

Thanks,
Samarthya
saurabh777 is offline     Reply With Quote
Old 04-24-2009, 01:42 AM   #5
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Slackware 12.1
Posts: 449
Thanked: 51
Please write a simple daemon which does this:
  1. Open the file, using the same fopen() statement that you use in the real daemon.
  2. If it succeeds, syslog that it succeeded.
  3. If it fails, syslog that it failed and syslog the errno.
Then try this daemon at system reboot and then restart it explicitly.

Do they both fail? Both succeed? One succeed, and one fail?
wje_lq is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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
nfs daemon fails freeindy Linux - Server 1 06-11-2008 05:47 AM
Ultrium 2 - multi-tape error (DUMP: fopen on /dev/tty fails: No such device or addres tbwalter55 Linux - Hardware 0 01-11-2007 10:28 AM
Mandriva 10.1 fails to reboot and shows "No reboot fixup found for your hardware" ROY913 Mandriva 1 12-12-2005 03:10 AM
fopen fails and returns err jackkerouac Programming 3 02-08-2005 10:22 PM
a CGI written in C, problem with an fopen() system call Sm0k3 Programming 2 10-03-2003 03:18 PM


All times are GMT -5. The time now is 02:18 PM.

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration