diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2002-03-07 23:13:44 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2002-03-07 23:13:44 +0800 |
commit | ae31e19f92e717919ac8e3db9039eb38d2b89aae (patch) | |
tree | c70164d6a1852344f44b04a653ae2815043512af /util/shmsweep.c | |
download | pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.gz pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.bz2 pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.lz pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.xz pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.zst pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.zip |
Initial revision
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@1 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util/shmsweep.c')
-rw-r--r-- | util/shmsweep.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/util/shmsweep.c b/util/shmsweep.c new file mode 100644 index 00000000..01acb26b --- /dev/null +++ b/util/shmsweep.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/shm.h> +#include <sys/stat.h> +#include "config.h" +#include "pttstruct.h" + +int main() { + int i, shm, counter; + struct utmpfile_t *utmpshm; + + + shm = shmget(UTMPSHM_KEY, USHM_SIZE, SHM_R | SHM_W); + if(shm == -1) { + perror("shmget"); + exit(0); + } + + utmpshm = shmat(shm, NULL, 0); + if(utmpshm == (struct utmpfile_t *)-1) { + perror("shmat"); + exit(0); + } + + for(i = counter = 0; i < USHM_SIZE; i++) + if(utmpshm->uinfo[i].pid) { + char buf[256]; + userinfo_t *f; + struct stat sb; + + f = &utmpshm->uinfo[i]; + sprintf(buf, "/proc/%d", f->pid); + if(stat(buf, &sb)) { + f->pid = 0; + utmpshm->number--; + counter++; + } + } + printf("clear %d slots\n", counter); + return 0; +} |