klish.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <stdlib.h>
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <assert.h>
  6. #include <unistd.h>
  7. #include <errno.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <fcntl.h>
  11. #include <getopt.h>
  12. #include <sys/socket.h>
  13. #include <sys/un.h>
  14. #include <faux/faux.h>
  15. #include <faux/str.h>
  16. #include <klish/ktp.h>
  17. #include <klish/ktp_session.h>
  18. #include "private.h"
  19. int main(int argc, char **argv)
  20. {
  21. int retval = -1;
  22. struct options *opts = NULL;
  23. int unix_sock = -1;
  24. ktp_session_t *session = NULL;
  25. // Parse command line options
  26. opts = opts_init();
  27. if (opts_parse(argc, argv, opts)) {
  28. fprintf(stderr, "Error: Can't parse command line options\n");
  29. goto err;
  30. }
  31. // Connect to server
  32. unix_sock = ktp_connect_unix(opts->unix_socket_path);
  33. if (unix_sock < 0) {
  34. fprintf(stderr, "Error: Can't connect to server\n");
  35. goto err;
  36. }
  37. session = ktp_session_new(unix_sock);
  38. assert(session);
  39. if (!session) {
  40. fprintf(stderr, "Error: Can't create klish session\n");
  41. goto err;
  42. }
  43. write(ktp_session_fd(session), "hello", 5);
  44. retval = 0;
  45. err:
  46. ktp_session_free(session);
  47. ktp_disconnect(unix_sock);
  48. opts_free(opts);
  49. return retval;
  50. }