diff options
| author | Richard M. Stallman | 1995-06-28 20:10:12 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-06-28 20:10:12 +0000 |
| commit | ccd318fb5b55bd8c2512259ccf631d5a945e6895 (patch) | |
| tree | bb77af759503664d820dd9578403769d5c5bd118 /lib-src | |
| parent | efcb1c1a15126b9f7206fa594d3b708b284220ef (diff) | |
| download | emacs-ccd318fb5b55bd8c2512259ccf631d5a945e6895.tar.gz emacs-ccd318fb5b55bd8c2512259ccf631d5a945e6895.zip | |
Make all error messages start with `Error: '.
(fatal_error, perror_1): New functions, use throughout.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/emacsserver.c | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/lib-src/emacsserver.c b/lib-src/emacsserver.c index 29c87e8dbd2..726ed86441f 100644 --- a/lib-src/emacsserver.c +++ b/lib-src/emacsserver.c | |||
| @@ -32,7 +32,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |||
| 32 | #undef close | 32 | #undef close |
| 33 | #undef signal | 33 | #undef signal |
| 34 | 34 | ||
| 35 | |||
| 36 | #if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC) | 35 | #if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC) |
| 37 | #include <stdio.h> | 36 | #include <stdio.h> |
| 38 | 37 | ||
| @@ -106,7 +105,7 @@ main () | |||
| 106 | 105 | ||
| 107 | if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) | 106 | if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) |
| 108 | { | 107 | { |
| 109 | perror ("socket"); | 108 | perror_1 ("socket"); |
| 110 | exit (1); | 109 | exit (1); |
| 111 | } | 110 | } |
| 112 | server.sun_family = AF_UNIX; | 111 | server.sun_family = AF_UNIX; |
| @@ -116,15 +115,13 @@ main () | |||
| 116 | 115 | ||
| 117 | if (unlink (server.sun_path) == -1 && errno != ENOENT) | 116 | if (unlink (server.sun_path) == -1 && errno != ENOENT) |
| 118 | { | 117 | { |
| 119 | perror ("unlink"); | 118 | perror_1 ("unlink"); |
| 120 | exit (1); | 119 | exit (1); |
| 121 | } | 120 | } |
| 122 | #else | 121 | #else |
| 123 | if ((homedir = getenv ("HOME")) == NULL) | 122 | if ((homedir = getenv ("HOME")) == NULL) |
| 124 | { | 123 | fatal_error ("No home directory\n"); |
| 125 | fprintf (stderr,"No home directory\n"); | 124 | |
| 126 | exit (1); | ||
| 127 | } | ||
| 128 | strcpy (server.sun_path, homedir); | 125 | strcpy (server.sun_path, homedir); |
| 129 | strcat (server.sun_path, "/.emacs-server-"); | 126 | strcat (server.sun_path, "/.emacs-server-"); |
| 130 | gethostname (system_name, sizeof (system_name)); | 127 | gethostname (system_name, sizeof (system_name)); |
| @@ -135,7 +132,7 @@ main () | |||
| 135 | 132 | ||
| 136 | if (bind (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2) < 0) | 133 | if (bind (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2) < 0) |
| 137 | { | 134 | { |
| 138 | perror ("bind"); | 135 | perror_1 ("bind"); |
| 139 | exit (1); | 136 | exit (1); |
| 140 | } | 137 | } |
| 141 | /* Only this user can send commands to this Emacs. */ | 138 | /* Only this user can send commands to this Emacs. */ |
| @@ -145,7 +142,7 @@ main () | |||
| 145 | */ | 142 | */ |
| 146 | if (listen (s, 5) < 0) | 143 | if (listen (s, 5) < 0) |
| 147 | { | 144 | { |
| 148 | perror ("listen"); | 145 | perror_1 ("listen"); |
| 149 | exit (1); | 146 | exit (1); |
| 150 | } | 147 | } |
| 151 | 148 | ||
| @@ -158,7 +155,7 @@ main () | |||
| 158 | FD_SET (0, &rmask); | 155 | FD_SET (0, &rmask); |
| 159 | FD_SET (s, &rmask); | 156 | FD_SET (s, &rmask); |
| 160 | if (select (s + 1, &rmask, 0, 0, 0) < 0) | 157 | if (select (s + 1, &rmask, 0, 0, 0) < 0) |
| 161 | perror ("select"); | 158 | perror_1 ("select"); |
| 162 | if (FD_ISSET (s, &rmask)) /* client sends list of filenames */ | 159 | if (FD_ISSET (s, &rmask)) /* client sends list of filenames */ |
| 163 | { | 160 | { |
| 164 | fromlen = sizeof (fromunix); | 161 | fromlen = sizeof (fromunix); |
| @@ -167,9 +164,9 @@ main () | |||
| 167 | if (infd < 0) | 164 | if (infd < 0) |
| 168 | { | 165 | { |
| 169 | if (errno == EMFILE || errno == ENFILE) | 166 | if (errno == EMFILE || errno == ENFILE) |
| 170 | printf ("Too many clients.\n"); | 167 | fprintf (stderr, "Error: too many clients.\n"); |
| 171 | else | 168 | else |
| 172 | perror ("accept"); | 169 | perror_1 ("accept"); |
| 173 | continue; | 170 | continue; |
| 174 | } | 171 | } |
| 175 | 172 | ||
| @@ -185,7 +182,7 @@ main () | |||
| 185 | infile = fdopen (infd, "r+"); /* open stream */ | 182 | infile = fdopen (infd, "r+"); /* open stream */ |
| 186 | if (infile == NULL) | 183 | if (infile == NULL) |
| 187 | { | 184 | { |
| 188 | printf ("Too many clients.\n"); | 185 | fprintf (stderr, "Error: too many clients.\n"); |
| 189 | write (infd, "Too many clients.\n", 18); | 186 | write (infd, "Too many clients.\n", 18); |
| 190 | close (infd); /* Prevent descriptor leak.. */ | 187 | close (infd); /* Prevent descriptor leak.. */ |
| 191 | continue; | 188 | continue; |
| @@ -193,7 +190,7 @@ main () | |||
| 193 | str = fgets (string, BUFSIZ, infile); | 190 | str = fgets (string, BUFSIZ, infile); |
| 194 | if (str == NULL) | 191 | if (str == NULL) |
| 195 | { | 192 | { |
| 196 | perror ("fgets"); | 193 | perror_1 ("fgets"); |
| 197 | close (infd); /* Prevent descriptor leak.. */ | 194 | close (infd); /* Prevent descriptor leak.. */ |
| 198 | continue; | 195 | continue; |
| 199 | } | 196 | } |
| @@ -218,10 +215,7 @@ main () | |||
| 218 | clearerr (stdin); | 215 | clearerr (stdin); |
| 219 | scanf ("%s %d%*c", code, &infd); | 216 | scanf ("%s %d%*c", code, &infd); |
| 220 | if (ferror (stdin) || feof (stdin)) | 217 | if (ferror (stdin) || feof (stdin)) |
| 221 | { | 218 | fatal_error ("server: error reading from standard input\n"); |
| 222 | fprintf (stderr, "server: error reading from standard input\n"); | ||
| 223 | exit (1); | ||
| 224 | } | ||
| 225 | 219 | ||
| 226 | /* Transfer text from Emacs to the client, up to a newline. */ | 220 | /* Transfer text from Emacs to the client, up to a newline. */ |
| 227 | infile = openfiles[infd]; | 221 | infile = openfiles[infd]; |
| @@ -293,10 +287,8 @@ main () | |||
| 293 | * Create a message queue using ~/.emacs-server as the path for ftok | 287 | * Create a message queue using ~/.emacs-server as the path for ftok |
| 294 | */ | 288 | */ |
| 295 | if ((homedir = getenv ("HOME")) == NULL) | 289 | if ((homedir = getenv ("HOME")) == NULL) |
| 296 | { | 290 | fatal_error ("No home directory\n"); |
| 297 | fprintf (stderr,"No home directory\n"); | 291 | |
| 298 | exit (1); | ||
| 299 | } | ||
| 300 | strcpy (string, homedir); | 292 | strcpy (string, homedir); |
| 301 | #ifndef HAVE_LONG_FILE_NAMES | 293 | #ifndef HAVE_LONG_FILE_NAMES |
| 302 | /* If file names are short, we can't fit the host name. */ | 294 | /* If file names are short, we can't fit the host name. */ |
| @@ -311,7 +303,7 @@ main () | |||
| 311 | s = msgget (key, 0600 | IPC_CREAT); | 303 | s = msgget (key, 0600 | IPC_CREAT); |
| 312 | if (s == -1) | 304 | if (s == -1) |
| 313 | { | 305 | { |
| 314 | perror ("msgget"); | 306 | perror_1 ("msgget"); |
| 315 | exit (1); | 307 | exit (1); |
| 316 | } | 308 | } |
| 317 | 309 | ||
| @@ -372,7 +364,7 @@ main () | |||
| 372 | if (errno == EINTR) | 364 | if (errno == EINTR) |
| 373 | continue; | 365 | continue; |
| 374 | #endif | 366 | #endif |
| 375 | perror ("msgrcv"); | 367 | perror_1 ("msgrcv"); |
| 376 | exit (1); | 368 | exit (1); |
| 377 | } | 369 | } |
| 378 | else | 370 | else |
| @@ -409,3 +401,25 @@ main () | |||
| 409 | #endif /* HAVE_SYSVIPC */ | 401 | #endif /* HAVE_SYSVIPC */ |
| 410 | 402 | ||
| 411 | #endif /* HAVE_SOCKETS or HAVE_SYSVIPC */ | 403 | #endif /* HAVE_SOCKETS or HAVE_SYSVIPC */ |
| 404 | |||
| 405 | /* This is like perror but puts `Error: ' at the beginning. */ | ||
| 406 | |||
| 407 | perror_1 (string) | ||
| 408 | char *string; | ||
| 409 | { | ||
| 410 | char *copy = (char *) malloc (strlen (string) + 8); | ||
| 411 | if (copy == 0) | ||
| 412 | fatal_error ("Virtual memory exhausted"); | ||
| 413 | |||
| 414 | strcpy (copy, "Error: "); | ||
| 415 | strcat (copy, string); | ||
| 416 | perror (copy); | ||
| 417 | } | ||
| 418 | |||
| 419 | fatal_error (string) | ||
| 420 | char *string; | ||
| 421 | { | ||
| 422 | fprintf (stderr, "%s", "Error: "); | ||
| 423 | fprintf (stderr, string); | ||
| 424 | exit (1); | ||
| 425 | } | ||