uic.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (C) 2006 Steven Dake (sdake@mvista.com)
  3. *
  4. * This software licensed under BSD license, the text of which follows:
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * - Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * - Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from this
  16. * software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  28. * THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include <sys/uio.h>
  31. #include <sys/mman.h>
  32. #include <sys/socket.h>
  33. #include <sys/un.h>
  34. #include <sys/sysinfo.h>
  35. #include <sys/time.h>
  36. #include <sys/resource.h>
  37. #include <netinet/in.h>
  38. #include <arpa/inet.h>
  39. #include <unistd.h>
  40. #include <fcntl.h>
  41. #include <stdlib.h>
  42. #include <stdio.h>
  43. #include <errno.h>
  44. #include <signal.h>
  45. #include <sched.h>
  46. #include <time.h>
  47. #include <pthread.h>
  48. #include <sys/poll.h>
  49. char *socketname = "lcr.uis.socket";
  50. int uic_connect (int *fd)
  51. {
  52. int res;
  53. struct sockaddr_un addr;
  54. memset (&addr, 0, sizeof (struct sockaddr_un));
  55. addr.sun_family = PF_UNIX;
  56. strcpy (addr.sun_path + 1, "lcr.socket");
  57. *fd = socket (PF_UNIX, SOCK_STREAM, 0);
  58. if (*fd == -1) {
  59. return -errno;
  60. }
  61. res = connect (*fd, (struct sockaddr *)&addr, sizeof (addr));
  62. if (res == -1) {
  63. return -errno;
  64. }
  65. return 0;
  66. }
  67. struct req_msg {
  68. int len;
  69. char msg[0];
  70. };
  71. int uic_msg_send (int fd, char *msg)
  72. {
  73. struct msghdr msg_send;
  74. struct iovec iov_send[2];
  75. struct req_msg req_msg;
  76. int res;
  77. req_msg.len = strlen (msg) + 1;
  78. iov_send[0].iov_base = (void *)&req_msg;
  79. iov_send[0].iov_len = sizeof (struct req_msg);
  80. iov_send[1].iov_base = (void *)msg;
  81. iov_send[1].iov_len = req_msg.len;
  82. msg_send.msg_iov = iov_send;
  83. msg_send.msg_iovlen = 2;
  84. msg_send.msg_name = 0;
  85. msg_send.msg_namelen = 0;
  86. msg_send.msg_control = 0;
  87. msg_send.msg_controllen = 0;
  88. msg_send.msg_flags = 0;
  89. retry_send:
  90. res = sendmsg (fd, &msg_send, 0);
  91. if (res == -1 && errno == EINTR) {
  92. goto retry_send;
  93. }
  94. if (res == -1) {
  95. res = -errno;
  96. }
  97. return (res);
  98. }
  99. int main (void)
  100. {
  101. int client_fd;
  102. int res;
  103. res = uic_connect (&client_fd);
  104. if (res != 0) {
  105. printf ("Couldn't connect to live replacement service\n");
  106. }
  107. uic_msg_send (client_fd, "livereplace ckpt version 2");
  108. return 0;
  109. }