Changeset 44
- Timestamp:
- 06/30/08 11:15:23
(3 months ago)
- Author:
- jtang
- Message:
Merged no-calloc() patch; updated Makefiles.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r30 |
r44 |
|
| 4 | 4 | TARGET=libsipc.so |
|---|
| 5 | 5 | SONAME=$(TARGET).$(SOVERSION) |
|---|
| 6 | | LIBSO=$(TARGET).$(SOVERSION).$(RELEASE) |
|---|
| | 6 | LIBSO=$(TARGET).$(SOVERSION) |
|---|
| | 7 | RELEASESO=$(LIBSO).$(RELEASE) |
|---|
| 7 | 8 | |
|---|
| 8 | 9 | TOP_SRCDIR ?= .. |
|---|
| … | … | |
| 11 | 12 | OBJS=$(patsubst %.c,%.o,$(wildcard *.c)) |
|---|
| 12 | 13 | |
|---|
| 13 | | all: $(LIBSO) |
|---|
| | 14 | all: $(RELEASESO) |
|---|
| 14 | 15 | |
|---|
| 15 | | $(LIBSO): $(OBJS) |
|---|
| | 16 | $(RELEASESO): $(OBJS) |
|---|
| 16 | 17 | $(CC) $(LDFLAGS) -shared -o $@ $^ -Wl,-soname,$(SONAME),--version-script=libsipc.map,-z,defs $(LIBDIRS) |
|---|
| | 18 | ln -sf $@ $(LIBSO) |
|---|
| 17 | 19 | ln -sf $@ $(TARGET) |
|---|
| 18 | 20 | |
|---|
| … | … | |
| 20 | 22 | $(CC) $(AM_CFLAGS) $(CFLAGS) $(INCLUDEDIRS) -c -o $@ $< |
|---|
| 21 | 23 | |
|---|
| 22 | | install: $(LIBSO) |
|---|
| | 24 | install: $(RELEASESO) |
|---|
| 23 | 25 | test -d $(DESTDIR)/$(LIBDIR) || install -m 755 -d $(DESTDIR)/$(LIBDIR) |
|---|
| 24 | | install -m 644 $(LIBSO) $(DESTDIR)/$(LIBDIR) |
|---|
| 25 | | cd $(DESTDIR)/$(LIBDIR) && ln -sf $(LIBSO) $(TARGET) |
|---|
| 26 | | cd $(DESTDIR)/$(LIBDIR) && ln -sf $(LIBSO) $(TARGET).$(SOVERSION) |
|---|
| | 26 | install -m 644 $(RELEASESO) $(DESTDIR)/$(LIBDIR) |
|---|
| | 27 | cd $(DESTDIR)/$(LIBDIR) && ln -sf $(RELEASESO) $(TARGET) |
|---|
| | 28 | cd $(DESTDIR)/$(LIBDIR) && ln -sf $(RELEASESO) $(LIBSO) |
|---|
| 27 | 29 | |
|---|
| 28 | 30 | clean: |
|---|
| 29 | | -rm -f $(OBJS) $(LIBSO) $(TARGET) |
|---|
| | 31 | -rm -f $(OBJS) $(RELEASESO) $(LIBSO) $(TARGET) |
|---|
| 30 | 32 | |
|---|
| 31 | 33 | .PHONY: all install clean |
|---|
| r21 |
r44 |
|
| 1 | | { |
|---|
| | 1 | VERS_1.0{ |
|---|
| 2 | 2 | global: |
|---|
| 3 | 3 | sipc_open; |
|---|
| r41 |
r44 |
|
| 89 | 89 | |
|---|
| 90 | 90 | char *data; |
|---|
| | 91 | struct msgbuf *mbuf; |
|---|
| 91 | 92 | size_t len; |
|---|
| 92 | 93 | size_t msg_len; /* Length in bytes of the next message */ |
|---|
| r41 |
r44 |
|
| 29 | 29 | #include <sys/stat.h> |
|---|
| 30 | 30 | #include <fcntl.h> |
|---|
| | 31 | #include <assert.h> |
|---|
| 31 | 32 | #include "sipc_internal.h" |
|---|
| 32 | 33 | #include "sipc_mqueue.h" |
|---|
| … | … | |
| 67 | 68 | sipc->funcs = &mqueue_funcs; |
|---|
| 68 | 69 | sipc->data = NULL; |
|---|
| | 70 | sipc->mbuf = NULL; |
|---|
| 69 | 71 | |
|---|
| 70 | 72 | /* Determine maximum size of a message from proc */ |
|---|
| … | … | |
| 97 | 99 | free(sipc->data); |
|---|
| 98 | 100 | sipc->data = NULL; |
|---|
| | 101 | free(sipc->mbuf); |
|---|
| | 102 | sipc->mbuf = NULL; |
|---|
| 99 | 103 | } |
|---|
| 100 | 104 | |
|---|
| … | … | |
| 105 | 109 | sipc->data = calloc(1, sipc->len); |
|---|
| 106 | 110 | if (!sipc->data) { |
|---|
| | 111 | sipc_error(sipc, "Out of memory\n"); |
|---|
| | 112 | return -1; |
|---|
| | 113 | } |
|---|
| | 114 | |
|---|
| | 115 | /* Allocate message buffer */ |
|---|
| | 116 | sipc->mbuf = (struct msgbuf *)calloc(1, SIPC_MQUEUE_MSG_SZ); |
|---|
| | 117 | if (!sipc->mbuf) { |
|---|
| 107 | 118 | sipc_error(sipc, "Out of memory\n"); |
|---|
| 108 | 119 | return -1; |
|---|
| … | … | |
| 114 | 125 | free(sipc->data); |
|---|
| 115 | 126 | sipc->data = NULL; |
|---|
| | 127 | free(sipc->mbuf); |
|---|
| | 128 | sipc->mbuf = NULL; |
|---|
| 116 | 129 | return -1; |
|---|
| 117 | 130 | } |
|---|
| … | … | |
| 132 | 145 | size_t packet_sz; |
|---|
| 133 | 146 | char *packet = NULL; |
|---|
| 134 | | struct msgbuf *mbuf = NULL; |
|---|
| 135 | | |
|---|
| | 147 | |
|---|
| | 148 | if (!sipc) |
|---|
| | 149 | goto err; |
|---|
| 136 | 150 | if (sipc->role != SIPC_SENDER) |
|---|
| 137 | 151 | goto err; |
|---|
| 138 | 152 | |
|---|
| 139 | | mbuf = (struct msgbuf *)calloc(1, SIPC_MQUEUE_MSG_SZ); |
|---|
| 140 | | if (!mbuf) { |
|---|
| 141 | | sipc_error(sipc, "%s\n", "Out of memory"); |
|---|
| 142 | | goto err; |
|---|
| 143 | | } |
|---|
| 144 | | |
|---|
| | 153 | struct msgbuf *mbuf = sipc->mbuf; |
|---|
| | 154 | assert(mbuf); |
|---|
| | 155 | memset(mbuf, 0, SIPC_MQUEUE_MSG_SZ); |
|---|
| 145 | 156 | sipc->msg_len = msg_len; |
|---|
| 146 | 157 | mqueue_send_msg_len(sipc, msg_len); |
|---|
| … | … | |
| 170 | 181 | mqueue_send_end_xmit(sipc); |
|---|
| 171 | 182 | sipc->msg_len = SIPC_MSGLEN_NOT_SET; |
|---|
| 172 | | free(mbuf); |
|---|
| 173 | 183 | return 0; |
|---|
| 174 | 184 | |
|---|
| 175 | 185 | err: |
|---|
| 176 | 186 | free(packet); |
|---|
| 177 | | free(mbuf); |
|---|
| 178 | 187 | sipc->msg_len = SIPC_MSGLEN_NOT_SET; |
|---|
| 179 | 188 | return -1; |
|---|
| … | … | |
| 184 | 193 | int retv = -1, alloc_sz = 0, idx = 0, recv_sz; |
|---|
| 185 | 194 | int msgtxt_sz = SIPC_MQUEUE_MSG_SZ - sizeof(struct msgbuf); |
|---|
| 186 | | struct msgbuf *mbuf = NULL; |
|---|
| 187 | 195 | |
|---|
| 188 | 196 | if (!sipc || !data || !len) |
|---|
| … | … | |
| 198 | 206 | } |
|---|
| 199 | 207 | |
|---|
| 200 | | mbuf = calloc(1, SIPC_MQUEUE_MSG_SZ); |
|---|
| 201 | | if (!mbuf) { |
|---|
| 202 | | sipc_error(sipc, "Out of memory\n"); |
|---|
| 203 | | goto err; |
|---|
| 204 | | } |
|---|
| | 208 | struct msgbuf *mbuf = sipc->mbuf; |
|---|
| | 209 | assert(mbuf); |
|---|
| | 210 | memset(mbuf, 0, SIPC_MQUEUE_MSG_SZ); |
|---|
| 205 | 211 | |
|---|
| 206 | 212 | /* Receive and validate the length of message marker */ |
|---|
| … | … | |
| 272 | 278 | err: |
|---|
| 273 | 279 | sipc->msg_len = SIPC_MSGLEN_NOT_SET; /* Unset message length */ |
|---|
| 274 | | free(mbuf); |
|---|
| 275 | 280 | return retv; |
|---|
| 276 | 281 | } |
|---|
| r33 |
r44 |
|
| 1 | 1 | TESTS = test_ipc ipc_creator ipc_destroyer |
|---|
| 2 | | AM_LDFLAGS = -lsipc -lcunit -Wl,-rpath,$(LIBDIRS) |
|---|
| | 2 | AM_CFLAGS = -I../include |
|---|
| | 3 | AM_LDFLAGS = -lsipc -lcunit -Wl,-rpath=$(TOP_BUILDDIR)/src -L$(TOP_BUILDDIR)/src |
|---|
| | 4 | TOP_BUILDDIR := $(shell pwd)/.. |
|---|
| 3 | 5 | |
|---|
| 4 | 6 | all: |
|---|
Download in other formats:
* Generating other formats may take time.