/[muddleftpd]/muddleftpd/src/shmem.c
ViewVC logotype

Diff of /muddleftpd/src/shmem.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by ganneff, Thu Sep 26 07:55:42 2002 UTC revision 1.1.6.1 by ganneff, Mon Oct 21 19:52:59 2002 UTC
# Line 1  Line 1 
1    
2  /* Copyright (C) 1999 Beau Kuiper  /* Copyright (C) 1999 Beau Kuiper
3    
4     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
# Line 19  Line 20 
20  void shmem_finish(int shmemnum)  void shmem_finish(int shmemnum)
21  {  {
22          struct shmid_ds buffer;          struct shmid_ds buffer;
23    
24          if (shmemnum != -1)          if (shmemnum != -1)
25          {          {
26                  if (shmctl(shmemnum, IPC_RMID, &buffer) == -1);                  if (shmctl(shmemnum, IPC_RMID, &buffer) == -1);
27    
28  /*              close(shmem_lockfd); */  /*              close(shmem_lockfd); */
29          }          }
30  }  }
31    
32  void *shmem_get(char *ipcfile, int size, int *shmemnum, int *isnew, int *lockfd)  void *shmem_get(char *ipcfile,
33                                    int size,
34                                    int *shmemnum,
35                                    int *isnew,
36                                    int *lockfd)
37  {  {
38          key_t ipckey = ftok(ipcfile, '/');          key_t ipckey = ftok(ipcfile, '/');
39          void *shmemarea;          void *shmemarea;
40    
41          *isnew = TRUE;          *isnew = TRUE;
42          *shmemnum = shmget(ipckey, size,          *shmemnum = shmget(ipckey, size, IPC_CREAT | IPC_EXCL | 0600);
                                 IPC_CREAT | IPC_EXCL | 0600);  
43          if (*shmemnum == -1)          if (*shmemnum == -1)
44          {          {
45                  *isnew = FALSE;                  *isnew = FALSE;
46                  *shmemnum = shmget(ipckey, size,                  *shmemnum = shmget(ipckey, size, IPC_CREAT | /* IPC_EXCL | */ 0600);
                                         IPC_CREAT |/* IPC_EXCL |*/ 0600);  
47          }          }
48          if (*shmemnum == -1)          if (*shmemnum == -1)
49                  ERRORMSGFATAL(strerror(errno));                  ERRORMSGFATAL(strerror(errno));
50    
51          shmemarea = shmat(*shmemnum, NULL, 0);          shmemarea = shmat(*shmemnum, NULL, 0);
52            
53          /* get semaphores. Using the config file so others can join in (we use file locks for portability, simplicity          /*
54             and usability. */           * get semaphores. Using the config file so others can join in (we use file locks for portability, simplicity
55                     * and usability.
56             */
57    
58          *lockfd = open(ipcfile, O_RDWR);          *lockfd = open(ipcfile, O_RDWR);
59          if (*lockfd == -1)          if (*lockfd == -1)
60                  ERRORMSGFATAL(strerror(errno));                  ERRORMSGFATAL(strerror(errno));
61          return(shmemarea);          return (shmemarea);
62  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.6.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26