mirror of
https://github.com/paxed/dgamelaunch.git
synced 2025-07-31 01:24:43 +02:00
Block signals during writefile().
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@239 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
parent
90fdfa022c
commit
8769ab9e15
@ -1285,17 +1285,31 @@ writefile (int requirenew)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
int my_done = 0;
|
int my_done = 0;
|
||||||
struct flock fl = { 0 };
|
struct flock fl = { 0 };
|
||||||
|
sigset_t oldmask, toblock;
|
||||||
|
|
||||||
fl.l_type = F_WRLCK;
|
fl.l_type = F_WRLCK;
|
||||||
fl.l_whence = SEEK_SET;
|
fl.l_whence = SEEK_SET;
|
||||||
fl.l_start = 0;
|
fl.l_start = 0;
|
||||||
fl.l_len = 0;
|
fl.l_len = 0;
|
||||||
|
|
||||||
|
sigemptyset(&toblock);
|
||||||
|
sigaddset(&toblock, SIGHUP);
|
||||||
|
sigaddset(&toblock, SIGINT);
|
||||||
|
sigaddset(&toblock, SIGQUIT);
|
||||||
|
sigaddset(&toblock, SIGTERM);
|
||||||
|
sigprocmask(SIG_BLOCK, &toblock, &oldmask);
|
||||||
|
|
||||||
fpl = fopen (myconfig->lockfile, "r+");
|
fpl = fopen (myconfig->lockfile, "r+");
|
||||||
if (!fpl)
|
if (!fpl)
|
||||||
graceful_exit (115);
|
{
|
||||||
|
sigprocmask(SIG_SETMASK, &oldmask, NULL);
|
||||||
|
graceful_exit (115);
|
||||||
|
}
|
||||||
if (fcntl (fileno (fpl), F_SETLK, &fl))
|
if (fcntl (fileno (fpl), F_SETLK, &fl))
|
||||||
graceful_exit (107);
|
{
|
||||||
|
sigprocmask(SIG_SETMASK, &oldmask, NULL);
|
||||||
|
graceful_exit (107);
|
||||||
|
}
|
||||||
|
|
||||||
fl.l_type = F_UNLCK;
|
fl.l_type = F_UNLCK;
|
||||||
|
|
||||||
@ -1304,7 +1318,10 @@ writefile (int requirenew)
|
|||||||
|
|
||||||
fp = fopen (myconfig->passwd, "w");
|
fp = fopen (myconfig->passwd, "w");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
graceful_exit (104);
|
{
|
||||||
|
sigprocmask(SIG_SETMASK, &oldmask, NULL);
|
||||||
|
graceful_exit (104);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < f_num; i++)
|
for (i = 0; i < f_num; i++)
|
||||||
{
|
{
|
||||||
@ -1314,6 +1331,9 @@ writefile (int requirenew)
|
|||||||
{
|
{
|
||||||
/* this is if someone managed to register at the same time
|
/* this is if someone managed to register at the same time
|
||||||
* as someone else. just die. */
|
* as someone else. just die. */
|
||||||
|
fclose(fp);
|
||||||
|
fclose(fpl);
|
||||||
|
sigprocmask(SIG_SETMASK, &oldmask, NULL);
|
||||||
graceful_exit (111);
|
graceful_exit (111);
|
||||||
}
|
}
|
||||||
fprintf (fp, "%s:%s:%s:%s\n", me->username, me->email, me->password,
|
fprintf (fp, "%s:%s:%s:%s\n", me->username, me->email, me->password,
|
||||||
@ -1332,11 +1352,18 @@ writefile (int requirenew)
|
|||||||
fprintf (fp, "%s:%s:%s:%s\n", me->username, me->email, me->password,
|
fprintf (fp, "%s:%s:%s:%s\n", me->username, me->email, me->password,
|
||||||
me->env);
|
me->env);
|
||||||
else /* Oops, someone else registered the last available slot first */
|
else /* Oops, someone else registered the last available slot first */
|
||||||
graceful_exit (116);
|
{
|
||||||
|
fclose(fp);
|
||||||
|
fclose(fpl);
|
||||||
|
sigprocmask(SIG_SETMASK, &oldmask, NULL);
|
||||||
|
graceful_exit (116);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
fclose (fpl);
|
fclose (fpl);
|
||||||
|
|
||||||
|
sigprocmask(SIG_SETMASK, &oldmask, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************* */
|
/* ************************************************************* */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user