Block signals during writefile().

git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@239 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
Jilles Tjoelker 2004-02-17 00:53:28 +00:00
parent 90fdfa022c
commit 8769ab9e15

View File

@ -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)
{
sigprocmask(SIG_SETMASK, &oldmask, NULL);
graceful_exit (115); graceful_exit (115);
}
if (fcntl (fileno (fpl), F_SETLK, &fl)) if (fcntl (fileno (fpl), F_SETLK, &fl))
{
sigprocmask(SIG_SETMASK, &oldmask, NULL);
graceful_exit (107); 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)
{
sigprocmask(SIG_SETMASK, &oldmask, NULL);
graceful_exit (104); 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 */
{
fclose(fp);
fclose(fpl);
sigprocmask(SIG_SETMASK, &oldmask, NULL);
graceful_exit (116); graceful_exit (116);
} }
}
fclose (fp); fclose (fp);
fclose (fpl); fclose (fpl);
sigprocmask(SIG_SETMASK, &oldmask, NULL);
} }
/* ************************************************************* */ /* ************************************************************* */