Move shmem freeing into it's own function

git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@568 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
Pasi Kallinen 2010-05-13 13:31:40 +00:00
parent ef9018dff1
commit bf9db511f5
1 changed files with 24 additions and 15 deletions

View File

@ -537,6 +537,22 @@ shm_mk_keys(key_t *shm_key, key_t *shm_sem_key)
#endif
}
#ifdef USE_SHMEM
int
shm_free()
{
key_t shm, sem;
int shm_id;
int shm_size = sizeof(struct dg_shm) + shm_n_games * sizeof(struct dg_shm_game);
shm_mk_keys(&shm, &sem);
if ((shm_id = shmget(shm, shm_size, 0644)) != -1) {
shmctl(shm_id, IPC_RMID, NULL);
return 0;
}
return 1;
}
#endif
void
shm_init(struct dg_shm **shm_dg_data, struct dg_shm_game **shm_dg_game)
{
@ -2336,23 +2352,16 @@ main (int argc, char** argv)
break;
case 'S': /* Free the shared memory block */
{
#ifdef USE_SHMEM
key_t shm, sem;
int shm_id;
int shm_size = sizeof(struct dg_shm) + shm_n_games * sizeof(struct dg_shm_game);
shm_mk_keys(&shm, &sem);
if ((shm_id = shmget(shm, shm_size, 0644)) != -1) {
shmctl(shm_id, IPC_RMID, NULL);
if (!silent) fprintf(stderr, "shmem block freed.\n");
} else {
if (!silent) fprintf(stderr, "nonexistent shmem block.\n");
}
#else
if (!silent) fprintf(stderr, "warning: dgamelaunch was compiled without shmem.\n");
#endif
graceful_exit(0);
if (shm_free()) {
if (!silent) fprintf(stderr, "nonexistent shmem block.\n");
} else {
if (!silent) fprintf(stderr, "shmem block freed.\n");
}
#else
if (!silent) fprintf(stderr, "warning: dgamelaunch was compiled without shmem.\n");
#endif
graceful_exit(0);
break;
case 'D': /* dump the shared memory block data */