2 * Copyright (C) 2009 Sony Computer Entertainment Inc.
3 * Copyright 2009 Sony Corp.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #if defined(HAVE_CONFIG_H)
30 #include <sys/socket.h>
31 #include <sys/types.h>
34 #include "discover/user-event.h"
37 #define DBG(_args...) do {fprintf(stderr, _args); fflush(stderr); } while (0)
39 static inline int __attribute__ ((format (printf, 1, 2))) DBG(
40 __attribute__((unused)) const char *fmt, ...) {return 0; }
46 struct sockaddr_un addr;
47 char buf[PBOOT_USER_EVENT_SIZE];
52 s = socket(PF_UNIX, SOCK_DGRAM, 0);
55 fprintf(stderr, "pb-event: socket: %s\n", strerror(errno));
59 result = EXIT_SUCCESS;
61 len = fread(buf, 1, sizeof(buf), stdin);
64 fprintf(stderr, "pb-event: msg too big (%u byte max)\n",
66 result = EXIT_FAILURE;
67 /* continue on and try to write msg */
73 memset(&addr, 0, sizeof(addr));
74 addr.sun_family = AF_UNIX;
75 strcpy(addr.sun_path, PBOOT_USER_EVENT_SOCKET);
77 for (i = 10; i; i--) {
78 ssize_t sent = sendto(s, buf, len, 0, (struct sockaddr *)&addr,
84 DBG("pb-event: waiting for server %d\n", i);
89 fprintf(stderr, "pb-event: send: %s\n", strerror(errno));
93 DBG("pb-event: wrote %u bytes\n", len);