Changeset 96ace1b for ipc.c


Ignore:
Timestamp:
2006-03-05T20:07:33Z (15 years ago)
Author:
Jelmer Vernooij <jelmer@…>
Branches:
master
Children:
728a981
Parents:
f665dab (diff), 27ac72d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

[merge] Wilmer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ipc.c

    rf665dab r96ace1b  
    2828#include "ipc.h"
    2929#include "commands.h"
     30#ifndef _WIN32
     31#include <sys/un.h>
     32#endif
    3033
    3134GSList *child_list = NULL;
     
    3437static void ipc_master_cmd_client( irc_t *data, char **cmd )
    3538{
     39        /* Normally data points at an irc_t block, but for the IPC master
     40           this is different. We think this scary cast is better than
     41           creating a new command_t structure, just to make the compiler
     42           happy. */
    3643        struct bitlbee_child *child = (void*) data;
    3744       
     
    457464}
    458465
     466
     467static gboolean new_ipc_client (GIOChannel *gio, GIOCondition cond, gpointer data)
     468{
     469        struct bitlbee_child *child = g_new0( struct bitlbee_child, 1 );
     470        int serversock;
     471
     472        serversock = g_io_channel_unix_get_fd(gio);
     473
     474        child->ipc_fd = accept(serversock, NULL, 0);
     475
     476        if (child->ipc_fd == -1) {
     477                log_message( LOGLVL_WARNING, "Unable to accept connection on UNIX domain socket: %s", strerror(errno) );
     478                return TRUE;
     479        }
     480               
     481        child->ipc_inpa = gaim_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child );
     482               
     483        child_list = g_slist_append( child_list, child );
     484
     485        return TRUE;
     486}
     487
     488#ifndef _WIN32
     489int ipc_master_listen_socket()
     490{
     491        struct sockaddr_un un_addr;
     492        int serversock;
     493        GIOChannel *gio;
     494
     495        /* Clean up old socket files that were hanging around.. */
     496        if (unlink(IPCSOCKET) == -1 && errno != ENOENT) {
     497                log_message( LOGLVL_ERROR, "Could not remove old IPC socket at %s: %s", IPCSOCKET, strerror(errno) );
     498                return 0;
     499        }
     500
     501        un_addr.sun_family = AF_UNIX;
     502        strcpy(un_addr.sun_path, IPCSOCKET);
     503
     504        serversock = socket(AF_UNIX, SOCK_STREAM, PF_UNIX);
     505
     506        if (serversock == -1) {
     507                log_message( LOGLVL_WARNING, "Unable to create UNIX socket: %s", strerror(errno) );
     508                return 0;
     509        }
     510
     511        if (bind(serversock, &un_addr, sizeof(un_addr)) == -1) {
     512                log_message( LOGLVL_WARNING, "Unable to bind UNIX socket to %s: %s", IPCSOCKET, strerror(errno) );
     513                return 0;
     514        }
     515
     516        if (listen(serversock, 5) == -1) {
     517                log_message( LOGLVL_WARNING, "Unable to listen on UNIX socket: %s", strerror(errno) );
     518                return 0;
     519        }
     520       
     521        gio = g_io_channel_unix_new(serversock);
     522       
     523        if (gio == NULL) {
     524                log_message( LOGLVL_WARNING, "Unable to create IO channel for unix socket" );
     525                return 0;
     526        }
     527
     528        g_io_add_watch(gio, G_IO_IN, new_ipc_client, NULL);
     529        return 1;
     530}
     531#else
     532        /* FIXME: Open named pipe \\.\BITLBEE */
     533#endif
     534
    459535int ipc_master_load_state()
    460536{
Note: See TracChangeset for help on using the changeset viewer.