2 * (C) Copyright 2009 ZeXx86 (zexx86@gmail.com)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Based on GLugin http://exa.czweb.org/repos/glugin.tar.bz2
19 * Big thanks for "exa"
28 #include <sys/types.h>
29 #include <sys/socket.h>
34 int plugin_action_0 (pluginData
*pd
)
38 return creat ("/tmp/.arenalivep", 0777);
41 int plugin_action_1 (pluginData
*pd
)
44 struct sockaddr_un local
, remote
;
46 if ((s
= socket (AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
51 local
.sun_family
= AF_UNIX
;
52 strcpy (local
.sun_path
, "/tmp/.arenalive");
53 unlink (local
.sun_path
);
55 l
= strlen (local
.sun_path
) + sizeof (local
.sun_family
);
57 if (bind (s
, (struct sockaddr
*) &local
, l
) == -1) {
62 if (listen (s
, 5) == -1)
67 pid_t child
= fork ();
73 char *user
= getenv ("USER");
78 if (strlen (user
) > 32) {
79 Log ("ERROR -> env USER - too long");
83 unsigned l
= strlen (pd
->conparam
);
85 Log ("ERROR -> pd->conparam - too long");
89 conparam_verify (pd
->conparam
, l
);
91 /* prevent before multiple instances */
92 system ("killall arenalive-linux -s9");
96 // ~80 + 3*32 + 128 + 15 < 512 chars
97 snprintf (cmd
, 511, "LD_LIBRARY_PATH=/home/%s/.arenalive/ /home/%s/.arenalive/%s %s &> /home/%s/.arenalive/log",
98 user
, user
, "arenalive-linux", pd
->conparam
, user
);
107 if ((s2
= accept (s
, (struct sockaddr
*) &remote
, (unsigned *) &t
)) == -1) {
108 Log ("accept == -1");
112 char str
[sizeof (Window
)+1];
114 memcpy (str
, &pd
->win
, sizeof (Window
));
116 if (send (s2
, str
, sizeof (Window
), 0) < 0)
127 int plugin_action (pluginData
*pd
)
129 switch (pd
->action
) {
131 return plugin_action_0 (pd
);
133 return plugin_action_1 (pd
);