comparison lib-src/emacsclient.c @ 42176:1f5dbeefa536

Include "config.h", not <../src/config.h>. (main): Parenthesize assignment when used as truth value to prevent gcc warnings.
author Pavel Janík <Pavel@Janik.cz>
date Wed, 19 Dec 2001 07:21:00 +0000
parents 42510bd54993
children 83c1951257f1
comparison
equal deleted inserted replaced
42175:80ed9c7f014f 42176:1f5dbeefa536
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */ 20 Boston, MA 02111-1307, USA. */
21 21
22 22
23 #define NO_SHORTNAMES 23 #define NO_SHORTNAMES
24 #include <../src/config.h> 24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
25 #undef signal 29 #undef signal
26 30
27 #include <ctype.h> 31 #include <ctype.h>
28 #include <stdio.h> 32 #include <stdio.h>
29 #include <getopt.h> 33 #include <getopt.h>
30 #ifdef HAVE_UNISTD_H 34 #ifdef HAVE_UNISTD_H
31 #include <unistd.h> 35 #include <unistd.h>
32 #endif 36 #endif
82 86
83 if (opt == EOF) 87 if (opt == EOF)
84 break; 88 break;
85 89
86 alternate_editor = getenv ("ALTERNATE_EDITOR"); 90 alternate_editor = getenv ("ALTERNATE_EDITOR");
87 91
88 switch (opt) 92 switch (opt)
89 { 93 {
90 case 0: 94 case 0:
91 /* If getopt returns 0, then it has already processed a 95 /* If getopt returns 0, then it has already processed a
92 long-named option. We should do nothing. */ 96 long-named option. We should do nothing. */
93 break; 97 break;
94 98
95 case 'a': 99 case 'a':
96 alternate_editor = optarg; 100 alternate_editor = optarg;
97 break; 101 break;
98 102
99 case 'n': 103 case 'n':
100 nowait = 1; 104 nowait = 1;
101 break; 105 break;
102 106
103 case 'V': 107 case 'V':
155 *q++ = *p++; 159 *q++ = *p++;
156 } 160 }
157 } 161 }
158 *q++ = 0; 162 *q++ = 0;
159 163
160
161 return copy; 164 return copy;
162 } 165 }
163 166
164 /* Like malloc but get fatal error if memory is exhausted. */ 167 /* Like malloc but get fatal error if memory is exhausted. */
165 168
196 exit (1); 199 exit (1);
197 } 200 }
198 } 201 }
199 202
200 203
201
202 204
203 #if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC) 205 #if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC)
204 206
205 int 207 int
206 main (argc, argv) 208 main (argc, argv)
270 decode_options (argc, argv); 272 decode_options (argc, argv);
271 273
272 if (argc - optind < 1) 274 if (argc - optind < 1)
273 print_help_and_exit (); 275 print_help_and_exit ();
274 276
275 /* 277 /*
276 * Open up an AF_UNIX socket in this person's home directory 278 * Open up an AF_UNIX socket in this person's home directory
277 */ 279 */
278 280
279 if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) 281 if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
280 { 282 {
281 fprintf (stderr, "%s: ", argv[0]); 283 fprintf (stderr, "%s: ", argv[0]);
282 perror ("socket"); 284 perror ("socket");
283 fail (argc, argv); 285 fail (argc, argv);
284 } 286 }
285 287
286 server.sun_family = AF_UNIX; 288 server.sun_family = AF_UNIX;
287 289
288 { 290 {
289 system_name_length = 32; 291 system_name_length = 32;
290 292
315 { 317 {
316 /* Failing that, see if LOGNAME or USER exist and differ from 318 /* Failing that, see if LOGNAME or USER exist and differ from
317 our euid. If so, look for a socket based on the UID 319 our euid. If so, look for a socket based on the UID
318 associated with the name. This is reminiscent of the logic 320 associated with the name. This is reminiscent of the logic
319 that init_editfns uses to set the global Vuser_full_name. */ 321 that init_editfns uses to set the global Vuser_full_name. */
320 322
321 char *user_name = (char *) getenv ("LOGNAME"); 323 char *user_name = (char *) getenv ("LOGNAME");
322 if (!user_name) 324 if (!user_name)
323 user_name = (char *) getenv ("USER"); 325 user_name = (char *) getenv ("USER");
324 326
325 if (user_name) 327 if (user_name)
326 { 328 {
327 struct passwd *pw = getpwnam (user_name); 329 struct passwd *pw = getpwnam (user_name);
328 if (pw && (pw->pw_uid != geteuid ())) 330 if (pw && (pw->pw_uid != geteuid ()))
329 { 331 {
332 (int) pw->pw_uid, system_name); 334 (int) pw->pw_uid, system_name);
333 sock_status = socket_status (server.sun_path); 335 sock_status = socket_status (server.sun_path);
334 } 336 }
335 } 337 }
336 } 338 }
337 339
338 switch (sock_status) 340 switch (sock_status)
339 { 341 {
340 case 1: 342 case 1:
341 /* There's a socket, but it isn't owned by us. This is OK if 343 /* There's a socket, but it isn't owned by us. This is OK if
342 we are root. */ 344 we are root. */
344 { 346 {
345 fprintf (stderr, "%s: Invalid socket owner\n", argv[0]); 347 fprintf (stderr, "%s: Invalid socket owner\n", argv[0]);
346 fail (argc, argv); 348 fail (argc, argv);
347 } 349 }
348 break; 350 break;
349 351
350 case 2: 352 case 2:
351 /* `stat' failed */ 353 /* `stat' failed */
352 if (errno == ENOENT) 354 if (errno == ENOENT)
353 fprintf (stderr, 355 fprintf (stderr,
354 "%s: can't find socket; have you started the server?\n", 356 "%s: can't find socket; have you started the server?\n",
446 448
447 /* Now, wait for an answer and print any messages. On some systems, 449 /* Now, wait for an answer and print any messages. On some systems,
448 the first line we read will actually be the output we just sent. 450 the first line we read will actually be the output we just sent.
449 We can't predict whether that will happen, so if it does, we 451 We can't predict whether that will happen, so if it does, we
450 detect it by recognizing `Client: ' at the beginning. */ 452 detect it by recognizing `Client: ' at the beginning. */
451 453
452 while (str = fgets (string, BUFSIZ, in)) 454 while ((str = fgets (string, BUFSIZ, in)))
453 printf ("%s", str); 455 printf ("%s", str);
454 456
455 return 0; 457 return 0;
456 } 458 }
457 459