Remove the watcher if user kills the terminal while watching.
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@556 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
parent
f11bf73dd8
commit
e80d1c338b
|
@ -253,6 +253,11 @@ gen_inprogress_lock (int game, pid_t pid, char* ttyrec_filename)
|
||||||
|
|
||||||
/* ************************************************************* */
|
/* ************************************************************* */
|
||||||
|
|
||||||
|
#ifdef USE_SHMEM
|
||||||
|
int hup_shm_idx = -1;
|
||||||
|
char *hup_shm_ttyrec_fn = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
catch_sighup (int signum)
|
catch_sighup (int signum)
|
||||||
{
|
{
|
||||||
|
@ -262,6 +267,23 @@ catch_sighup (int signum)
|
||||||
kill (child, SIGHUP);
|
kill (child, SIGHUP);
|
||||||
sleep (5);
|
sleep (5);
|
||||||
}
|
}
|
||||||
|
#ifdef USE_SHMEM
|
||||||
|
if (hup_shm_idx != -1) {
|
||||||
|
struct dg_shm *shm_dg_data = NULL;
|
||||||
|
struct dg_shm_game *shm_dg_game = NULL;
|
||||||
|
shm_init(&shm_dg_data, &shm_dg_game);
|
||||||
|
|
||||||
|
shm_sem_wait(shm_dg_data);
|
||||||
|
if (shm_dg_game[hup_shm_idx].in_use &&
|
||||||
|
!strcmp(shm_dg_game[hup_shm_idx].ttyrec_fn, hup_shm_ttyrec_fn) &&
|
||||||
|
(shm_dg_game[hup_shm_idx].nwatchers > 0)) {
|
||||||
|
shm_dg_game[hup_shm_idx].nwatchers--;
|
||||||
|
}
|
||||||
|
shm_sem_post(shm_dg_data);
|
||||||
|
hup_shm_idx = -1;
|
||||||
|
free(hup_shm_ttyrec_fn);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
debug_write("catchup sighup");
|
debug_write("catchup sighup");
|
||||||
graceful_exit (2);
|
graceful_exit (2);
|
||||||
}
|
}
|
||||||
|
@ -872,6 +894,8 @@ watchgame:
|
||||||
shm_dg_game[shm_idx].nwatchers++;
|
shm_dg_game[shm_idx].nwatchers++;
|
||||||
games[idx]->nwatchers++;
|
games[idx]->nwatchers++;
|
||||||
}
|
}
|
||||||
|
hup_shm_idx = shm_idx;
|
||||||
|
hup_shm_ttyrec_fn = strdup(games[idx]->ttyrec_fn);
|
||||||
shm_sem_post(shm_dg_data);
|
shm_sem_post(shm_dg_data);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -888,6 +912,8 @@ watchgame:
|
||||||
setproctitle("<Anonymous>");
|
setproctitle("<Anonymous>");
|
||||||
#ifdef USE_SHMEM
|
#ifdef USE_SHMEM
|
||||||
if (games[idx]->is_in_shm) {
|
if (games[idx]->is_in_shm) {
|
||||||
|
hup_shm_idx = -1;
|
||||||
|
free(hup_shm_ttyrec_fn);
|
||||||
shm_sem_wait(shm_dg_data);
|
shm_sem_wait(shm_dg_data);
|
||||||
if (shm_dg_game[shm_idx].in_use &&
|
if (shm_dg_game[shm_idx].in_use &&
|
||||||
!strcmp(shm_dg_game[shm_idx].ttyrec_fn, games[idx]->ttyrec_fn) &&
|
!strcmp(shm_dg_game[shm_idx].ttyrec_fn, games[idx]->ttyrec_fn) &&
|
||||||
|
|
|
@ -251,6 +251,13 @@ extern void debug_write(char *str);
|
||||||
extern struct dg_game **sort_games(struct dg_game **games, int len, dg_sortmode sortmode);
|
extern struct dg_game **sort_games(struct dg_game **games, int len, dg_sortmode sortmode);
|
||||||
|
|
||||||
int runmenuloop(struct dg_menu *menu);
|
int runmenuloop(struct dg_menu *menu);
|
||||||
|
|
||||||
|
extern void shm_sem_wait(struct dg_shm *shm_dg_data);
|
||||||
|
extern void shm_sem_post(struct dg_shm *shm_dg_data);
|
||||||
|
extern void shm_update(struct dg_shm *shm_dg_data, struct dg_game **games, int len);
|
||||||
|
extern void shm_mk_keys(key_t *shm_key, key_t *shm_sem_key);
|
||||||
|
extern void shm_init(struct dg_shm **shm_dg_data, struct dg_shm_game **shm_dg_game);
|
||||||
|
|
||||||
extern int dgl_getch(void);
|
extern int dgl_getch(void);
|
||||||
extern void idle_alarm_set_enabled(int enabled);
|
extern void idle_alarm_set_enabled(int enabled);
|
||||||
extern void idle_alarm_reset(void);
|
extern void idle_alarm_reset(void);
|
||||||
|
|
Loading…
Reference in New Issue