summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/actions.c1
-rw-r--r--src/communications.c11
-rw-r--r--src/communications.h2
-rw-r--r--src/events.c2
-rw-r--r--src/main.c36
-rw-r--r--src/ratpoison.h7
6 files changed, 45 insertions, 14 deletions
diff --git a/src/actions.c b/src/actions.c
index 2b065e3..f547a38 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -736,6 +736,7 @@ cmd_source (int interactive, char *data)
marked_message_printf (0, 0, " source: %s : %s ", data, strerror(errno));
else
{
+ set_close_on_exec (fileptr);
read_rc_file (fileptr);
fclose (fileptr);
}
diff --git a/src/communications.c b/src/communications.c
index 4e4e509..352a7ef 100644
--- a/src/communications.c
+++ b/src/communications.c
@@ -81,10 +81,15 @@ recieve_command_result (Window w)
}
int
-send_command (unsigned char *cmd, int screen_num)
+send_command (unsigned char interactive, unsigned char *cmd, int screen_num)
{
Window w;
int done = 0;
+ struct sbuf *s;
+
+ s = sbuf_new(0);
+ sbuf_printf(s, "%c%s", interactive, cmd);
+
/* If the user specified a specific screen, then send the event to
that screen. */
@@ -103,12 +108,14 @@ send_command (unsigned char *cmd, int screen_num)
XSelectInput (dpy, w, PropertyChangeMask);
XChangeProperty (dpy, w, rp_command, XA_STRING,
- 8, PropModeReplace, cmd, strlen (cmd) + 1);
+ 8, PropModeReplace, sbuf_get(s), strlen (cmd) + 2);
XChangeProperty (dpy, DefaultRootWindow (dpy),
rp_command_request, XA_WINDOW,
8, PropModeAppend, (unsigned char *)&w, sizeof (Window));
+ sbuf_free (s);
+
while (!done)
{
XEvent ev;
diff --git a/src/communications.h b/src/communications.h
index 3bd6046..c371282 100644
--- a/src/communications.h
+++ b/src/communications.h
@@ -22,6 +22,6 @@
#ifndef _RATPOISON_COMMUNICATIONS_H
#define _RATPOISON_COMMUNICATIONS_H 1
-int send_command (unsigned char *cmd, int screen_num);
+int send_command (unsigned char interactive, unsigned char *cmd, int screen_num);
#endif /* ! _RATPOISON_COMMUNICATIONS_H */
diff --git a/src/events.c b/src/events.c
index 85548a4..7221883 100644
--- a/src/events.c
+++ b/src/events.c
@@ -446,7 +446,7 @@ execute_remote_command (Window w)
}
PRINT_DEBUG (("command: %s\n", req));
- result = command (0, req);
+ result = command (req[0], &req[1]);
XFree (req);
return result;
diff --git a/src/main.c b/src/main.c
index e44ee62..e252d75 100644
--- a/src/main.c
+++ b/src/main.c
@@ -48,14 +48,15 @@ static void init_screen (rp_screen *s, int screen_num);
/* Command line options */
static struct option ratpoison_longopts[] =
- { {"help", no_argument, 0, 'h'},
- {"version", no_argument, 0, 'v'},
- {"command", required_argument, 0, 'c'},
- {"display", required_argument, 0, 'd'},
- {"screen", required_argument, 0, 's'},
- {0, 0, 0, 0} };
+ { {"help", no_argument, 0, 'h'},
+ {"interactive", no_argument, 0, 'i'},
+ {"version", no_argument, 0, 'v'},
+ {"command", required_argument, 0, 'c'},
+ {"display", required_argument, 0, 'd'},
+ {"screen", required_argument, 0, 's'},
+ {0, 0, 0, 0} };
-static char ratpoison_opts[] = "hvc:d:s:";
+static char ratpoison_opts[] = "hvic:d:s:";
void
fatal (const char *msg)
@@ -289,7 +290,8 @@ print_help ()
printf ("-v, --version Display the version\n");
printf ("-d, --display <dpy> Set the X display to use\n");
printf ("-s, --screen <num> Only use the specified screen\n");
- printf ("-c, --command <cmd> Send ratpoison a colon-command\n\n");
+ printf ("-c, --command <cmd> Send ratpoison a colon-command\n");
+ printf ("-i, --interactive Execute commands in interactive mode\n\n");
printf ("Report bugs to ratpoison-devel@lists.sourceforge.net\n\n");
@@ -297,6 +299,15 @@ print_help ()
}
void
+set_close_on_exec (FILE *fd)
+{
+ int fnum = fileno (fd);
+ int flags = fcntl (fnum, F_GETFD);
+ if (flags >= 0)
+ fcntl (fnum, F_SETFD, flags | FD_CLOEXEC);
+}
+
+void
read_rc_file (FILE *file)
{
size_t n = 256;
@@ -384,6 +395,7 @@ read_startup_files ()
if (fileptr)
{
+ set_close_on_exec(fileptr);
read_rc_file (fileptr);
fclose (fileptr);
}
@@ -484,6 +496,7 @@ main (int argc, char *argv[])
int screen_arg = 0;
int screen_num = 0;
char *display = NULL;
+ unsigned char interactive = 0;
myargv = argv;
@@ -524,6 +537,9 @@ main (int argc, char *argv[])
screen_arg = 1;
screen_num = strtol (optarg, NULL, 10);
break;
+ case 'i':
+ interactive = 1;
+ break;
default:
exit (EXIT_FAILURE);
@@ -549,9 +565,9 @@ main (int argc, char *argv[])
for (i=0; i<cmd_count; i++)
{
if (screen_arg)
- send_command (command[i], screen_num);
+ send_command (interactive, command[i], screen_num);
else
- send_command (command[i], -1);
+ send_command (interactive, command[i], -1);
free (command[i]);
}
diff --git a/src/ratpoison.h b/src/ratpoison.h
index 5d4bd7b..0a9719e 100644
--- a/src/ratpoison.h
+++ b/src/ratpoison.h
@@ -30,6 +30,12 @@
#include <stdio.h>
#include <stdarg.h>
#include <X11/Xlib.h>
+#include <fcntl.h>
+
+/* Some systems don't define the close-on-exec flag in fcntl.h */
+#ifndef FD_CLOEXEC
+# define FD_CLOEXEC 1
+#endif
/* Helper macro for error and debug reporting. */
#define PRINT_LINE(type) printf (PACKAGE ":%s:%d: %s: ",__FILE__, __LINE__, #type)
@@ -82,6 +88,7 @@ extern XGCValues gv;
void clean_up ();
rp_screen *find_screen (Window w);
+void set_close_on_exec (FILE *fd);
void read_rc_file (FILE *file);
void fatal (const char *msg);