From: Andre Date: Tue, 21 Feb 2006 15:42:12 +0000 (+0100) Subject: make para_server use the new ipc subsystem X-Git-Tag: v0.2.11~65 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=bc6c214340c1760203b24097c2066abfcaa1c539;p=paraslash.git make para_server use the new ipc subsystem Straight-forward conversion. This BTW gets rid of the ancient /dev/zero hack which worked pretty well for all the years but is not general enough for the plm dbtool. Another 42 also disappeared ;) --- diff --git a/server.c b/server.c index a6fca8b6..c46966ea 100644 --- a/server.c +++ b/server.c @@ -34,12 +34,12 @@ #include "afs.h" #include "config.h" #include "close_on_fork.h" -#include /* MAP_SHARED, PROT_READ, PROT_WRITE */ #include "send.h" #include "error.h" #include "net.h" #include "daemon.h" #include "string.h" +#include "ipc.h" /** define the array of error lists needed by para_server */ INIT_SERVER_ERRLISTS; @@ -108,7 +108,7 @@ struct sender senders[] = { /* global variables for server-internal use */ static FILE *logfile; -static int mmd_semid; +static int mmd_mutex, mmd_shm_id; static int signal_pipe; /** @@ -151,27 +151,27 @@ void para_log(int ll, char* fmt,...) va_end(argp); } - /* - * setup shared memory area and get semaphore for locking + * setup shared memory area and get mutex for locking */ static void shm_init(void) { - int fd; - caddr_t area; + void *shm; + int ret = shm_new(sizeof(struct misc_meta_data)); - if ((fd = open("/dev/zero", O_RDWR)) < 0) { - PARA_EMERG_LOG("%s", "failed to open /dev/zero\n"); - exit(EXIT_FAILURE); - } - if ((area = mmap(0, sizeof(struct misc_meta_data), - PROT_READ | PROT_WRITE, - MAP_SHARED, fd, 0)) == (caddr_t) - 1) { - PARA_EMERG_LOG("%s", "mmap error\n"); - exit(EXIT_FAILURE); - } - close(fd); /* we dont need /dev/zero anymore */ - mmd = (struct misc_meta_data *)area; + if (ret < 0) + goto err_out; + + ret = shm_attach(ret, ATTACH_RW, &shm); + if (ret < 0) + goto err_out; + mmd = shm; + mmd_shm_id = ret; + + ret = mutex_new(); + if (ret < 0) + goto err_out; + mmd_mutex = ret; mmd->dbt_num = 0; mmd->num_played = 0; @@ -184,21 +184,10 @@ static void shm_init(void) mmd->afs_status_flags = AFS_NEXT; mmd->new_afs_status_flags = AFS_NEXT; mmd->sender_cmd_data.cmd_num = -1; - - mmd_semid = semget(42, 1, IPC_CREAT | 0666); - if (mmd_semid == -1) { - PARA_EMERG_LOG("%s", "semget failed\n"); - exit(EXIT_FAILURE); - } -} - -static void do_semop(struct sembuf *sops, int num) -{ - if (semop(mmd_semid, sops, num) >= 0) - return; - PARA_WARNING_LOG("semop failed (%s), retrying\n", strerror(errno)); - while (semop(mmd_semid, sops, num) < 0) - ; /* nothing */ + return; +err_out: + PARA_EMERG_LOG("%s", PARA_STRERROR(-ret)); + exit(EXIT_FAILURE); } /** @@ -208,19 +197,7 @@ static void do_semop(struct sembuf *sops, int num) */ void mmd_lock(void) { - struct sembuf sops[2] = { - { - .sem_num = 0, - .sem_op = 0, - .sem_flg = SEM_UNDO - }, - { - .sem_num = 0, - .sem_op = 1, - .sem_flg = SEM_UNDO - } - }; - do_semop(sops, 2); + mutex_lock(mmd_mutex); } /** @@ -228,16 +205,10 @@ void mmd_lock(void) * * \sa semop(2), struct misc_meta_data */ + void mmd_unlock(void) { - struct sembuf sops[1] = { - { - .sem_num = 0, - .sem_op = -1, - .sem_flg = SEM_UNDO - }, - }; - do_semop(sops, 1); + mutex_unlock(mmd_mutex); } static void parse_config(int override) @@ -551,6 +522,10 @@ repeat: case SIGTERM: PARA_EMERG_LOG("terminating on signal %d\n", sig); kill(0, SIGTERM); + dblist[mmd->dbt_num].shutdown(); + mutex_destroy(mmd_mutex); + shm_detach(mmd); + shm_destroy(mmd_shm_id); exit(EXIT_FAILURE); } }