From 29efa2321b18692d80e71ea6734cea3c95f54949 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Tue, 9 Apr 2013 17:30:51 +0000 Subject: [PATCH] Add a src file for xcatflowrequest -Tried bash /dev/udp and read built-in. This causes single byte read() calls (see zread.c in bash source) -Tried gawk. No concept of a timeout and getline never did return the data right... git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@15902 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- src/xcatflowrequest.c | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/xcatflowrequest.c diff --git a/src/xcatflowrequest.c b/src/xcatflowrequest.c new file mode 100644 index 000000000..7bf604370 --- /dev/null +++ b/src/xcatflowrequest.c @@ -0,0 +1,48 @@ +/* IBM(c) 2013 EPL licens http://www.eclipse.org/legal/epl-v10.html + * Jarrod Johnson - jbjohnso@us.ibm.com + * This program periodically transmits a udp packet to designated xCAT server + * It waits for an 'ok' and then exits + */ +#include +#include +#include +#include +#include +#include +#include +int main(int argc, char* argv[]) { + int server; + struct addrinfo hints; + struct addrinfo *results,*cur; + struct timeval timeout; + int canread=0; + char buffer[128]; + srand(time(NULL)); + memset(&hints,0,sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_protocol = IPPROTO_UDP; + fd_set selectset; + getaddrinfo(argv[1],argv[2],&hints,&results); + server = socket(AF_UNSPEC,SOCK_DGRAM,17); + for (cur=results; cur != NULL; cur = cur->ai_next) { + server = socket(cur->ai_family,cur->ai_socktype,cur->ai_protocol); + if (server == -1) continue; + if (connect(server,cur->ai_addr,cur->ai_addrlen) != -1) break; + close(server); + } + FD_ZERO(&selectset); + FD_SET(server,&selectset); + while (1) { + timeout.tv_sec = rand() % 120+60; + timeout.tv_usec = rand() % 10000; + write(server,"resourcerequest: xcatd\n",strlen("resourcerequest: xcatd\n")); + canread = select(FD_SETSIZE,&selectset,NULL,NULL,&timeout); + if (canread) { + read(server,buffer,sizeof(buffer)); + if (strncmp(buffer,"resourcerequest: ok",strlen("resourcerequest: ok"))==0) { + exit(0); + } + } + } +}