~ubuntu-branches/ubuntu/precise/corosync/precise-proposed

« back to all changes in this revision

Viewing changes to lcr/uis.c

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2009-08-21 09:29:56 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090821092956-w9qxxxx3zeoh8dem
Tags: 1.0.0-4ubuntu2
* debian/control:
  - 'Ubuntu Developers' instead of 'Ubuntu Core Developers'
    as maintainer
  - Bump debhelper dependecy to 7

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * Copyright (c) 2006 Steven Dake (sdake@redhat.com)
3
3
 *
4
4
 * This software licensed under BSD license, the text of which follows:
5
 
 * 
 
5
 *
6
6
 * Redistribution and use in source and binary forms, with or without
7
7
 * modification, are permitted provided that the following conditions are met:
8
8
 *
27
27
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28
28
 * THE POSSIBILITY OF SUCH DAMAGE.
29
29
 */
 
30
 
 
31
#include <config.h>
 
32
 
30
33
#include <sys/uio.h>
31
34
#include <sys/mman.h>
32
35
#include <sys/types.h>
41
44
#include <stdlib.h>
42
45
#include <stdio.h>
43
46
#include <errno.h>
44
 
#include <signal.h>
45
47
#include <sched.h>
46
48
#include <time.h>
47
49
#include <pthread.h>
51
53
#define SERVER_BACKLOG 5
52
54
 
53
55
#if defined(COROSYNC_LINUX) || defined(COROSYNC_SOLARIS)
54
 
/* SUN_LEN is broken for abstract namespace 
 
56
/* SUN_LEN is broken for abstract namespace
55
57
 */
56
58
#define AIS_SUN_LEN(a) sizeof(*(a))
57
59
#else
59
61
#endif
60
62
 
61
63
#ifdef COROSYNC_LINUX
62
 
static char *socketname = "lcr.socket";
 
64
static const char *socketname = "lcr.socket";
63
65
#else
64
 
static char *socketname = "/var/run/lcr.socket";
 
66
static const char *socketname = SOCKETDIR "/lcr.socket";
65
67
#endif
66
68
 
67
69
static void uis_lcr_bind (int *server_fd)
101
103
}
102
104
 
103
105
struct uis_commands {
104
 
        char *command;
 
106
        const char *command;
105
107
        void (*cmd_handler) (char *);
106
108
};
107
109
 
108
 
void cmd1 (char *cmd) {
 
110
static void cmd1 (char *cmd) {
109
111
        printf ("cmd1 executed with cmd line %s\n", cmd);
110
112
}
111
113
 
115
117
        }
116
118
};
117
119
 
118
 
struct req_msg {
 
120
struct uis_req_msg {
119
121
        int len;
120
122
        char msg[0];
121
123
};
122
124
 
123
125
static void lcr_uis_dispatch (int fd)
124
126
{
125
 
        struct req_msg header;
 
127
        struct uis_req_msg header;
126
128
        char msg_contents[512];
127
129
        ssize_t readsize;
128
130
 
150
152
#ifdef COROSYNC_LINUX
151
153
        int on = 1;
152
154
#endif
153
 
        int res;
154
155
 
155
156
        /*
156
157
         * Main acceptance and dispatch loop
160
161
        ufds[0].events = POLLIN;
161
162
        ufds[1].events = POLLOUT;
162
163
        for (;;) {
163
 
                res = poll (ufds, nfds, -1);
 
164
                int res = poll (ufds, nfds, -1);
 
165
                if (res == 0 || (res < 0 && errno == EINTR))
 
166
                        continue;
 
167
                if (res < 0)
 
168
                        return NULL;
164
169
                if (nfds == 1 && ufds[0].revents & POLLIN) {
165
170
                        ufds[1].fd = accept (ufds[0].fd,
166
171
                                (struct sockaddr *)&un_addr, &addrlen);
167
 
#ifdef COROSYNC_LINUX                   
 
172
#ifdef COROSYNC_LINUX
168
173
                        setsockopt(ufds[1].fd, SOL_SOCKET, SO_PASSCRED,
169
174
                                &on, sizeof (on));
170
175
#endif
171
 
                        nfds = 2;               
 
176
                        nfds = 2;
172
177
                }
173
178
                if (ufds[0].revents & POLLIN) {
174
179
                        lcr_uis_dispatch (ufds[1].fd);
175
180
                }
176
181
        }
177
 
 
178
 
 
179
 
        return 0;
180
182
}
181
183
 
182
184
__attribute__ ((constructor)) static int lcr_uis_ctors (void)
187
189
 
188
190
        return (0);
189
191
}
190