Function crash the server.
#1

Hi. I have this function make my server crash.
PHP код:
WriteLogs(const playername[], file[30], const author[], const reason[], const other[])
{
    static 
daymonthhourminutesecondeyearstringW[190];
    if(
strfind(file".log"false0) == -1format(filesizeof(file), "%s.log"file);
    
format(filesizeof(file), "/Logs/%s"file);
    new 
File:pos=fopen(fileio_append);
    
gettime(hourminuteseconde);
    
getdate(yearmonthday);
    
format(stringW,sizeof(stringW),"\r\n[%02i/%02i/%02i] %02i:%02i:%02i | %s %s %s : %s"daymonthyearhourminutesecondeauthorreasonplayernameother);
    
fwrite(pos,stringW);
    
fclose(pos);

Function which is calling WriteLogs.
PHP код:
ResetSetData(setid, const reason[])
{
    
printf("[Debut]ResetSetData %i"setid);
    new 
INI:File INI_Open(DMSetPath(setid));
    
INI_SetTag(File"Weapons");
    
INI_WriteString(File"Name"DMWeapons[setid][sName]);
       
INI_WriteInt(File,"Weapon1",DMWeapons[setid][sWeapon1]);
       
INI_WriteInt(File,"Weapon2",DMWeapons[setid][sWeapon2]);
       
INI_WriteInt(File,"Weapon3",DMWeapons[setid][sWeapon3]);
       
INI_WriteInt(File,"Weapon4",DMWeapons[setid][sWeapon4]);
    
INI_WriteFloat(File,"Version"DMWeapons[setid][sVersion]);
       
INI_Close(File);
       
    
printf("[FS] ResetSetData | Set %i | Rewrote | [Reason : %s]"setidreason);
    static 
str[90];
    
format(strsizeof(str), "SetID: %i"setid);
    
WriteLogs(str"LOG_DM_System""SERVER""REWROTE SET DATA [Reset Set Data]"reason); // THERE IS THE LINE MAKING CRASH THE SERVER
    
printf("[FS] ResetSetData | Set %i | End"setidreason);
    return 
1;

I call ResetSetData a first time, all is working. I call it a second time, the server crash.
Help is appreciate.
Best regards.
Reply
#2

Are you sure that you have a folder "Logs" inside scriptfiles foldier?
Reply
#3

Yes there is a folder. Like I said, this is working a first time and the file is correctly create.
Reply
#4

Make also sure that "pos" returned by fopen is not 0 otherwise using it to file functions such as fwrite and fclose will crash the server.

Always have crashdetect plugin loaded to get information directly than guessing.

A suggestion as well if you are interested: https://sampforum.blast.hk/showthread.php?tid=603175
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Make also sure that "pos" returned by fopen is not 0 otherwise using it to file functions such as fwrite and fclose will crash the server.

Always have crashdetect plugin loaded to get information directly than guessing.

A suggestion as well if you are interested: https://sampforum.blast.hk/showthread.php?tid=603175
What do you mean by "pos" ?



Alright, installed crashdetect plugin :
PHP код:
[17:58:13] [debugServer crashed while executing fs.amx
[17:58:13] [debugAMX backtrace:
[
17:58:13] [debug#0 native fwrite () from samp-server.exe
[17:58:13] [debug#1 00029dbc in ?? (17393428, 17393828, 17393884, 17393912, 17412996) from fs.amx
[17:58:13] [debug#2 0002944c in ?? (1, 17412996) from fs.amx
[17:58:13] [debug#3 00022d80 in public cmd_resetsetdata (0, 17396976) from fs.amx
[17:58:13] [debug#4 native CallLocalFunction () from samp-server.exe
[17:58:13] [debug#5 00000664 in public OnPlayerCommandText (0, 17396912) from fs.amx
[17:58:13] [debugNative backtrace:
[
17:58:13] [debug#0 77040d72 in ?? () from C:\Windows\SYSTEM32\ntdll.dll
[17:58:13] [debug#1 00498bb8 in ?? () from samp-server.exe
[17:58:13] [debug#2 0040531e in ?? () from samp-server.exe
[17:58:13] [debugServer crashed while executing fs.amx
[17:58:13] [debugAMX backtrace:
[
17:58:13] [debug#0 native fwrite () from samp-server.exe
[17:58:13] [debug#1 00029dbc in public cmd_resetsetdata (0, 17396912) from fs.amx
[17:58:13] [debug#2 native CallLocalFunction () from samp-server.exe
[17:58:13] [debug#3 00000664 in public OnPlayerCommandText (0, 17396912) from fs.amx
[17:58:13] [debugNative backtrace:
[
17:58:13] [debug#0 77041e49 in ?? () from C:\Windows\SYSTEM32\ntdll.dll
[17:58:13] [debug#1 77041c6a in ?? () from C:\Windows\SYSTEM32\ntdll.dll
[17:58:13] [debug#2 00498e11 in ?? () from samp-server.exe
[17:58:13] [debug#3 0044d9c9 in ?? () from samp-server.exe
[17:58:13] [debug#4 0045856c in ?? () from samp-server.exe
[17:58:13] [debug#5 0045ad2a in ?? () from samp-server.exe
[17:58:13] [debug#6 61c07c09 in ?? () from plugins\crashdetect.dll
[17:58:13] [debug#7 75f02cc7 in ?? () from C:\Windows\SYSTEM32\KERNELBASE.dll
[17:58:13] [debug#8 75f02ce8 in ?? () from C:\Windows\SYSTEM32\KERNELBASE.dll 
Reply
#6

It's crashing on fwrite so maybe the file doesn't exist try this...

PHP код:
WriteLogs(const playername[], file[30], const author[], const reason[], const other[])
{
    static 
daymonthhourminutesecondeyearstringW[190];
    if(
strfind(file".log"false0) == -1format(filesizeof(file), "%s.log"file);
    
format(filesizeof(file), "/Logs/%s"file);
    if(!
fexist(file)) {
       new 
File:pos=fopen(fileio_write);
       
fclose(pos);
    }
    new 
File:pos=fopen(fileio_append);
    
gettime(hourminuteseconde);
    
getdate(yearmonthday);
    
format(stringW,sizeof(stringW),"\r\n[%02i/%02i/%02i] %02i:%02i:%02i | %s %s %s : %s"daymonthyearhourminutesecondeauthorreasonplayernameother);
    
fwrite(pos,stringW);
    
fclose(pos);

Reply
#7

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
What do you mean by "pos" ?
Код:
new File:pos=fopen(file, io_append);
if the value of "pos" variable is 0 and is used in fwrite will crash the server. To prevent it:
pawn Код:
new File:pos=fopen(file, io_append);
if (!pos) return;
but since it won't open the file, it won't write either. You may as well add return values like if pos is 0, return 0 otherwise 1 and if you do:
pawn Код:
if (!WriteLogs(...)) ...
you can print in the console that it failed to open the file etc.
Reply
#8

You must set the permissions to 777, so it will manage to write into the file

There is an option to filezilla with right click, you will find it then set it to 777
Reply
#9

Quote:
Originally Posted by SecretBoss
Посмотреть сообщение
You must set the permissions to 777, so it will manage to write into the file

There is an option to filezilla with right click, you will find it then set it to 777
Local server.

Quote:
Originally Posted by jlalt
Посмотреть сообщение
It's crashing on fwrite so maybe the file doesn't exist try this...

PHP код:
WriteLogs(const playername[], file[30], const author[], const reason[], const other[])
{
    static 
daymonthhourminutesecondeyearstringW[190];
    if(
strfind(file".log"false0) == -1format(filesizeof(file), "%s.log"file);
    
format(filesizeof(file), "/Logs/%s"file);
    if(!
fexist(file)) {
       new 
File:pos=fopen(fileio_write);
       
fclose(pos);
    }
    new 
File:pos=fopen(fileio_append);
    
gettime(hourminuteseconde);
    
getdate(yearmonthday);
    
format(stringW,sizeof(stringW),"\r\n[%02i/%02i/%02i] %02i:%02i:%02i | %s %s %s : %s"daymonthyearhourminutesecondeauthorreasonplayernameother);
    
fwrite(pos,stringW);
    
fclose(pos);

Now it's crashing on fclose. Put a print before fclose.
PHP код:
[18:09:04fclose inc.
[
18:09:04] [debugServer crashed while executing dmsystem.amx
[18:09:04] [debugAMX backtrace:
[
18:09:04] [debug#0 native fclose () from samp-server.exe
[18:09:04] [debug#1 00029d1c in ?? (17393428, 17393828, 17393884, 17393912, 17413044) from dmsystem.amx
[18:09:04] [debug#2 0002944c in ?? (0, 17413044) from dmsystem.amx
[18:09:04] [debug#3 00022d80 in public cmd_resetsetdata (0, 17397024) from dmsystem.amx
[18:09:04] [debug#4 native CallLocalFunction () from samp-server.exe
[18:09:04] [debug#5 00000664 in public OnPlayerCommandText (0, 17396960) from dmsystem.amx
[18:09:04] [debugNative backtrace:
[
18:09:04] [debug#0 0049939b in ?? () from samp-server.exe
[18:09:04] [debug#1 004056cd in ?? () from samp-server.exe
[18:09:04] [debug#2 637b62ca in ?? () from plugins\crashdetect.dll
[18:09:04] [debug#3 637b8b28 in ?? () from plugins\crashdetect.dll
[18:09:04] [debug#4 637b09c7 in ?? () from plugins\crashdetect.dll
[18:09:04] [debug#5 637b631a in ?? () from plugins\crashdetect.dll
[18:09:04] [debug#6 004746be in ?? () from samp-server.exe
[18:09:04] [debug#7 004010b6 in ?? () from samp-server.exe
[18:09:04] [debug#8 637b62ca in ?? () from plugins\crashdetect.dll
[18:09:04] [debug#9 637b8b28 in ?? () from plugins\crashdetect.dll
[18:09:04] [debug#10 637b09c7 in ?? () from plugins\crashdetect.dll
[18:09:04] [debug#11 637b631a in ?? () from plugins\crashdetect.dll
[18:09:04] [debug#12 0046b168 in ?? () from samp-server.exe 
Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Код:
new File:pos=fopen(file, io_append);
if the value of "pos" variable is 0 and is used in fwrite will crash the server. To prevent it:
pawn Код:
new File:pos=fopen(file, io_append);
if (!pos) return;
but since it won't open the file, it won't write either. You may as well add return values like if pos is 0, return 0 otherwise 1 and if you do:
pawn Код:
if (!WriteLogs(...)) ...
you can print in the console that it failed to open the file etc.
Alright, I'll try it soon.

Thanks all for your help.
Reply
#10

It's solved! Thanks all.
PHP код:
WriteLogs(static playername[], file[70], static author[], static reason[], static other[])
{
    static 
daymonthhourminutesecondeyearstringW[190], path[90];
    if(
strfind(file".txt"false0) == -1format(filesizeof(file), "%s.txt"file);
    
format(pathsizeof(path), "/Logs/%s"file);
    new 
File:pos=fopen(pathio_append);
    if(!
pos) return printf("[FS] Write Logs Error | Reason : pos=fopen Error | %s"path), 1;
    
gettime(hourminuteseconde);
    
getdate(yearmonthday);
    
format(stringW,sizeof(stringW),"\r\n[%02i/%02i/%02i] %02i:%02i:%02i | %s %s %s : %s"daymonthyearhourminutesecondeauthorreasonplayernameother);
    
fwrite(pos,stringW);
    
fclose(pos);
    return 
1;

Path problem.

EDIT: I'm fucking retarded, solved again.
EDIT2: Solved.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)