[HELP] Server crash on linux
#1

This commands are working on windows loaded pc, but doesn't on linux . It gives crash. anyone knows How to fix?

Code:
#define FILE_NAME "log/gravardata.txt"







public actualizardata(playerid)
{
  if(PlayerInfo[playerid][pPhousekey] == 255)
	{
	return 1;
    }
  if(PlayerInfo[playerid][pPhousekey] <11 )
	{
	return 1;
    }
  new chave;
  new str[128];
  new File:gstats;
  new day,month,year;
  getdate(day,month,year);
  chave = PlayerInfo[playerid][pPhousekey];
  format(str, sizeof(str), "Casa Nє%d",chave);
  fdeleteline(FILE_NAME,str);
  new sstr[128];
  format(sstr, sizeof(sstr), "Casa Nє%d Data: %d.%d.%d \r<br>\n",chave,day,month,year);
  gstats=fopen(FILE_NAME, io_append);
  fwrite(gstats, sstr);
  fclose(gstats);
  return 1;
}


stock fdeleteline(filename[], removed[])
{
    new string[64], str[32], File:handle, File:ftmp;
    handle = fopen(filename,io_read);
    format(str,sizeof(str),"%s.part",filename);
    ftmp = fopen(str,io_write);
    while(fread(handle,string))
        if(strfind(string,removed) == -1)
            fwrite(ftmp,string);
    fclose(handle);
    fclose(ftmp);
    handle = fopen(filename,io_write);
    ftmp = fopen(str,io_read);
    while(fread(ftmp,string))
        fwrite(handle,string);
    fclose(handle);
    fclose(ftmp);
    return fremove(str);
}
Reply
#2

If you use io_read and the file doesn't exist, the server will crash.

Add a check to confirm the file you're trying to open with fopen()'s io_read parameters actually exists.

Not sure if this crash is exclusive to Linux.

pawn Code:
stock fdeleteline(filename[], removed[])
{
    new string[64], str[32], File:handle, File:ftmp;
    if(fexist(filename)) handle = fopen(filename,io_read); else return 0;
    format(str,sizeof(str),"%s.part",filename);
    if(fexist(str)) ftmp = fopen(str,io_write); else return 0;
    while(fread(handle,string))
        if(strfind(string,removed) == -1)
            fwrite(ftmp,string);
    fclose(handle);
    fclose(ftmp);
    handle = fopen(filename,io_write);
    if(fexist(str)) ftmp = fopen(str,io_read); else return 0;
    while(fread(ftmp,string))
        fwrite(handle,string);
    fclose(handle);
    fclose(ftmp);
    return fremove(str);
}
Reply
#3

Files are cASe sEnSiTiVe. If you need to, look at this tutorial written by me: http:/wiki.sa-mp.com/wiki/Debugging
Reply
#4

im try only with the actualizardata(playerid) just for testing, and add if(!gstats) { fcreate(FILE_NAME); }
and the linux crashe again.




Code:
public actualizardata(playerid)
{
  if(PlayerInfo[playerid][pPhousekey] == 255)
	{
	return 1;
    }
  if(PlayerInfo[playerid][pPhousekey] <11 )
	{
	return 1;
    }
  new chave;
  new str[128];
  new File:gstats;
  new day,month,year;
  getdate(day,month,year);
  chave = PlayerInfo[playerid][pPhousekey];
  format(str, sizeof(str), "Casa Nє%d",chave);
  new sstr[128];
  format(sstr, sizeof(sstr), "Casa Nє%d Data: %d.%d.%d \r<br>\n",chave,day,month,year);
  gstats=fopen(FILE_NAME, io_append);
  if(!gstats) { fcreate(FILE_NAME); }
//  fdeleteline(FILE_NAME,str);
  fwrite(gstats, sstr);
  fclose(gstats);
  return 1;
}
Reply
#5

this simple code is crashing the server only in linux

Code:
if(strcmp(cmdtext, "/actualizardata", true) == 0)
	{

    actualizardata(playerid);
    SendClientMessage(playerid, COLOR_YELLOW, "actualizar");
    return 1;
	}




public actualizardata(playerid)
{
    new File:gstats;
    new pname[24];
    new str[256];
    new ccurdate = getdate();
    GetPlayerName(playerid, pname, 24);
    format(str, 30, "%s %d",pname,ccurdate);
    gstats=fopen(FILE_NAME, io_append);
    fwrite(gstats, str);
    fclose(gstats);
    return 1;
}
Reply
#6

Files are case sensitive
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)