From patchwork Mon Apr 13 01:11:55 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 25889 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 688FDDECF9 for ; Mon, 13 Apr 2009 11:18:46 +1000 (EST) X-Original-To: cbe-oss-dev@ozlabs.org Delivered-To: cbe-oss-dev@ozlabs.org Received: from hera.kernel.org (hera.kernel.org [140.211.167.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 18021DE23F; Mon, 13 Apr 2009 11:16:08 +1000 (EST) Received: from hera.kernel.org (IDENT:U2FsdGVkX1892nqqd0gvGnHvAgFyxSEPNbYtoCa6SYQ@localhost [127.0.0.1]) by hera.kernel.org (8.14.2/8.14.2) with ESMTP id n3D1Fx41008746 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 13 Apr 2009 01:15:59 GMT Received: (from geoff@localhost) by hera.kernel.org (8.14.2/8.13.1/Submit) id n3D1FxMW008745; Mon, 13 Apr 2009 01:15:59 GMT Message-Id: <20090413011137.949902779@am.sony.com> References: <20090413011136.475152916@am.sony.com> In-Reply-To: <20090413011136.475152916@am.sony.com> User-Agent: quilt/0.46-1 Date: Sun, 12 Apr 2009 18:11:55 -0700 From: Geoff Levand To: Jeremy Kerr Content-Disposition: inline; filename=event-helper-util.diff X-Virus-Scanned: ClamAV 0.93.3/9226/Sun Apr 12 20:02:45 2009 on hera.kernel.org X-Virus-Status: Clean X-Spam-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00, UNPARSEABLE_RELAY,URIBL_SBL autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on hera.kernel.org X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0 (hera.kernel.org [127.0.0.1]); Mon, 13 Apr 2009 01:16:01 +0000 (UTC) Cc: cbe-oss-dev@ozlabs.org Subject: [Cbe-oss-dev] [patch 19/24] petitboot: Add pb-event helper utility X-BeenThere: cbe-oss-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Discussion about Open Source Software for the Cell Broadband Engine List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Add a new helper utility pb_event. pb_event reads data on stdin and writes it to the petitboot event socket. Signed-off-by: Geoff Levand --- configure.ac | 2 - rules.mk | 15 +++++++- utils/pb-event.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 3 deletions(-) --- a/configure.ac +++ b/configure.ac @@ -51,6 +51,6 @@ AS_IF([test "x$with_twin" != xno], [${twin_LIBS}])]) mkdir -p discover lib/list lib/log lib/pb-protocol lib/system lib/talloc \ - lib/waiter test ui/common ui/ncurses ui/test ui/twin + lib/waiter test ui/common ui/ncurses ui/test ui/twin utils AC_OUTPUT --- a/rules.mk +++ b/rules.mk @@ -13,6 +13,7 @@ pb_discover = discover/pb-discover pb_cui = ui/ncurses/pb-cui pb_test = ui/test/pb-test pb_twin = ui/twin/pb-twin +pb_event = utils/pb-event parser_test = test/parser-test # install targets and components @@ -20,6 +21,7 @@ daemons = $(pb_discover) parsers = event kboot yaboot uis = $(pb_test) tests = $(parser_test) +utils = $(pb_event) ifeq ($(PBTWIN),y) uis += $(pb_twin) @@ -61,7 +63,7 @@ daemon_objs = $(lib_objs) $(parser_objs) client_objs = $(lib_objs) $(ui_common_objs) -all: $(uis) $(daemons) +all: $(uis) $(daemons) $(utils) # ncurses cui pb_cui_objs = $(client_objs) $(ncurses_objs) ui/ncurses/ps3-cui.o \ @@ -97,6 +99,13 @@ $(pb_discover_objs): $(makefiles) $(pb_discover): $(pb_discover_objs) $(LINK.o) -o $@ $^ +# utils +pb_event_objs = utils/pb-event.o +$(pb_event_objs): $(makefiles) + +$(pb_event): $(pb_event_objs) + $(LINK.o) -o $@ $^ + # parser-test parser_test_objs = $(lib_objs) $(parser_objs) test/parser-test.o $(parser_test_objs): $(makefiles) @@ -108,7 +117,7 @@ parser-test: $(parser_test) install: all $(rules) $(INSTALL) -d $(DESTDIR)$(sbindir)/ - $(INSTALL) $(daemons) $(uis) $(DESTDIR)$(sbindir)/ + $(INSTALL) $(daemons) $(uis) $(utils) $(DESTDIR)$(sbindir)/ $(INSTALL) -d $(DESTDIR)$(pkgdatadir)/artwork/ $(INSTALL) $(addprefix $(top_srcdir)/ui/twin/artwork/,$(artwork)) \ $(DESTDIR)$(pkgdatadir)/artwork/ @@ -142,6 +151,8 @@ clean: rm -f $(pb_twin_objs) rm -f $(daemons) rm -f $(pb_discover_objs) + rm -f $(utils) + rm -f $(pb_event_objs) rm -f $(tests) rm -f $(parser_test_objs) --- /dev/null +++ b/utils/pb-event.c @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2009 Sony Computer Entertainment Inc. + * Copyright 2009 Sony Corp. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#if defined(HAVE_CONFIG_H) +#include "config.h" +#endif + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "discover/user-event.h" + +#if defined(DEBUG) +#define DBG(_args...) do {fprintf(stderr, _args); fflush(stderr); } while (0) +#else +static inline int __attribute__ ((format (printf, 1, 2))) DBG( + __attribute__((unused)) const char *fmt, ...) {return 0; } +#endif + +int main(void) +{ + int result; + struct sockaddr_un addr; + char buf[PBOOT_USER_EVENT_SIZE]; + ssize_t len; + int s; + int i; + + s = socket(PF_UNIX, SOCK_DGRAM, 0); + + if (s < 0) { + fprintf(stderr, "pb-event: socket: %s\n", strerror(errno)); + return EXIT_FAILURE; + } + + result = EXIT_SUCCESS; + + len = fread(buf, 1, sizeof(buf), stdin); + + if (!feof(stdin)) { + fprintf(stderr, "pb-event: msg too big (%u byte max)\n", + sizeof(buf)); + result = EXIT_FAILURE; + /* continue on and try to write msg */ + } + + if (!len) + return result; + + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + strcpy(addr.sun_path, PBOOT_USER_EVENT_SOCKET); + + for (i = 10; i; i--) { + ssize_t sent = sendto(s, buf, len, 0, (struct sockaddr *)&addr, + SUN_LEN(&addr)); + + if (sent == len) + break; + + DBG("pb-event: waiting for server %d\n", i); + sleep(1); + } + + if (!i) { + fprintf(stderr, "pb-event: send: %s\n", strerror(errno)); + return EXIT_FAILURE; + } + + DBG("pb-event: wrote %u bytes\n", len); + return result; +}