From: Spencer Baugh <sbaugh@catern.com>
To: emacs-devel@gnu.org
Cc: Spencer Baugh <sbaugh@catern.com>
Subject: [PATCH 3/5] emacsclient: support passing stdin/out/err to emacs
Date: Mon, 6 Jun 2016 21:25:04 -0400 [thread overview]
Message-ID: <1465262706-5229-4-git-send-email-sbaugh@catern.com> (raw)
In-Reply-To: <1465262706-5229-1-git-send-email-sbaugh@catern.com>
To make this more useful, the terminal name is now also determined by
looking at stderr, not stdout. If stderr is redirected, we'll still have
trouble, though...
---
lib-src/emacsclient.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 42 insertions(+), 3 deletions(-)
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index aab9c4b..1b1f75a 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -76,6 +76,7 @@ char *w32_getenv (const char *);
#include <stdio.h>
#include <getopt.h>
#include <unistd.h>
+#include <fcntl.h>
#include <pwd.h>
#include <sys/stat.h>
@@ -119,6 +120,12 @@ int quiet = 0;
/* Nonzero means args are expressions to be evaluated. --eval. */
int eval = 0;
+/* Nonzero means we will pass stdin/stdout/stderr to Emacs. --pipeline. */
+int pipeline = 0;
+
+/* Nonzero means pass stdin/stdout/stderr to Emacs on next write. */
+int send_fds_once = 0;
+
/* Nonzero means don't open a new frame. Inverse of --create-frame. */
int current_frame = 1;
@@ -163,6 +170,7 @@ struct option longopts[] =
{ "version", no_argument, NULL, 'V' },
{ "tty", no_argument, NULL, 't' },
{ "nw", no_argument, NULL, 't' },
+ { "pipeline", no_argument, NULL, 'l' },
{ "create-frame", no_argument, NULL, 'c' },
{ "alternate-editor", required_argument, NULL, 'a' },
{ "frame-parameters", required_argument, NULL, 'F' },
@@ -468,7 +476,7 @@ decode_options (int argc, char **argv)
{
int opt = getopt_long_only (argc, argv,
#ifndef NO_SOCKETS_IN_FILE_SYSTEM
- "VHneqa:s:f:d:F:tc",
+ "VHneqla:s:f:d:F:tc",
#else
"VHneqa:f:d:F:tc",
#endif
@@ -492,6 +500,11 @@ decode_options (int argc, char **argv)
case 's':
socket_name = optarg;
break;
+
+ case 'l':
+ pipeline = 1;
+ send_fds_once = 1;
+ break;
#endif
case 'f':
@@ -738,7 +751,33 @@ send_to_emacs (HSOCKET s, const char *data)
if (sblen == SEND_BUFFER_SIZE
|| (sblen > 0 && send_buffer[sblen-1] == '\n'))
{
- int sent = send (s, send_buffer, sblen, 0);
+ int sent;
+ if (send_fds_once) {
+ struct iovec iov;
+ struct msghdr msgh;
+ char cbuf[512] = {};
+ iov = (struct iovec) { .iov_base = send_buffer,
+ .iov_len = sblen, };
+ msgh = (struct msghdr) { .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_control = cbuf,
+ .msg_controllen = sizeof cbuf, };
+ struct cmsghdr *cmsg;
+ int myfds[3] = { 0, 1, 2 };
+ cmsg = CMSG_FIRSTHDR(&msgh);
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(sizeof (myfds));
+ /* Initialize the payload: */
+ memcpy(CMSG_DATA(cmsg), myfds, sizeof (myfds));
+ /* Sum of the length of all control messages in the buffer: */
+ msgh.msg_controllen = cmsg->cmsg_len;
+
+ sent = sendmsg (s, &msgh, 0);
+ send_fds_once = 0;
+ } else {
+ sent = send (s, send_buffer, sblen, 0);
+ }
if (sent < 0)
{
message (true, "%s: failed to send %d bytes to socket: %s\n",
@@ -1019,7 +1058,7 @@ static int
find_tty (const char **tty_type, const char **tty_name, int noabort)
{
const char *type = egetenv ("TERM");
- const char *name = ttyname (fileno (stdout));
+ const char *name = ttyname (fileno (stderr));
if (!name)
{
--
2.8.2
next prev parent reply other threads:[~2016-06-07 1:25 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-07 1:25 Teaching emacsclient to act as a pager, and more Spencer Baugh
2016-06-07 1:25 ` [PATCH 1/5] process: add features for direct use of FDs Spencer Baugh
2016-06-07 1:25 ` [PATCH 2/5] server.el: accept FDs from emacsclient Spencer Baugh
2016-06-07 1:25 ` Spencer Baugh [this message]
2016-06-07 1:25 ` [PATCH 4/5] server: add pager tapping and show-active Spencer Baugh
2016-06-07 1:25 ` [PATCH 5/5] emacsclient: add extra-quiet mode Spencer Baugh
2016-06-08 15:51 ` Teaching emacsclient to act as a pager, and more Tassilo Horn
2016-06-08 16:13 ` Anders Lindgren
2016-06-08 17:30 ` Tassilo Horn
2016-06-09 0:25 ` raman
2016-06-09 11:31 ` H. Dieter Wilhelm
2016-06-27 22:42 ` Ole JørgenBrønner
2016-07-24 18:22 ` sbaugh
2016-09-09 13:42 ` Noam Postavsky
2016-09-09 14:14 ` sbaugh
2016-09-09 14:59 ` Stefan Monnier
2016-09-09 15:58 ` sbaugh
2016-09-09 19:26 ` Stefan Monnier
2016-09-09 19:42 ` Eli Zaretskii
2016-09-09 21:13 ` sbaugh
2016-09-10 6:37 ` Using file descriptors in Emacs (was: Teaching emacsclient to act as a pager, and more) Eli Zaretskii
2016-09-10 20:15 ` Teaching emacsclient to act as a pager, and more sbaugh
2016-09-11 2:11 ` Leo Liu
2018-02-16 23:14 ` Kaushal Modi
2018-02-17 15:46 ` Göktuğ Kayaalp
2016-09-09 15:53 ` Eli Zaretskii
2016-09-09 17:16 ` sbaugh
2016-09-09 18:50 ` Eli Zaretskii
2016-09-09 19:03 ` sbaugh
2016-09-09 19:26 ` Eli Zaretskii
2016-09-09 20:38 ` sbaugh
2016-09-10 7:12 ` Using file descriptors in Emacs Eli Zaretskii
2016-09-10 14:28 ` sbaugh
2016-09-11 15:28 ` Eli Zaretskii
2016-09-11 16:00 ` sbaugh
2016-09-11 16:39 ` Eli Zaretskii
2016-09-11 16:57 ` sbaugh
2016-09-11 17:13 ` Eli Zaretskii
2016-09-12 15:40 ` Davis Herring
2016-09-09 13:27 ` Teaching emacsclient to act as a pager, and more sbaugh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1465262706-5229-4-git-send-email-sbaugh@catern.com \
--to=sbaugh@catern.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.