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.8 by pcg, Wed Mar 17 05:15:02 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines