mirror of
https://github.com/EnergyMech/energymech.git
synced 2025-12-17 15:36:50 +00:00
safer sessionsaving
This commit is contained in:
parent
a882fe9b6e
commit
1a72d7c537
3
VERSIONS
3
VERSIONS
@ -1,5 +1,8 @@
|
|||||||
3.1 -- WORK IN PROGRESS (~May, 2018)
|
3.1 -- WORK IN PROGRESS (~May, 2018)
|
||||||
|
|
||||||
|
* Changed: Session config is saved to "filename.sessiontemp" and once the save is complete
|
||||||
|
its moved to "filename.session", just in case something happens that might create a corrupt
|
||||||
|
session file (eg, SIGSEGV).
|
||||||
* Added: SERVERSILENCETIMEOUT, maximum idle timer for server connection. in case of lost FIN packets
|
* Added: SERVERSILENCETIMEOUT, maximum idle timer for server connection. in case of lost FIN packets
|
||||||
* Fixed: Compiles clean with -std=c89
|
* Fixed: Compiles clean with -std=c89
|
||||||
* Added: $guid to esay variables
|
* Added: $guid to esay variables
|
||||||
|
|||||||
@ -148,7 +148,8 @@ int write_session(void)
|
|||||||
UniVar *varval;
|
UniVar *varval;
|
||||||
int j,sf;
|
int j,sf;
|
||||||
|
|
||||||
if ((sf = open(SESSIONFILE,O_WRONLY|O_CREAT|O_TRUNC,NEWFILEMODE)) < 0)
|
/* save to filename.sessiontemp at first, in case SIGSEGV happens */
|
||||||
|
if ((sf = open(SESSIONTEMPFILE,O_WRONLY|O_CREAT|O_TRUNC,NEWFILEMODE)) < 0)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
|
|
||||||
#ifdef RAWDNS
|
#ifdef RAWDNS
|
||||||
@ -311,6 +312,8 @@ int write_session(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
close(sf);
|
close(sf);
|
||||||
|
unlink(SESSIONFILE);
|
||||||
|
rename(SESSIONTEMPFILE,SESSIONFILE);
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,16 @@
|
|||||||
#define LS /* nothing */
|
#define LS /* nothing */
|
||||||
#endif /* LIBRARY */
|
#endif /* LIBRARY */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* startup ==
|
||||||
|
*/
|
||||||
|
#define STARTUP_RUNNING 0
|
||||||
|
#define STARTUP_ECHOTOCONSOLE (startup > 1 && startup < 1000)
|
||||||
|
#define STARTUP_COMMANDANDEXIT 3
|
||||||
|
#define STARTUP_TESTRUN 6
|
||||||
|
#define STARTUP_NORMALSTART 1000
|
||||||
|
#define STARTUP_SIGSEGV 31337
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Channel Crap
|
* Channel Crap
|
||||||
*/
|
*/
|
||||||
|
|||||||
2
src/io.c
2
src/io.c
@ -355,7 +355,7 @@ void to_user_q(const char *target, const char *format, ...)
|
|||||||
|
|
||||||
stringcat(message,"\n");
|
stringcat(message,"\n");
|
||||||
|
|
||||||
if (startup > 0)
|
if (STARTUP_ECHOTOCONSOLE)
|
||||||
{
|
{
|
||||||
write(1,message,strlen(message));
|
write(1,message,strlen(message));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -448,6 +448,7 @@ void sig_segv(int crap, siginfo_t *si, void *uap)
|
|||||||
greg_t *rsp,*rip; /* general registers */
|
greg_t *rsp,*rip; /* general registers */
|
||||||
|
|
||||||
time(&now);
|
time(&now);
|
||||||
|
startup = STARTUP_SIGSEGV;
|
||||||
|
|
||||||
debug("(sigsegv) trying to access "mx_pfmt"\n",(mx_ptr)si->si_addr);
|
debug("(sigsegv) trying to access "mx_pfmt"\n",(mx_ptr)si->si_addr);
|
||||||
mctx = &((ucontext_t *)uap)->uc_mcontext;
|
mctx = &((ucontext_t *)uap)->uc_mcontext;
|
||||||
@ -919,6 +920,7 @@ int main(int argc, char **argv, char **envp)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
uptime = time(&now);
|
uptime = time(&now);
|
||||||
|
startup = STARTUP_NORMALSTART;
|
||||||
|
|
||||||
if ((getuid() == 0) || (geteuid() == 0))
|
if ((getuid() == 0) || (geteuid() == 0))
|
||||||
{
|
{
|
||||||
@ -1060,7 +1062,7 @@ int main(int argc, char **argv, char **envp)
|
|||||||
to_file(1,"error: Missing argument for -e <command string>\n");
|
to_file(1,"error: Missing argument for -e <command string>\n");
|
||||||
_exit(0);
|
_exit(0);
|
||||||
case 't':
|
case 't':
|
||||||
startup = 666;
|
startup = STARTUP_TESTRUN;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
if (opt[2] != 0)
|
if (opt[2] != 0)
|
||||||
@ -1276,12 +1278,12 @@ int main(int argc, char **argv, char **envp)
|
|||||||
monitor_fs(executable);
|
monitor_fs(executable);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (startup == 666)
|
if (startup == STARTUP_TESTRUN)
|
||||||
{
|
{
|
||||||
to_file(1,"init: test run completed, exiting...\n");
|
to_file(1,"init: test run completed, exiting...\n");
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
startup = FALSE;
|
startup = STARTUP_RUNNING;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
debug("(main) entering doit()...\n");
|
debug("(main) entering doit()...\n");
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user