Fixed up copyright year mention.
[dabba.git] / dabba / ipc.c
blob84c4fa0d4fa8e87fd2aace4c14dc7c1a75b2070d
1 /* __LICENSE_HEADER_BEGIN__ */
3 /*
4 * Copyright (C) 2012 Emmanuel Roullit <emmanuel.roullit@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
22 /* __LICENSE_HEADER_END__ */
24 #include <stdio.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <assert.h>
28 #include <errno.h>
29 #include <dabba/ipc.h>
31 int dabba_ipc_msg(struct dabba_ipc_msg *msg)
33 int qid;
34 ssize_t rcv;
35 int snd;
37 assert(msg);
39 qid = dabba_get_ipc_queue_id(0660);
41 if (qid < 0) {
42 perror("Cannot get IPC id");
43 return errno;
46 snd = msgsnd(qid, msg, sizeof(msg->msg_body), 0);
48 if (snd < 0) {
49 perror("Error while sending IPC msg");
50 return errno;
53 usleep(100);
55 rcv = msgrcv(qid, msg, sizeof(msg->msg_body), 0, 0);
57 if (rcv <= 0) {
58 perror("Error while receiving IPC msg");
59 return errno;
62 if (msg->msg_body.error != 0) {
63 printf("The daemon reported: %s\n",
64 strerror(msg->msg_body.error));
65 return msg->msg_body.error;
68 return 0;