How to init the SPI device in daemon?


 
Thread Tools Search this Thread
Top Forums Programming How to init the SPI device in daemon?
# 1  
Old 11-04-2011
How to init the SPI device in daemon?

I have to make a linux monitoring daemon that works with a SPI device (/dev/spidev). However, I always failed to init this SPI device. The return error code is 25, which means "inappropriate ioctl for device". As I know, daemon runs in background and doesn't have a control terminal and this might be the reason that caused SPI device failed to init.

If I make a similar program and run it manually under Linux shell then it can init the SPI device properly without any problem.

My question is: Is there a way to init the SPI device if I run my program as a daemon?

Thank you
# 2  
Old 11-04-2011
"inappropriate ioctl for device" is odd. Without seeing your actual code, we're only guessing what's going wrong, but if I had to guess -- it may not actually succeed in opening the device, doesn't check whether it did, and ends up doing ioctl() on FD 0 or somesuch. Which for a daemon probably ends up being /dev/null.
# 3  
Old 11-05-2011
Hi Corona,

Thanks for your suggestion. Here is the log from strace:

_newselect(0, NULL, NULL, NULL, {0, 16576}) = 0 (Timeout)
open("/dev/spidev0.0", O_RDWR) = 6
ioctl(6, 0x80406b00, 0x7f812fe0) = 4
time([987124305]) = 987124305
getpid() = 881
socket(PF_FILE, SOCK_DGRAM, 0) = 7
fcntl64(7, F_SETFD, FD_CLOEXEC) = 0
connect(7, {sa_family=AF_FILE, path="/dev/log"}, 16) = -1 ENOENT (No such file or directory)
close(7) = 0
time([987124305]) = 987124305
getpid() = 881
socket(PF_FILE, SOCK_DGRAM, 0) = 7
fcntl64(7, F_SETFD, FD_CLOEXEC) = 0
connect(7, {sa_family=AF_FILE, path="/dev/log"}, 16) = -1 ENOENT (No such file or directory)
close(7)


If I enable syslog, then here is the log from syslog:
Apr 13 01:20:23 UNKNOWN[881]: -----------------------------------
Apr 13 01:20:23 UNKNOWN[881]: SPIRead:467 Error No. [25], Error: [Inappropriate ioctl for device]
Apr 13 01:20:23 UNKNOWN[881]: -----------------------------------
Apr 13 01:20:23 UNKNOWN[881]: _IOC_NR(SPI_IOC_MESSAGE( 0)) 0
Apr 13 01:20:23 UNKNOWN[881]: _IOC_NR(SPI_IOC_MESSAGE(1)) 0
Apr 13 01:20:23 UNKNOWN[881]: _IOC_NR(SPI_IOC_MESSAGE(2)) 0
Apr 13 01:20:23 UNKNOWN[881]: _IOC_DIR(SPI_IOC_MESSAGE(2)) 4
Apr 13 01:20:23 UNKNOWN[881]: _IOC_WRITE 4


Do you have any comment on this?
# 4  
Old 11-08-2011
From man ioctl:

Code:
RETURN VALUE
       Usually, on success zero is returned.  A few ioctl() requests  use  the
       return  value  as an output parameter and return a nonnegative value on
       success.  On error, -1 is returned, and errno is set appropriately.

Again, without seeing your code, I'm only guessing, but your code may be incorrectly assuming all nonzero return values mean error, not just negative returns.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. HP-UX

Failed to open tape device /dev/rmt/0mn:Device busy (errno = 16)

Hi, Unable to make tape backup, please help. /opt/ignite/bin/make_tape_recovery -a /dev/rmt/?mn -I -v -m tar -x inc_entire=vg00 * Creating local directories for configuration files and archive. ======= 04/25/16 16:28:08 IST Started /opt/ignite/bin/make_tape_recovery. (Mon... (4 Replies)
Discussion started by: anuragr
4 Replies

2. Red Hat

Device-mapper behaviour booting on init=bin/bash

Good morning Recently we needed to change the password from a redhat 6.5 system that no one knew the root password. Starting the system with the init=/bin/bash method took us to the following scenario: system_vg active with only root_lv and tmpfs mounted. our entries at fstab are like... (1 Reply)
Discussion started by: Ikaro0
1 Replies

3. Red Hat

Unable To Activate Ethernet Network Device in RHEL 5.5 - e100 device eth0 does not seem to be presen

Hi All, Could anyone please help to resolve the below problem. I installed RHEL5.5 in my desktop.But when i try to activate the ethernet connection then it gives me the error. I spent 2 days for the above and go through with several suggestion found by googling. But no luck. ... (0 Replies)
Discussion started by: Tanmoy
0 Replies

4. Red Hat

init-script failing because of /etc/rc.d/init.d/functions

I encountered a problem on one of our database servers. OS: CentOS 5.5 final Kernel: 2.6.18-238.5.1.el5.028stab085.2 (OpenVZ kernel) We wrote some DB-Start/Stop-scripts ("/db2/admin/scripts_dba/start_services.ksh" and ".../stop_services.ksh") to start the database instances. (Database... (1 Reply)
Discussion started by: bakunin
1 Replies

5. Solaris

What is the diffe b/w init s and init S

i did my research in finding the answer but couldn't find right one. Please give your inputs. (6 Replies)
Discussion started by: ranumala
6 Replies

6. UNIX for Advanced & Expert Users

Problem on init 0, execution is the same with init 6

Hi, I am experiencing a weird thing on my SUNFIRE machine with Solaris 9 OS. When I do init 0 to shutdown the machine to go to ok prompt, what it did was shutdown and reboot like an init 6 command do. I did check the corresponding rc scripts that were involved with init 0 and compared with rc... (2 Replies)
Discussion started by: Yenthanh
2 Replies

7. Red Hat

Difference between 'init s' and 'init 1'

What is the difference between 'init s' and 'init 1'. I know that both will work to change the current run level to single user mode. Is there any difference in those two commands? (5 Replies)
Discussion started by: praveen_b744
5 Replies

8. Linux

How to I change init levels after typing init 1

Dear all, I typed in init 1 on my redhat box as root and according to wikipedia (http://en.wikipedia.org/wiki/Runlevel): 1 Single-User Mode Does not configure network interfaces, start daemons, or allow non-root logins So now I can't connect back to it. How do I change the init back to 3?... (8 Replies)
Discussion started by: z1dane
8 Replies

9. UNIX for Advanced & Expert Users

Init 6 & Init 0 problem

Hi Expert, I have encountered some problem with my SUN system. Everytime when i issue command #init 6 OR #init 0 it just logout and prompt for login again instead of rebooting the server when run init 6 and system shutdown when run init 0.. I can only reboot the system using reboot ... Was... (6 Replies)
Discussion started by: sc2005
6 Replies
Login or Register to Ask a Question