Nп/п : 21 из 100
 От   : The Natural Philosopher             2:5075/128        15 сен 23 11:19:11
 К    : Ralf Fassel                                           15 сен 23 13:21:04
 Тема : Re: Weird code crash
----------------------------------------------------------------------------------
                                                                                 
@MSGID: 1@dont-email.me> f6ddb83e
@REPLY: <ygail8biyxm.fsf@akutech.de> 1727fb9c
@REPLYADDR The Natural Philosopher
<tnp@invalid.invalid>
@REPLYTO 2:5075/128 The Natural Philosopher
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: 1@dont-email.me>
@RFC-References: 1@dont-email.me>
<ygamsxoixhx.fsf@akutech.de> 4@dont-email.me> <ygail8biyxm.fsf@akutech.de>
@TZUTC: 0100
@PID: Mozilla/5.0 (X11; Linux x86_64; rv:102.0)
Gecko/20100101 Thunderbird/102.15.1
@TID: FIDOGATE-5.12-ge4e8b94
On 15/09/2023 10:11, Ralf Fassel wrote:
> * The Natural Philosopher <tnp@invalid.invalid>
> | On 14/09/2023 16:29, Ralf Fassel wrote:
> | > * The Natural Philosopher <tnp@invalid.invalid>
> | > | One possibility is that it is opening and reading a file at the
> | > | precise time another process is writing it...in both cases the read
> | > | and write
> | > | operations are atomic and done with C code.
> | >>
> | > | READ
> | > | ====
> | > | fp=fopen(fullname, "r");
> | > | len=fread(filbuf,1,255,fp); // read entire file
> | > Check for fp != NULL is missing here in this example code before
> | > fread().  If this also in the production version, it might be a problem
> | > if the file is not accessible for any reason.
> | > R`
> | Ralf, I already put that in this morning, re compiled the code and
> | after an hour, it crashed again.
>>
> | The filename is built by scanning a directory so the filename must exist.

> That assumption does not hold.  Since scanning and opening are separated
> by a time gap (albeit a `small` one), there is a non-zero chance that
> the file vanished between scan and open.

> Further possibilities:
> - how is `filbuf` used after the fread()?  If you use it as C-string, make
>    sure it is 0-terminated (fread() won`t do that for you).  Maybe use
>    fgets(3) instead?


dir = opendir(VOLATILE_DIR);

if(!dir)
return;
while ((dp = readdir (dir)) != NULL)
{
filename=dp->d_name;
// skip known bollocks
if(!strcmp(filename, "." ) || !strcmp(filename, ".." ) || 
!strcmp(filename, "relays.dat" ))
continue;
// construct full path
sprintf(fullname,"%s/%s",VOLATILE_DIR,filename);
stat(fullname,&stats);// get tfile times
if(time(NULL)-stats.st_ctime >1800) // skip files older than half an hour
continue;
len=strlen(filename);
if(strncmp(filename+len-4, ".dat",4)) // .dat file but not relays.dat
continue;
fp=fopen(fullname, "r");
if(fp==0) //file has disappeared?
continue;
len=fread(filbuf,1,255,fp);
if(len==0) // file has zero length
goto baddata;
filbuf[len]=0;
if(len=strncmp(filbuf,"ZONE",4)) //supposed to reject a file whose 
contents do not start with ZONE
goto baddata;

// looking very much like a temperature file
i=(int)filbuf[4] -`1`; // this is our zone from "ZONE2" etc. 1-4 is 
zone but index is 0-3 so subtract `1`
p=strstr(filbuf,"
");
if(p)
{
p++;
if(q=strstr(p,"
"))
{
*q++=0;
thermometers[i].name=strdup(p); // make a copy of the name and 
attach it to our thermometer structure
p=q;
}
else goto baddata;
// now to fetch the temp data.
if(q=strstr(p,"
"))
{
*q++=0;
thermometers[i].temp=atof(p);
p=q;
}
else goto baddata;
// what`s left is the voltage. To hell with any crap after it
thermometers[i].battery=atof(p);
}
baddata:fclose(fp);
} // end of directory scan loop
> | I am leaning towards possibly a cracked solder joint or board.

> Well, since the Raspi is cheap, that should be easily checked by simply
> using another one.  I bet 1 beer that it is *not* a cracked board, since
> with that many more processes should run into trouble, not only this
> particular one.

> R` (.sig not from me .-)

-- 
There is something fascinating about science. One gets such wholesale 
returns of conjecture out of such a trifling investment of fact.

Mark Twain

 --- Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
 * Origin: A little, after lunch (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх