2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 /* FIXME: The signal handling of this module is largely broken */
21 #include "FvwmConsole.h"
24 int s
; /* socket handle */
26 char *name
; /* name of this program at executing time */
30 * close socket and exit
44 RETSIGTYPE
ReapChildren(int sig
)
46 fvwmReapChildren(sig
);
53 * print error message on stderr
55 void ErrMsg(char *msg
)
57 fprintf(stderr
, "%s error in %s: %s\n", name
, msg
, strerror(errno
));
68 * send command to and receive message from the server
70 int main(int argc
, char *argv
[])
73 char data
[MAX_MESSAGE_SIZE
];
74 int len
; /* length of socket address */
75 struct sockaddr_un sas
;
76 int clen
; /* command length */
77 int pid
; /* child process id */
82 signal(SIGCHLD
, ReapChildren
);
83 signal(SIGPIPE
, sclose
);
84 signal(SIGINT
, sclose
);
85 signal(SIGQUIT
, sclose
);
87 name
=strrchr(argv
[0], '/');
94 home
= getenv("FVWM_USERDIR");
95 s_name
= safemalloc(strlen(home
) + sizeof(S_NAME
) + 1);
97 strcat(s_name
, S_NAME
);
98 s
= socket(AF_UNIX
, SOCK_STREAM
, 0);
103 /* name the socket and obtain the size of it*/
104 sas
.sun_family
= AF_UNIX
;
105 strcpy(sas
.sun_path
, s_name
);
106 len
= sizeof(sas
) - sizeof(sas
.sun_path
) + strlen(sas
.sun_path
);
107 rc
= connect(s
, (struct sockaddr
*)&sas
, len
);
124 /* loop of get user's command and send it to server */
138 /* send the command including null to the server */
140 fvwm_send(s
, cmd
, strlen(cmd
) + 1, 0);
142 kill(getppid(), SIGKILL
);
145 while (fgets(data
, MAX_MESSAGE_SIZE
, sp
))
147 /* get the response */
148 /* ignore config lines */
149 if (!strcmp(data
, C_BEG
))
151 while (fgets(data
, MAX_MESSAGE_SIZE
, sp
))
153 if (*data
== '\0' || !strcmp(data
,C_END
))