#include "net.h"
#include "daemon.h"
#include "fd.h"
+#include "ipc.h"
#include "user_list.h"
#include "server_command_list.h"
#include "afs_command_list.h"
static RC4_KEY rc4_send_key;
static unsigned char rc4_buf[2 * RC4_KEY_LEN];
+extern int mmd_mutex;
extern struct misc_meta_data *mmd;
extern struct sender senders[];
static void mmd_dup(struct misc_meta_data *new_mmd)
{
- mmd_lock();
+ mutex_lock(mmd_mutex);
*new_mmd = *mmd;
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
}
/*
if (!subcmds[i])
return -E_COMMAND_SYNTAX;
scd->cmd_num = i;
- mmd_lock();
+ mutex_lock(mmd_mutex);
if (!senders[scd->sender_num].client_cmds[scd->cmd_num]) {
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
return -E_SENDER_CMD;
}
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
switch (scd->cmd_num) {
case SENDER_ON:
case SENDER_OFF:
return ret;
}
for (i = 0; i < 10; i++) {
- mmd_lock();
+ mutex_lock(mmd_mutex);
if (mmd->sender_cmd_data.cmd_num >= 0) {
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
usleep(100 * 1000);
continue;
}
mmd->sender_cmd_data = scd;
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
break;
}
return (i < 10)? 1 : -E_LOCK;
if (argc != 1)
return -E_COMMAND_SYNTAX;
- mmd_lock();
+ mutex_lock(mmd_mutex);
for (i = 0; senders[i].name; i++) {
char *info = senders[i].info();
sender_info = para_strcat(sender_info, info);
sender_list,
sender_info
);
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
free(ut);
free(sender_list);
free(sender_info);
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
- mmd_lock();
+ mutex_lock(mmd_mutex);
mmd->new_vss_status_flags |= VSS_PLAYING;
mmd->new_vss_status_flags &= ~VSS_NOMORE;
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
return 1;
}
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
- mmd_lock();
+ mutex_lock(mmd_mutex);
mmd->new_vss_status_flags &= ~VSS_PLAYING;
mmd->new_vss_status_flags &= ~VSS_REPOS;
mmd->new_vss_status_flags |= VSS_NEXT;
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
return 1;
}
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
- mmd_lock();
+ mutex_lock(mmd_mutex);
if (!vss_paused() && !vss_stopped()) {
mmd->events++;
mmd->new_vss_status_flags &= ~VSS_PLAYING;
mmd->new_vss_status_flags &= ~VSS_NEXT;
}
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
return 1;
}
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
- mmd_lock();
+ mutex_lock(mmd_mutex);
mmd->events++;
mmd->new_vss_status_flags |= VSS_NEXT;
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
return 1;
}
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
- mmd_lock();
+ mutex_lock(mmd_mutex);
if (vss_playing() || vss_paused())
mmd->new_vss_status_flags |= VSS_NOMORE;
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
return 1;
}
return -E_COMMAND_SYNTAX;
if (ret > 1 && c == '-')
backwards = 1; /* jmp backwards */
- mmd_lock();
+ mutex_lock(mmd_mutex);
ret = -E_NO_AUDIO_FILE;
if (!mmd->afd.afhi.chunks_total || !mmd->afd.afhi.seconds_total)
goto out;
mmd->events++;
ret = 1;
out:
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
return ret;
}
return -E_COMMAND_SYNTAX;
if (sscanf(argv[1], "%lu", &i) <= 0)
return -E_COMMAND_SYNTAX;
- mmd_lock();
+ mutex_lock(mmd_mutex);
ret = -E_NO_AUDIO_FILE;
if (!mmd->afd.afhi.chunks_total)
goto out;
ret = 1;
mmd->events++;
out:
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
return ret;
}
/* valid command and sufficient perms */
alarm(0);
argc = split_args(command, &argv, "\n");
- mmd_lock();
+ mutex_lock(mmd_mutex);
mmd->num_commands++;
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
PARA_NOTICE_LOG("calling com_%s() for %s@%s\n", cmd->name, u->name,
peername);
ret = cmd->handler(fd, argc, argv);
out:
free(command);
free(argv);
- mmd_lock();
+ mutex_lock(mmd_mutex);
if (cmd && (cmd->perms & AFS_WRITE) && ret >= 0)
mmd->events++;
mmd->active_connections--;
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
exit(ret < 0? EXIT_FAILURE : EXIT_SUCCESS);
}
/** A random value used in child context for authentication. */
uint32_t afs_socket_cookie;
+/** The mutex protecting the shared memory area containing the mmd struct. */
+int mmd_mutex;
+
/* global variables for server-internal use */
static FILE *logfile;
/** The file containing user information (public key, permissions). */
static char *user_list_file = NULL;
-static int mmd_mutex, mmd_shm_id;
+static int mmd_shm_id;
static pid_t afs_pid;
-/** The task resposible for server command handling. */
+/** The task responsible for server command handling. */
struct server_command_task {
/** TCP port on which para_server listens for connections. */
int listen_fd;
exit(EXIT_FAILURE);
}
-/**
- * Lock the shared memory area containing the mmd struct.
- *
- * \sa semop(2), struct misc_meta_data.
- */
-void mmd_lock(void)
-{
- mutex_lock(mmd_mutex);
-}
-
-/**
- * Unlock the shared memory area containing the mmd struct.
- *
- * \sa semop(2), struct misc_meta_data.
- */
-
-void mmd_unlock(void)
-{
- mutex_unlock(mmd_mutex);
-}
-
static void parse_config(int override)
{
char *home = para_homedir();
int ret;
status_refresh();
- mmd_unlock();
+ mutex_unlock(mmd_mutex);
ret = para_select(max_fileno + 1, readfds, writefds, timeout_tv);
- mmd_lock();
+ mutex_lock(mmd_mutex);
return ret;
}
.select_function = server_select
};
server_init(argc, argv);
- mmd_lock();
+ mutex_lock(mmd_mutex);
ret = schedule(&s);
if (ret < 0) {
PARA_EMERG_LOG("%s\n", para_strerror(-ret));