int fd;
struct flock fl = { 0 };
- snprintf(pidbuf, 16, "%.15d", pid);
-
+ snprintf (pidbuf, 16, "%.15d", pid);
+
fl.l_type = F_WRLCK;
fl.l_whence = SEEK_SET;
fl.l_start = 0;
if (fcntl (fd, F_SETLKW, &fl) == -1)
graceful_exit (68);
- write(fd, pidbuf, strlen(pidbuf));
+ write (fd, pidbuf, strlen (pidbuf));
}
/* ************************************************************* */
while ((pdirent = readdir (pdir)))
{
- if (!strcmp (pdirent->d_name, ".") || !strcmp(pdirent->d_name, ".."))
- continue;
+ if (!strcmp (pdirent->d_name, ".") || !strcmp (pdirent->d_name, ".."))
+ continue;
snprintf (fullname, 130, "%s%s", LOC_INPROGRESSDIR, pdirent->d_name);
/* O_RDWR here should be O_RDONLY, but we need to test for
* an exclusive lock */
fd = open (fullname, O_RDWR);
- if ((fd > 0) && fcntl(fd, F_SETLK, &fl) == -1)
+ if ((fd > 0) && fcntl (fd, F_SETLK, &fl) == -1)
{
/* stat to check idle status */
refresh ();
endwin ();
ttyplay_main (ttyrecname, 1, 0);
- initncurses();
+ initncurses ();
}
}
time_t now;
int mail_empty = 1;
struct flock fl = { 0 };
-
+
fl.l_type = F_WRLCK;
fl.l_whence = SEEK_SET;
fl.l_start = 0;
refresh ();
while (fcntl (fileno (user_spool), F_SETLK, &fl) == -1)
- {
- if (errno != EAGAIN)
{
- mvaddstr (10, 1, "Received a weird error from fcntl, so I'm giving up.");
- getch();
- return;
+ if (errno != EAGAIN)
+ {
+ mvaddstr (10, 1,
+ "Received a weird error from fcntl, so I'm giving up.");
+ getch ();
+ return;
+ }
+ sleep (1);
}
- sleep (1);
- }
fprintf (user_spool, "%s:%s\n", me->username, message);
fpl = fopen ("/dgl-lock", "r");
if (!fpl)
graceful_exit (106);
- if (fcntl (fileno(fpl), F_SETLKW, &fl) == -1)
+ if (fcntl (fileno (fpl), F_SETLKW, &fl) == -1)
graceful_exit (114);
}
void
purge_stale_locks (void)
{
- DIR* pdir;
+ DIR *pdir;
struct dirent *dent;
- if (!(pdir = opendir(LOC_INPROGRESSDIR)))
- graceful_exit(200);
+ if (!(pdir = opendir (LOC_INPROGRESSDIR)))
+ graceful_exit (200);
+
+ while ((dent = readdir (pdir)) != NULL)
+ {
+ FILE *ipfile;
+ char *colon;
+ char buf[16];
+ pid_t pid;
+ int seconds = 0;
+
+ colon = strchr (dent->d_name, ':');
+ /* should never happen */
+ if (!colon)
+ graceful_exit (201);
+
+ if (strncmp (dent->d_name, me->username, colon - dent->d_name))
+ continue;
- while ((dent = readdir(pdir)) != NULL)
- {
- FILE* ipfile;
- char* colon;
- char buf[16];
- pid_t pid;
-
- colon = strchr(dent->d_name, ':');
- /* should never happen */
- if (!colon)
- graceful_exit(201);
+ if (!(ipfile = fopen (dent->d_name, "r")))
+ graceful_exit (202);
- if (strncmp(dent->d_name, me->username, colon - dent->d_name))
- continue;
+ if (fgets (buf, 16, ipfile) == NULL)
+ graceful_exit (203);
- if (!(ipfile = fopen(dent->d_name, "r")))
- graceful_exit(202);
+ fclose (ipfile);
+ unlink (dent->d_name);
- if (fgets(buf, 16, ipfile) == NULL)
- graceful_exit(203);
+ pid = atoi (buf);
- fclose(ipfile);
- unlink(dent->d_name);
+ kill (pid, SIGHUP);
- pid = atoi(buf);
+ errno = 0;
- kill(pid, SIGHUP);
- }
-
- closedir(pdir);
+ /* Wait for it to stop running */
+ while (kill (pid, 0) == 0)
+ {
+ seconds++;
+ sleep (1);
+ if (seconds == 10)
+ {
+ clear ();
+ drawbanner (1, 1);
+ mvaddstr (3, 1,
+ "Couldn't terminate one of your stale Nethack processes gracefully.");
+ mvaddstr (4, 1, "Force its termination? [yn] ");
+ if (tolower (getch ()) == 'y')
+ {
+ kill (pid, SIGTERM);
+ break;
+ }
+ }
+ }
+ seconds = 0;
+ }
+
+ closedir (pdir);
}
int
endwin ();
- purge_stale_locks();
-
+ purge_stale_locks ();
+
/* environment */
snprintf (atrcfilename, 81, "@%s", rcfilename);
#if defined(LIBC_SCCS) && !defined(lint)
static char *rcsid =
- "$OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $";
+ "$OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
*/
size_t
strlcpy (dst, src, siz)
- char *dst;
- const char *src;
- size_t siz;
+ char *dst;
+ const char *src;
+ size_t siz;
{
- register char *d = dst;
- register const char *s = src;
- register size_t n = siz;
+ register char *d = dst;
+ register const char *s = src;
+ register size_t n = siz;
- /* Copy as many bytes as will fit */
- if (n != 0 && --n != 0)
- {
- do
- {
- if ((*d++ = *s++) == 0)
- break;
- }
- while (--n != 0);
- }
+ /* Copy as many bytes as will fit */
+ if (n != 0 && --n != 0)
+ {
+ do
+ {
+ if ((*d++ = *s++) == 0)
+ break;
+ }
+ while (--n != 0);
+ }
- /* Not enough room in dst, add NUL and traverse rest of src */
- if (n == 0)
- {
- if (siz != 0)
- *d = '\0'; /* NUL-terminate dst */
- while (*s++)
- ;
- }
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0)
+ {
+ if (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
- return (s - src - 1); /* count does not include NUL */
+ return (s - src - 1); /* count does not include NUL */
}