Hello all,
I have some strange effects when writing to FIFOs from user space with
write(). When I am trying to write my data(a struct) to the FIFO, I get a
segmentation fault.
I got around this by doing
memset (&cfg, 0, sizeof (CONFIG_DATA));
at the beginning of the function. How can this be ? I thought the data I
pass to write is handled like a buffer with n Bytes, but if seg fault
happens, somebody has to be interpreting something here ?
I put some pieces of code below. Maybe somebody can tell me whats wrong
here, if not, i'll just do my memset :).
Thanks in advance,
Marco Schwarz.
The function that looks like follows:
int rtc_config_add_card (int nIfNr, int nBusType, int nPCIBus, int nPCISlot,
int nDeviceID, int nVendorID, int nRefreshTime,
RTC_RETURN *ret)
{
CONFIG_DATA cfg;
int nBytesRead, nBytesSent;
/* Segmentation fault if not set to 0 !!! */
memset (&cfg, 0, sizeof (CONFIG_DATA));
cfg.nConfigAction = CA_ADD_CARD;
cfg.nIfNr = nIfNr;
cfg.nBusType = nBusType;
cfg.nPCIBus = nPCIBus;
cfg.nPCISlot = nPCISlot;
cfg.nDeviceID = nDeviceID;
cfg.nVendorID = nVendorID;
cfg.nRefreshTime = nRefreshTime;
printf ("\nADD_CARD\n");
printf ("cfg.nIfNr: %d\n",cfg.nIfNr);
printf ("cfg.nBusTyp: %d\n",cfg.nBusType);
printf ("cfg.nPCIBus: %d\n",cfg.nPCIBus);
printf ("cfg.nPCISlot: %d\n",cfg.nPCISlot);
printf ("cfg.nDeviceID: %x\n",cfg.nDeviceID);
printf ("cfg.nVendorID: %x\n",cfg.nVendorID);
printf ("cfg.nRefreshTime: %d\n",cfg.nRefreshTime);
nBytesSent = write(nConfigSendFIFO, &cfg, sizeof(CONFIG_DATA));
nBytesRead = read(nConfigReceiveFIFO, ret, sizeof(RTC_RETURN));
if (nBytesRead == sizeof (CONFIG_DATA))
return 0;
else
return -1;
}
Structure definition:
typedef struct
{
/* Allg. Teil */
int nConfigAction;
/* Kartenkonfiguration */
int nIfNr;
int nBusType;
int nPCIBus;
int nPCISlot;
int nDeviceID;
int nVendorID;
int nRefreshTime;
/* Signalkonfiguration */
int nSigNr;
int nSigType;
int nSigVM;
int nSigVMGrad;
int nSigVI;
int nSigVIInc;
int nConvPar;
float fRangeMax;
float fRangeMin;
} CONFIG_DATA;
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/