Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 04-23-2009, 03:46 AM   #1
LQ Newbie
Registered: Apr 2009
Posts: 1

Rep: Reputation: 0
Question fopen called in daemon fails on system reboot.

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.
Old 04-23-2009, 07:24 PM   #2
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 178Reputation: 178
Two questions.
  1. Do you specify the file as, for example,
    or do you specify it as
    expecting the current directory to be

  2. What is the value of errno after the fopen() failure?
Old 04-23-2009, 07:46 PM   #3
LQ Newbie
Registered: Dec 2008
Distribution: Debian, Gentoo, FreeBSD, OpenBSD, Slackware, CentOS
Posts: 27

Rep: Reputation: 16
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.
Old 04-23-2009, 11:31 PM   #4
LQ Newbie
Registered: Oct 2003
Location: india...delhi
Distribution: 7.2
Posts: 3

Rep: Reputation: 0
Unhappy Absolute path.

I use absolute path
Even if i specify
is there an issue? because if i use
I get the /root as the current directory.

Old 04-24-2009, 12:42 AM   #5
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 178Reputation: 178
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?


daemon, fopen

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

All times are GMT -5. The time now is 12:21 PM.

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