commit 390e0c3b5793178042a1a9a94ca6f62119a3b0ab
parent 928e54321874287fc9956dceb215961c39240608
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Wed, 1 Feb 2006 15:03:45 +0200
implemented '#write <file> <data>' semantic for spawn(), removed static linkage against libc for wmiir (due to gethostbyname issues)
Diffstat:
3 files changed, 46 insertions(+), 8 deletions(-)
diff --git a/cmd/Makefile b/cmd/Makefile
@@ -50,7 +50,7 @@ wmiimenu: ${OBJ_menu}
wmiir: ${OBJ_r}
@echo LD $@
- @${CC} -o $@ ${OBJ_r} -g -static -L${PREFIX}/lib -L/usr/lib -lc \
+ @${CC} -o $@ ${OBJ_r} -g -L${PREFIX}/lib -L/usr/lib -lc \
-L../libixp -lixp -L../libcext -lcext
# Solaris
# @${CC} -o $@ ${OBJ_r} -g -static -L${PREFIX}/lib -L/usr/lib -lc \
diff --git a/cmd/wmiir.c b/cmd/wmiir.c
@@ -25,7 +25,7 @@ usage()
{
fprintf(stderr, "%s",
"usage: wmiir [-a <server address>] [-v] <command>\n"
- " -a server address (default: $WMIIR_ADDRESS)\n"
+ " -a server address (default: $WMII_ADDRESS)\n"
" -v version info\n"
"valid commands:\n"
" create <file> -- creates file and writes data from stdin to file\n"
@@ -182,7 +182,7 @@ int
main(int argc, char *argv[])
{
int i = 0;
- char *cmd, *file, *sockfile = getenv("WMIIR_ADDRESS");
+ char *cmd, *file, *address = getenv("WMII_ADDRESS");
/* command line args */
if(argc < 2)
@@ -196,7 +196,7 @@ main(int argc, char *argv[])
break;
case 'a':
if(i + 1 < argc)
- sockfile = argv[++i];
+ address = argv[++i];
else
usage();
break;
@@ -208,12 +208,12 @@ main(int argc, char *argv[])
cmd = argv[argc - 2];
file = argv[argc - 1];
- if(!sockfile) {
- fprintf(stderr, "%s", "wmiir: error: $WMIIR_ADDRESS not set\n");
+ if(!address) {
+ fprintf(stderr, "%s", "wmiir: error: $WMII_ADDRESS not set\n");
usage();
}
/* open socket */
- if(ixp_client_init(&c, sockfile) == -1) {
+ if(ixp_client_init(&c, address) == -1) {
fprintf(stderr, "wmiir: %s\n", c.errstr);
exit(1);
}
diff --git a/libwmii/spawn.c b/libwmii/spawn.c
@@ -5,17 +5,55 @@
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "wmii.h"
+static void
+spawn_ixp_write(char *cmd)
+{
+ static IXPClient c;
+ char *file = cmd;
+ char *data = strchr(cmd, ' ');
+ char *address = getenv("WMII_ADDRESS");
+ unsigned int fid = c.root_fid << 2;
+ size_t len;
+
+ if(!data || !cmd || !address)
+ return;
+ *data = 0;
+ data++;
+ len = strlen(data);
+
+ if(ixp_client_init(&c, address) == -1) {
+ fprintf(stderr, "libwmii: %s\n", c.errstr);
+ return;
+ }
+ /* open */
+ if(ixp_client_open(&c, fid, file, IXP_OWRITE) == -1) {
+ fprintf(stderr, "libwmii: cannot open file '%s': %s\n", file, c.errstr);
+ return;
+ }
+ if(ixp_client_write(&c, fid, 0, len, (void *)data) != len) {
+ fprintf(stderr, "wmiir: cannot write file: %s\n", c.errstr);
+ return;
+ }
+ ixp_client_close(&c, fid);
+ ixp_client_deinit(&c);
+}
+
void
wmii_spawn(void *dpy, char *cmd)
{
/* the questionable double-fork is done to catch all zombies */
- if(fork() == 0) {
+ if(!cmd)
+ return;
+ if(!strncmp(cmd, "#write ", 7))
+ spawn_ixp_write(&cmd[7]);
+ else if(fork() == 0) {
if(fork() == 0) {
setsid();
close(ConnectionNumber(dpy));