comparison lib-src/emacsclient.c @ 10124:baab57e76991

[HAVE_SYSVIPC]: Include sys/utsname.h. (main): If socket/mqueue name is in home dir, add in the host name. Rename .emacs_server to .emacs-server-.... [!HAVE_SYSVIPC] (main): Fix error message diction.
author Richard M. Stallman <rms@gnu.org>
date Wed, 07 Dec 1994 07:39:23 +0000
parents dd3b83e4ceb0
children 3345f6426f49
comparison
equal deleted inserted replaced
10123:bb3d25f73eaf 10124:baab57e76991
25 #undef open 25 #undef open
26 #undef close 26 #undef close
27 #undef signal 27 #undef signal
28 28
29 29
30 #if !defined(HAVE_SOCKETS) && !defined(HAVE_SYSVIPC) 30 #if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC)
31 #include <stdio.h> 31 #include <stdio.h>
32 32
33 main (argc, argv) 33 main (argc, argv)
34 int argc; 34 int argc;
35 char **argv; 35 char **argv;
101 "Can't find socket; have you started the server?\n"); 101 "Can't find socket; have you started the server?\n");
102 else 102 else
103 perror ("stat"); 103 perror ("stat");
104 exit (1); 104 exit (1);
105 } 105 }
106 if (statbfr.st_uid != geteuid()) 106 if (statbfr.st_uid != geteuid ())
107 { 107 {
108 fprintf (stderr, "Illegal socket owner\n"); 108 fprintf (stderr, "Invalid socket owner\n");
109 exit (1); 109 exit (1);
110 } 110 }
111 } 111 }
112 #else 112 #else
113 if ((homedir = getenv ("HOME")) == NULL) 113 if ((homedir = getenv ("HOME")) == NULL)
114 { 114 {
115 fprintf (stderr, "%s: No home directory\n", argv[0]); 115 fprintf (stderr, "%s: No home directory\n", argv[0]);
116 exit (1); 116 exit (1);
117 } 117 }
118 strcpy (server.sun_path, homedir); 118 strcpy (server.sun_path, homedir);
119 strcat (server.sun_path, "/.emacs_server"); 119 strcat (server.sun_path, "/.emacs-server-");
120 gethostname (system_name, sizeof (system_name));
121 strcat (server.sun_path, system_name);
120 #endif 122 #endif
121 123
122 if (connect (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2) 124 if (connect (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2)
123 < 0) 125 < 0)
124 { 126 {
174 #else /* This is the SYSV IPC section */ 176 #else /* This is the SYSV IPC section */
175 177
176 #include <sys/types.h> 178 #include <sys/types.h>
177 #include <sys/ipc.h> 179 #include <sys/ipc.h>
178 #include <sys/msg.h> 180 #include <sys/msg.h>
181 #include <sys/utsname.h>
179 #include <stdio.h> 182 #include <stdio.h>
180 183
181 char *getwd (), *getcwd (), *getenv (); 184 char *getwd (), *getcwd (), *getenv ();
185 struct utsname system_name;
182 186
183 main (argc, argv) 187 main (argc, argv)
184 int argc; 188 int argc;
185 char **argv; 189 char **argv;
186 { 190 {
204 fprintf (stderr, "Usage: %s [+linenumber] filename\n", argv[0]); 208 fprintf (stderr, "Usage: %s [+linenumber] filename\n", argv[0]);
205 exit (1); 209 exit (1);
206 } 210 }
207 211
208 /* 212 /*
209 * Create a message queue using ~/.emacs_server as the path for ftok 213 * Create a message queue using ~/.emacs-server as the path for ftok
210 */ 214 */
211 if ((homedir = getenv ("HOME")) == NULL) 215 if ((homedir = getenv ("HOME")) == NULL)
212 { 216 {
213 fprintf (stderr, "%s: No home directory\n", argv[0]); 217 fprintf (stderr, "%s: No home directory\n", argv[0]);
214 exit (1); 218 exit (1);
215 } 219 }
216 strcpy (buf, homedir); 220 strcpy (buf, homedir);
217 strcat (buf, "/.emacs_server"); 221 #ifndef HAVE_LONG_FILE_NAMES
222 /* If file names are short, we can't fit the host name. */
223 strcat (buf, "/.emacs-server");
224 #else
225 strcat (buf, "/.emacs-server-");
226 uname (&system_name);
227 strcat (buf, system_name.nodename);
228 #endif
218 creat (buf, 0600); 229 creat (buf, 0600);
219 key = ftok (buf, 1); /* unlikely to be anyone else using it */ 230 key = ftok (buf, 1); /* unlikely to be anyone else using it */
220 s = msgget (key, 0600 | IPC_CREAT); 231 s = msgget (key, 0600 | IPC_CREAT);
221 if (s == -1) 232 if (s == -1)
222 { 233 {