/* $Id: server.c,v 1.11 2007-09-22 11:50:33 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <termios.h>
#include <unistd.h>
#include <util.h>
#include "tmux.h"
/*
* Main server functions.
*/
/* Client list. */
struct clients clients;
int server_main(int);
void fill_windows(struct pollfd **);
void handle_windows(struct pollfd **);
void fill_clients(struct pollfd **);
void handle_clients(struct pollfd **);
struct client *accept_client(int);
void lost_client(struct client *);
void user_start(struct client *, const char *, const char *,
size_t, void (*)(struct client *, const char *));
void user_input(struct client *, size_t);
void write_message(struct client *, const char *, ...);
void write_client(struct client *, u_int, void *, size_t);
void write_client2(
struct client *, u_int, void *, size_t, void *, size_t);
void write_clients(struct window *, u_int, void *, size_t);
void new_window(struct window *);
void lost_window(struct window *);
void changed_window(struct client *);
void draw_client(struct client *, u_int, u_int);
void process_client(struct client *);
void process_new_msg(struct client *, struct hdr *);
void process_attach_msg(struct client *, struct hdr *);
void process_create_msg(struct client *, struct hdr *);
void process_next_msg(struct client *, struct hdr *);
void process_previous_msg(struct client *, struct hdr *);
void process_select_msg(struct client *, struct hdr *);
void process_size_msg(struct client *, struct hdr *);
void process_input_msg(struct client *, struct hdr *);
void process_refresh_msg(struct client *, struct hdr *);
void process_sessions_msg(struct client *, struct hdr *);
void process_windows_msg(struct client *, struct hdr *);
void process_rename_msg(struct client *, struct hdr *);
void process_last_msg(struct client *, struct hdr *);
void process_windowlist_msg(struct client *, struct hdr *);
void rename_callback(struct client *, const char *);
/* Fork and start server process. */
int
server_start(void)
{
mode_t mode;
int fd;
struct sockaddr_un sa;
size_t sz;
pid_t pid;
FILE *f;
char *p