"Fossies" - the Fresh Open Source Software Archive

Member "mod_dns/dns_lock.c" (8 Mar 2001, 1727 Bytes) of package /linux/www/apache_httpd_modules/old/mod_dns-1.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 
    2 
    3 #include <sys/types.h>
    4 #include <sys/ipc.h>
    5 #include <sys/sem.h>
    6 #include <stdio.h>
    7 
    8 #include "httpd.h"
    9 #include "http_config.h"
   10 #include "http_core.h"
   11 #include "http_log.h"
   12 #include "http_protocol.h"
   13 #include "http_request.h"
   14 #include "http_main.h"
   15 #include "http_conf_globals.h"  // ap_user_id
   16 #include "dns_lock.h"
   17 
   18 
   19 
   20 
   21 
   22 
   23 // return:  semid
   24 
   25 int moddns_mutex_init ()
   26 {
   27   int sem;
   28   struct semid_ds perm = { };
   29 
   30   perm.sem_perm.uid = ap_user_id;
   31   perm.sem_perm.gid = -1;
   32   perm.sem_perm.mode = 0600;
   33 
   34   sem = semget (IPC_PRIVATE, 1, IPC_CREAT|IPC_EXCL);
   35   if (sem < 0) {
   36     perror ("mod_dns: Failed to create mutex: semget");
   37     exit(1);
   38   }
   39   if (semctl (sem, 0, IPC_SET, &perm) < 0) {
   40     perror ("mod_dns: Failed to set mutex permissions: semctl");
   41     exit(1);
   42   }
   43   if (semctl (sem, 0, SETVAL, 1) < 0) {
   44     perror ("mod_dns: Failed to open mutex: semctl");
   45     exit(1);
   46   }
   47 //fprintf (stderr, "created sem %d (pid=%d)\n", sem, getpid());
   48   return sem;
   49 }
   50 
   51 
   52 // remove mutex
   53 
   54 void moddns_mutex_zap (int lock)
   55 {
   56 //fprintf(stderr, "zapping sem %d (pid=%d)\n", lock, getpid());
   57   if (semctl (lock, 0, IPC_RMID, 0) < 0) {
   58     perror ("mod_dns: Failed to remove mutex: semctl");
   59   }
   60 }
   61 
   62 
   63 
   64 // lock mutex
   65 
   66 void moddns_mutex_lock (int lock)
   67 {
   68   static struct sembuf op = { 0, -1, SEM_UNDO };
   69 //  op.sem_num  = 0;
   70 //  op.sem_op   = -1;
   71 //  op.sem_flg  = SEM_UNDO;
   72   if (semop (lock, &op, 1) < 0) {
   73     perror ("mod_dns: Failed to aquire mutex: semop");
   74   }
   75 }
   76 
   77 
   78 // unlock mutex
   79 
   80 void moddns_mutex_unlock (int lock)
   81 {
   82   static struct sembuf op = { 0, 1, SEM_UNDO };
   83 //  op.sem_num  = 0;
   84 //  op.sem_op   = 1;
   85 //  op.sem_flg  = SEM_UNDO;
   86   if (semop (lock, &op, 1) < 0) {
   87     perror ("mod_dns: Failed to release mutex: semop");
   88   }
   89 }
   90 
   91 
   92 
   93 
   94 
   95 
   96 
   97 
   98