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