ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtc.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtc.C (file contents):
Revision 1.1 by pcg, Mon Nov 24 17:28:08 2003 UTC vs.
Revision 1.9 by pcg, Fri Apr 2 20:41:01 2004 UTC

1#include "../config.h"
1#include "rxvtdaemon.h" 2#include "rxvtdaemon.h"
3
4#include "rxvt.h"
2 5
3#include <cstdio> 6#include <cstdio>
4#include <cstdlib> 7#include <cstdlib>
5 8
6#include <unistd.h> 9#include <unistd.h>
10#include <signal.h>
7#include <sys/socket.h> 11#include <sys/socket.h>
8#include <sys/un.h> 12#include <sys/un.h>
9 13
10struct client : rxvt_connection { 14struct client : rxvt_connection {
11 client (); 15 client ();
13 17
14client::client () 18client::client ()
15{ 19{
16 if ((fd = socket (PF_LOCAL, SOCK_STREAM, 0)) < 0) 20 if ((fd = socket (PF_LOCAL, SOCK_STREAM, 0)) < 0)
17 { 21 {
18 perror ("unable to create listening socket"); 22 perror ("unable to create communications socket");
19 exit (EXIT_FAILURE); 23 exit (EXIT_FAILURE);
20 } 24 }
21 25
26 char *sockname = rxvt_connection::unix_sockname ();
22 sockaddr_un sa; 27 sockaddr_un sa;
23
24 sa.sun_family = AF_UNIX; 28 sa.sun_family = AF_UNIX;
25 strcpy (sa.sun_path, rxvt_connection::unix_sockname ()); 29 strcpy (sa.sun_path, sockname);
30 free (sockname);
26 31
27 if (connect (fd, (sockaddr *)&sa, sizeof (sa))) 32 if (connect (fd, (sockaddr *)&sa, sizeof (sa)))
28 { 33 {
29 perror ("unable to bind listening socket"); 34 perror ("unable to connect to rxvtd");
30 exit (EXIT_FAILURE); 35 exit (EXIT_FAILURE);
31 } 36 }
32} 37}
33 38
39extern char **environ;
40
34int 41int
35main(int argc, const char *const *argv) 42main (int argc, const char *const *argv)
36{ 43{
37 client c; 44 client c;
38 char buf[PATH_MAX]; 45 char buf[PATH_MAX];
39 46
47 {
48 sigset_t ss;
49
50 sigemptyset (&ss);
51 sigaddset (&ss, SIGHUP);
52 sigprocmask (SIG_BLOCK, &ss, 0);
53 }
54
40 c.send ("NEW"); 55 c.send ("NEW");
41 c.send ("DISPLAY"); c.send (getenv ("DISPLAY"));
42 // instead of getcwd we could opendir(".") and pass the fd for fchdir *g* 56 // instead of getcwd we could opendir (".") and pass the fd for fchdir *g*
43 c.send ("CWD"); c.send (getcwd (buf, sizeof (buf))); 57 c.send ("CWD"), c.send (getcwd (buf, sizeof (buf)));
44 58
45 c.send ("ARGV"); c.send (argc); 59 for (char **var = environ; *environ; environ++)
60 c.send ("ENV"), c.send (*environ);
61
46 for (int i = 0; i < argc; i++) 62 for (int i = 0; i < argc; i++)
47 c.send (argv[i]); 63 c.send ("ARG"), c.send (argv[i]);
64
48 c.send ("END"); 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;
49} 90}
50 91

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines