ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtc.C
Revision: 1.9
Committed: Fri Apr 2 20:41:01 2004 UTC (20 years, 1 month ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_7
Changes since 1.8: +2 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #include "../config.h"
2 #include "rxvtdaemon.h"
3
4 #include "rxvt.h"
5
6 #include <cstdio>
7 #include <cstdlib>
8
9 #include <unistd.h>
10 #include <signal.h>
11 #include <sys/socket.h>
12 #include <sys/un.h>
13
14 struct client : rxvt_connection {
15 client ();
16 };
17
18 client::client ()
19 {
20 if ((fd = socket (PF_LOCAL, SOCK_STREAM, 0)) < 0)
21 {
22 perror ("unable to create communications socket");
23 exit (EXIT_FAILURE);
24 }
25
26 char *sockname = rxvt_connection::unix_sockname ();
27 sockaddr_un sa;
28 sa.sun_family = AF_UNIX;
29 strcpy (sa.sun_path, sockname);
30 free (sockname);
31
32 if (connect (fd, (sockaddr *)&sa, sizeof (sa)))
33 {
34 perror ("unable to connect to rxvtd");
35 exit (EXIT_FAILURE);
36 }
37 }
38
39 extern char **environ;
40
41 int
42 main (int argc, const char *const *argv)
43 {
44 client c;
45 char buf[PATH_MAX];
46
47 {
48 sigset_t ss;
49
50 sigemptyset (&ss);
51 sigaddset (&ss, SIGHUP);
52 sigprocmask (SIG_BLOCK, &ss, 0);
53 }
54
55 c.send ("NEW");
56 // instead of getcwd we could opendir (".") and pass the fd for fchdir *g*
57 c.send ("CWD"), c.send (getcwd (buf, sizeof (buf)));
58
59 for (char **var = environ; *environ; environ++)
60 c.send ("ENV"), c.send (*environ);
61
62 for (int i = 0; i < argc; i++)
63 c.send ("ARG"), c.send (argv[i]);
64
65 c.send ("END");
66
67 auto_str tok;
68
69 for (;;)
70 if (!c.recv (tok))
71 {
72 fprintf (stderr, "protocol error: unexpected eof from server.\n");
73 break;
74 }
75 else if (!strcmp (tok, "MSG") && c.recv (tok))
76 fprintf (stderr, "%s", (const char *)tok);
77 else if (!strcmp (tok, "END"))
78 {
79 int success;
80 if (c.recv (success))
81 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);
82 }
83 else
84 {
85 fprintf (stderr, "protocol error: received illegal token '%s'.\n", (const char *)tok);
86 break;
87 }
88
89 return EXIT_FAILURE;
90 }
91