From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: =?iso-8859-1?q?Andreas_B=FCsching?= Newsgroups: gmane.emacs.devel Subject: Re: extensions for emacsclient (CVS version) Date: Wed, 10 Sep 2003 15:45:34 +0200 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1063201919 7474 80.91.224.253 (10 Sep 2003 13:51:59 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 10 Sep 2003 13:51:59 +0000 (UTC) Cc: emacs-devel@gnu.org, Miles Bader Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Wed Sep 10 15:51:57 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19x5O1-0000rj-00 for ; Wed, 10 Sep 2003 15:51:57 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 19x5OP-0001hx-00 for ; Wed, 10 Sep 2003 15:52:22 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.22) id 19x5Me-0007R0-DM for emacs-devel@quimby.gnus.org; Wed, 10 Sep 2003 09:50:32 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.22) id 19x5MX-0007Pz-NU for emacs-devel@gnu.org; Wed, 10 Sep 2003 09:50:25 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.22) id 19x5MV-0007Oi-7e for emacs-devel@gnu.org; Wed, 10 Sep 2003 09:50:24 -0400 Original-Received: from [199.232.41.8] (helo=mx20.gnu.org) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.22) id 19x5MU-0007Oa-RI; Wed, 10 Sep 2003 09:50:22 -0400 Original-Received: from [134.102.224.4] (helo=imh.informatik.uni-bremen.de) by mx20.gnu.org with esmtp (Exim 4.22) id 19x5Hs-0008Qb-Qe; Wed, 10 Sep 2003 09:45:36 -0400 Original-Received: from dataman.informatik.uni-bremen.de (IDENT:j1KlZ2FgWtf6jXcDNEHqF3omFO4zLaSW@dataman.informatik.uni-bremen.de [134.102.218.127]) by imh.informatik.uni-bremen.de (8.12.9/8.12.9) with ESMTP id h8ADjYe0023850; Wed, 10 Sep 2003 15:45:34 +0200 (MEST) Original-Received: (from crunchy@localhost) by dataman.informatik.uni-bremen.de (8.11.6/8.8.7) id h8ADjYm21036; Wed, 10 Sep 2003 15:45:34 +0200 Original-To: "Stefan Monnier" Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAALVBMVEUAAADgvEcRDgkCAAD4 +PjoxUn//+35+PFNQyz////+/vTCnz7l3sqEckP39eyvu3nmAAACRUlEQVR4nG3UQWsTQRQA4Efi IaI5zGGkkFbC5LJgAmFzyaG9LfVSA3uYk3oQNNDaY88STQ8pxmuwaXoV4kHYniqTQBNCSHUicSNi 2Y4nQYU0v8Hdmc2aZrOn2fnmzZt5+1g4DJ4hAPwM3iAYNZIAeuZjGLpuQN4+CMPIg1fxvyFw5yEH 0fMwRAAIQBgilaQuyBLI81Ka23ARgg0xrlb/wM0Q6JlToQ+WQLySYGQZ2K8xbtvZMAwsStHKcjAT J9lbIeh+pQ47zWghGK4x1hpopYtFEB3B+AuA6gIcb0w6/JcxgvUFGO0X+G/D6M7KOINGqWd4zxXA wTV4G5PzxgOAe9egFO8ZU6PAeSqrCuxDI5mRW3FeTqly+XAcqaqtJmc6xOfginxTYHCSjM1BV/Pn jS1CIudzkA4gpcnsPkRvGEZByUg1qoIjsv8fdLgdwInm5t7ygczByIMlEfUx6fkR96cjkg2gJuwZ FKbjVGx9Bh/o4/Segk1UzunppoL6rkXtLyrHplnOkda2hFoxgeiatqfuh+xcZlXBLmMYJ1KXqohm +42FdjyoP0EII2TnZd0nFmMW7m978AxRatEVXQFzl+FHOzICu0JRRcLQQd5bv6kAUYzuPvU+ue1g E2N6RwIyselu4IGtux2MqelF1DpuborNdovzs2jecsPNVZnjs3cOarbdPwNE8wyZiBab8h5Dx5WE D4573r68x2G9+PyhYExUvHauOKz9vekX8X2xaAlx2ZQNJoT4NNcl7/iPvhzUBy+5XPEPHY0ktsnr +9wAAAAASUVORK5CYII= X-URL: http://www.crunchy-home.de/ In-Reply-To: (Stefan Monnier's message of "10 Sep 2003 08:38:28 -0400") User-Agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:16268 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:16268 --=-=-= "Stefan Monnier" 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=emacsclient.c.patch --- 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); --=-=-= -- 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. --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://mail.gnu.org/mailman/listinfo/emacs-devel --=-=-=--