From: "Andreas Büsching" <crunchy@tzi.de>
Cc: emacs-devel@gnu.org, Miles Bader <miles@gnu.org>
Subject: Re: extensions for emacsclient (CVS version)
Date: Wed, 10 Sep 2003 15:45:34 +0200 [thread overview]
Message-ID: <xtzn0dcu58h.fsf@dataman.informatik.uni-bremen.de> (raw)
In-Reply-To: <jwvhe3kstrv.fsf@noir.iro.umontreal.ca> (Stefan Monnier's message of "10 Sep 2003 08:38:28 -0400")
[-- Attachment #1: Type: text/plain, Size: 1025 bytes --]
"Stefan Monnier" <monnier@IRO.UMontreal.CA> wrote:
>>>> Okay, I understand, we _would_ need to find good and emacs like method
>>>> to handle this potential problem, but what I would like to know first is,
>>>> if this patch has any chance to get into CVS.
>>> It seems perfectly reasonable to me.
>> This sounds great. So I will work on some security stuff and user
>> feedback, when this error occurs.
>
> I also like it (actually, in the past, I've suggested to obey $TMP
> so as to be able to use different sockets, but an explicit socket-name
> argument sounds much better).
>
>> Is there also a chance to get a patch into CVS which enables
>> emacsclient to read from stdin?
>
> Sounds good to me (especially for the -eval case).
Okay, I used the time to extend the first patch with a buffer overflow
check and I also added the feature to use stdin for input if:
1. -e or --eval is given on the command line
(I think it does not make sense for filenames)
2. there is no argument after the options
RFC
crunchy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: emacsclient.c.patch --]
[-- Type: text/x-patch, Size: 3611 bytes --]
--- emacsclient.c.orig Tue Sep 9 09:21:31 2003
+++ emacsclient.c Wed Sep 10 15:39:34 2003
@@ -67,6 +67,9 @@
is not running. --alternate-editor. */
const char * alternate_editor = NULL;
+/* If non-NULL, the filename of the UNIX socket */
+const char * socket_name = NULL;
+
void print_help_and_exit ();
struct option longopts[] =
@@ -76,6 +79,7 @@
{ "help", no_argument, NULL, 'H' },
{ "version", no_argument, NULL, 'V' },
{ "alternate-editor", required_argument, NULL, 'a' },
+ { "socket-name", required_argument, NULL, 's' },
{ "display", required_argument, NULL, 'd' },
{ 0, 0, 0, 0 }
};
@@ -91,7 +95,7 @@
while (1)
{
int opt = getopt_long (argc, argv,
- "VHnea:d:", longopts, 0);
+ "VHnea:s:d:", longopts, 0);
if (opt == EOF)
break;
@@ -109,6 +113,10 @@
alternate_editor = optarg;
break;
+ case 's':
+ socket_name = optarg;
+ break;
+
case 'd':
display = optarg;
break;
@@ -152,6 +160,8 @@
-n, --no-wait Don't wait for the server to return\n\
-e, --eval Evaluate the FILE arguments as ELisp expressions\n\
-d, --display=DISPLAY Visit the file in the given display\n\
+-s, --socket-name=FILENAME\n\
+ Set the filename of the UNIX socket for communication\n\
-a, --alternate-editor=EDITOR\n\
Editor to fallback to if the server is not running\n\
\n\
@@ -300,7 +310,7 @@
/* Process options. */
decode_options (argc, argv);
- if (argc - optind < 1)
+ if ((argc - optind < 1) && !eval)
{
fprintf (stderr, "%s: file name or argument required\n", progname);
fprintf (stderr, "Try `%s --help' for more information\n", progname);
@@ -347,7 +357,22 @@
{
int sock_status = 0;
- sprintf (server.sun_path, "/tmp/emacs%d-%s/server", (int) geteuid (), system_name);
+ if (socket_name)
+ {
+ if (strlen (socket_name) > sizeof server.sun_path )
+ {
+ fprintf (stderr, "Invalid socket name (%s): the socket name is too long (max. %d)\n", socket_name, sizeof server.sun_path);
+ exit (1);
+ }
+ else
+ {
+ sprintf (server.sun_path, "%s", socket_name);
+ }
+ }
+ else
+ {
+ sprintf (server.sun_path, "/tmp/emacs%d-%s/server", (int) geteuid (), system_name);
+ }
/* See if the socket exists, and if it's owned by us. */
sock_status = socket_status (server.sun_path);
@@ -457,22 +482,33 @@
if (display)
fprintf (out, "-display %s ", quote_file_name (display));
- for (i = optind; i < argc; i++)
+ if ((argc - optind > 0))
{
- if (eval)
- ; /* Don't prepend any cwd or anything like that. */
- else if (*argv[i] == '+')
+ for (i = optind; i < argc; i++)
{
- char *p = argv[i] + 1;
- while (isdigit ((unsigned char) *p) || *p == ':') p++;
- if (*p != 0)
+ if (eval)
+ ; /* Don't prepend any cwd or anything like that. */
+ else if (*argv[i] == '+')
+ {
+ char *p = argv[i] + 1;
+ while (isdigit ((unsigned char) *p) || *p == ':') p++;
+ if (*p != 0)
+ fprintf (out, "%s/", quote_file_name (cwd));
+ }
+ else if (*argv[i] != '/')
fprintf (out, "%s/", quote_file_name (cwd));
- }
- else if (*argv[i] != '/')
- fprintf (out, "%s/", quote_file_name (cwd));
- fprintf (out, "%s ", quote_file_name (argv[i]));
+ fprintf (out, "%s ", quote_file_name (argv[i]));
+ }
+ }
+ else
+ {
+ while ((str = fgets (string, BUFSIZ, stdin)))
+ {
+ fprintf (out, "%s ", quote_file_name (str));
+ }
}
+
fprintf (out, "\n");
fflush (out);
[-- Attachment #3: Type: text/plain, Size: 181 bytes --]
--
What happens if a big asteroid hits the Earth? Judging from realistic
simulations involving a sledge hammer and a common laboratory frog, we
can assume it will be pretty bad.
[-- Attachment #4: Type: text/plain, Size: 141 bytes --]
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/emacs-devel
next prev parent reply other threads:[~2003-09-10 13:45 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-10 8:26 extensions for emacsclient (CVS version) Andreas Büsching
2003-09-10 8:44 ` Miles Bader
2003-09-10 9:00 ` Andreas Büsching
2003-09-10 9:30 ` Miles Bader
2003-09-10 10:56 ` Andreas Büsching
2003-09-10 11:36 ` Miles Bader
2003-09-10 11:40 ` Andreas Büsching
2003-09-10 12:38 ` Stefan Monnier
2003-09-10 13:45 ` Andreas Büsching [this message]
2003-09-10 14:37 ` Miles Bader
2003-09-10 15:00 ` Andreas Büsching
2003-09-10 15:09 ` Miles Bader
2003-09-11 6:57 ` Andreas Büsching
2003-09-11 23:47 ` Richard Stallman
2003-09-12 5:22 ` Andreas Buesching
2003-09-12 21:06 ` Richard Stallman
2003-09-12 7:35 ` Andreas Büsching
2003-09-10 14:41 ` Stefan Monnier
2003-09-10 15:02 ` Andreas Büsching
2003-09-10 15:08 ` Stefan Monnier
2003-09-10 16:13 ` David Kastrup
2003-09-10 16:22 ` Andreas Büsching
2003-09-10 16:50 ` David Kastrup
2003-09-10 19:40 ` Alex Schroeder
2003-09-11 5:20 ` Andreas Buesching
2003-09-11 19:30 ` Andreas Buesching
2003-09-11 21:22 ` Miles Bader
2003-09-12 21:06 ` Richard Stallman
2003-09-11 23:46 ` Richard Stallman
2003-09-12 15:38 ` Stefan Monnier
2003-09-12 22:49 ` Alex Schroeder
2003-09-13 13:56 ` Richard Stallman
2003-09-11 13:16 ` Richard Stallman
2003-09-11 14:15 ` Andreas Büsching
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xtzn0dcu58h.fsf@dataman.informatik.uni-bremen.de \
--to=crunchy@tzi.de \
--cc=emacs-devel@gnu.org \
--cc=miles@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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).