diff options
| author | Richard M. Stallman | 1994-03-05 21:42:57 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-03-05 21:42:57 +0000 |
| commit | 1518a9eb45c4edd7e7c445f358a243222dcc18e8 (patch) | |
| tree | 049f0420a653c75de4e77d220689a26cdd2da08e /lib-src | |
| parent | 0bc439a07665479d6e918474839c562c4e92f9e5 (diff) | |
| download | emacs-1518a9eb45c4edd7e7c445f358a243222dcc18e8.tar.gz emacs-1518a9eb45c4edd7e7c445f358a243222dcc18e8.zip | |
(main) [HAVE_SYSVIPC]: Make msgp->mtext longer if necessary.
On HPUX, error if it's more than 512 chars.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/emacsclient.c | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 85d0bdebeb5..cacfaa8658f 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c | |||
| @@ -177,20 +177,25 @@ main (argc, argv) | |||
| 177 | #include <sys/msg.h> | 177 | #include <sys/msg.h> |
| 178 | #include <stdio.h> | 178 | #include <stdio.h> |
| 179 | 179 | ||
| 180 | char *getwd (), *getcwd (), *getenv (); | ||
| 181 | |||
| 180 | main (argc, argv) | 182 | main (argc, argv) |
| 181 | int argc; | 183 | int argc; |
| 182 | char **argv; | 184 | char **argv; |
| 183 | { | 185 | { |
| 184 | int s; | 186 | int s; |
| 185 | key_t key; | 187 | key_t key; |
| 186 | struct msgbuf * msgp = | 188 | /* Size of text allocated in MSGP. */ |
| 187 | (struct msgbuf *) malloc (sizeof *msgp + BUFSIZ); | 189 | int size_allocated = BUFSIZ; |
| 190 | /* Amount of text used in MSGP. */ | ||
| 191 | int used; | ||
| 192 | struct msgbuf *msgp | ||
| 193 | = (struct msgbuf *) malloc (sizeof (struct msgbuf) + size_allocated); | ||
| 188 | struct msqid_ds * msg_st; | 194 | struct msqid_ds * msg_st; |
| 189 | char *homedir, buf[BUFSIZ]; | 195 | char *homedir, buf[BUFSIZ]; |
| 190 | char gwdirb[BUFSIZ]; | 196 | char gwdirb[BUFSIZ]; |
| 191 | char *cwd; | 197 | char *cwd; |
| 192 | char *temp; | 198 | char *temp; |
| 193 | char *getwd (), *getcwd (), *getenv (); | ||
| 194 | 199 | ||
| 195 | if (argc < 2) | 200 | if (argc < 2) |
| 196 | { | 201 | { |
| @@ -241,17 +246,33 @@ main (argc, argv) | |||
| 241 | } | 246 | } |
| 242 | 247 | ||
| 243 | msgp->mtext[0] = 0; | 248 | msgp->mtext[0] = 0; |
| 249 | used = 0; | ||
| 244 | argc--; argv++; | 250 | argc--; argv++; |
| 245 | while (argc) | 251 | while (argc) |
| 246 | { | 252 | { |
| 253 | int need_cwd = 0; | ||
| 247 | if (*argv[0] == '+') | 254 | if (*argv[0] == '+') |
| 248 | { | 255 | { |
| 249 | char *p = argv[0] + 1; | 256 | char *p = argv[0] + 1; |
| 250 | while (*p >= '0' && *p <= '9') p++; | 257 | while (*p >= '0' && *p <= '9') p++; |
| 251 | if (*p != 0) | 258 | if (*p != 0) |
| 252 | strcat (msgp->mtext, cwd); | 259 | need_cwd = 1; |
| 253 | } | 260 | } |
| 254 | else if (*argv[0] != '/') | 261 | else if (*argv[0] != '/') |
| 262 | need_cwd = 1; | ||
| 263 | |||
| 264 | if (need_cwd) | ||
| 265 | used += strlen (cwd); | ||
| 266 | used += strlen (argv[0]) + 1; | ||
| 267 | while (used + 2 > size_allocated) | ||
| 268 | { | ||
| 269 | size_allocated *= 2; | ||
| 270 | msgp = (struct msgbuf *) realloc (msgp, | ||
| 271 | (sizeof (struct msgbuf) | ||
| 272 | + size_allocated)); | ||
| 273 | } | ||
| 274 | |||
| 275 | if (need_cwd) | ||
| 255 | strcat (msgp->mtext, cwd); | 276 | strcat (msgp->mtext, cwd); |
| 256 | 277 | ||
| 257 | strcat (msgp->mtext, argv[0]); | 278 | strcat (msgp->mtext, argv[0]); |
| @@ -259,6 +280,13 @@ main (argc, argv) | |||
| 259 | argv++; argc--; | 280 | argv++; argc--; |
| 260 | } | 281 | } |
| 261 | strcat (msgp->mtext, "\n"); | 282 | strcat (msgp->mtext, "\n"); |
| 283 | #ifdef HPUX /* HPUX has a bug. */ | ||
| 284 | if (strlen (msgp->mtext) >= 512) | ||
| 285 | { | ||
| 286 | fprintf (stderr, "emacsclient: args too long for msgsnd\n"); | ||
| 287 | exit (1); | ||
| 288 | } | ||
| 289 | #endif | ||
| 262 | msgp->mtype = 1; | 290 | msgp->mtype = 1; |
| 263 | if (msgsnd (s, msgp, strlen (msgp->mtext)+1, 0) < 0) | 291 | if (msgsnd (s, msgp, strlen (msgp->mtext)+1, 0) < 0) |
| 264 | { | 292 | { |