get_key() calls ftok(3), which returns a key_t value. key_t is also
the type which semget(2), the only function which receives the key via
mutex_get(), expects. It's stupid to convert the key_t from ftok(3)
into an int, only to convert it back to key_t later.
This patch changes ipc.c to use key_t everywhere. However, in
mutex_get() we print a log message containing the value of the key,
so the format string must be adjusted accordingly. Unfortunately,
on Linux, key_t is the same as int while on FreeBSD and NetBSD it is
defined as long. To avoid a warning from the compiler we use "%lx"
in the format string and cast the value to long.
#include "err.h"
#include "ipc.h"
#include "err.h"
#include "ipc.h"
-static int get_key(const char *config_file)
+static key_t get_key(const char *config_file)
assert(config_file);
ret = ftok(config_file, 'D');
assert(config_file);
ret = ftok(config_file, 'D');
return 0x0D55; /* no magic, this number just looks a bit like DSS */
}
return 0x0D55; /* no magic, this number just looks a bit like DSS */
}
-static int mutex_get(int key, int flags)
+static int mutex_get(key_t key, int flags)
- DSS_DEBUG_LOG(("getting semaphore 0x%x\n", key));
+ DSS_DEBUG_LOG(("getting semaphore 0x%lx\n", (long)key));
ret = semget(key, 2, flags);
if (ret < 0)
return -ERRNO_TO_DSS_ERROR(errno);
ret = semget(key, 2, flags);
if (ret < 0)
return -ERRNO_TO_DSS_ERROR(errno);
int lock_dss(char *config_file)
{
int lock_dss(char *config_file)
{
- int ret, key = get_key(config_file);
+ int ret;
+ key_t key = get_key(config_file);
ret = mutex_get(key, IPC_CREAT | 0600);
if (ret < 0)
ret = mutex_get(key, IPC_CREAT | 0600);
if (ret < 0)
int get_dss_pid(char *config_file, pid_t *pid)
{
int get_dss_pid(char *config_file, pid_t *pid)
{
- int ret, semid, key = get_key(config_file);
+ int ret, semid;
+ key_t key = get_key(config_file);