httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@ast.cam.ac.uk (David Robinson)
Subject Re: SysV Shared Memory Patch
Date Tue, 20 Feb 1996 14:46:00 GMT
>All good suggestions! I'll fold shmget into attach_seg, make sure that
>the seg's deleted if shmart fails and do some better logging.
>
>I'll upload 108b soon.

You may wish to include the following program in the support/ directory.

 David.

/* apache copyright here. (c) 1996 */

/* This program allows the user to view and delete shared-memory segments */

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

#include <sys/types.h>

#include <sys/ipc.h>
#include <sys/shm.h>

int
main(int argc, char **argv)
{
    int shmid;
    struct shmid_ds buf;
    int rc;

    if (argc != 3)
    {
	printf("shmop op key\n   op = ls | rm\n");
	exit(0);
    }
    if (strcmp(argv[1], "ls") != 0 && strcmp(argv[1], "rm") != 0)
    {
	fprintf(stderr, "Unknown operation: '%s'\n", argv[1]);
	exit(1);
    }
    if (sscanf(argv[2], "%d", &shmid) != 1)
    {
	fprintf(stderr, "Bad key: '%s'\n", argv[2]);
	exit(1);
    }

    if (strcmp(argv[1], "ls") == 0)
    {
	rc = shmctl(shmid, IPC_STAT, &buf);
	if (rc == -1)
	{
	    rc = errno;
	    perror("shmctl");
	    if (rc == EINVAL)
		fprintf(stderr, "%d is not a valid shared memory identifier\n",
			shmid);
	    exit(1);
	}

	printf("shm_perm.uid  = %ld\n", buf.shm_perm.uid);
	printf("shm_perm.gid  = %ld\n", buf.shm_perm.gid);
	printf("shm_perm.cuid = %ld\n", buf.shm_perm.cuid);
	printf("shm_perm.cgid = %ld\n", buf.shm_perm.cgid);
	printf("shm_perm.mode = %lo\n", buf.shm_perm.mode);
	printf("shm_perm.seq  = %lu\n", buf.shm_perm.seq);
	printf("shm_perm.key  = %d\n", buf.shm_perm.key);
	printf("shm_segsz  = %d\n", buf.shm_segsz);
/* buf.shm_amp  anon_map */
	printf("shm_lkcnt  = %u\n", buf.shm_lkcnt);
	printf("shm_lpid   = %ld\n", buf.shm_lpid);
	printf("shm_cpid   = %ld\n", buf.shm_cpid);
	printf("shm_nattch = %lu\n", buf.shm_nattch);
	printf("shm_cnattch= %lu\n", buf.shm_cnattch);
	printf("shm_atime  = %s", ctime(&buf.shm_atime));
	printf("shm_dtime  = %s", ctime(&buf.shm_dtime));
	printf("shm_ctime  = %s", ctime(&buf.shm_ctime));
/* buf.shm_cv  kcondvar_t */
/* shm_sptas   struct as */
    } else
    {
	rc = shmctl(shmid, IPC_RMID, NULL);
	if (rc == -1)
	{
	    rc = errno;
	    perror("shmctl");
	    if (rc == EINVAL)
		fprintf(stderr, "%d is not a valid shared memory identifier\n",
			shmid);
	    exit(1);
	}
    }

    return 0;
}

Mime
View raw message