#undef signal
-#if !defined(HAVE_SOCKETS) && !defined(HAVE_SYSVIPC)
+#if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC)
#include <stdio.h>
main (argc, argv)
#else /* HAVE_SOCKETS or HAVE_SYSVIPC */
-#if ! defined (HAVE_SYSVIPC)
+#if defined (HAVE_SOCKETS) && ! defined (NO_SOCKETS_IN_FILE_SYSTEM)
/* BSD code is very different from SYSV IPC code */
#include <sys/types.h>
extern char *strerror ();
extern int errno;
+int
main (argc, argv)
int argc;
char **argv;
char string[BUFSIZ];
char *getenv (), *getwd ();
+ char *getcwd ();
int geteuid ();
if (argc < 2)
{
if (errno == ENOENT)
fprintf (stderr,
- "Can't find socket; have you started the server?\n");
+ "%s: can't find socket; have you started the server?\n",
+ argv[0]);
else
- perror ("stat");
+ fprintf (stderr, "%s: can't stat %s: %s\n",
+ argv[0], server.sun_path, strerror (errno));
exit (1);
}
- if (statbfr.st_uid != geteuid())
+ if (statbfr.st_uid != geteuid ())
{
- fprintf (stderr, "Illegal socket owner\n");
+ fprintf (stderr, "%s: Invalid socket owner\n", argv[0]);
exit (1);
}
}
exit (1);
}
strcpy (server.sun_path, homedir);
- strcat (server.sun_path, "/.emacs_server");
+ strcat (server.sun_path, "/.emacs-server-");
+ gethostname (system_name, sizeof (system_name));
+ strcat (server.sun_path, system_name);
#endif
if (connect (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2)
exit (1);
}
+#ifdef BSD
cwd = getwd (string);
+#else
+ cwd = getcwd (string, sizeof string);
+#endif
if (cwd == 0)
{
/* getwd puts message in STRING if it fails. */
while (str = fgets (string, BUFSIZ, out))
printf ("%s", str);
- exit (0);
+ return 0;
}
#else /* This is the SYSV IPC section */
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
+#include <sys/utsname.h>
#include <stdio.h>
char *getwd (), *getcwd (), *getenv ();
+struct utsname system_name;
main (argc, argv)
int argc;
char gwdirb[BUFSIZ];
char *cwd;
char *temp;
+ char *progname = argv[0];
if (argc < 2)
{
}
/*
- * Create a message queue using ~/.emacs_server as the path for ftok
+ * Create a message queue using ~/.emacs-server as the path for ftok
*/
if ((homedir = getenv ("HOME")) == NULL)
{
exit (1);
}
strcpy (buf, homedir);
- strcat (buf, "/.emacs_server");
+#ifndef HAVE_LONG_FILE_NAMES
+ /* If file names are short, we can't fit the host name. */
+ strcat (buf, "/.emacs-server");
+#else
+ strcat (buf, "/.emacs-server-");
+ uname (&system_name);
+ strcat (buf, system_name.nodename);
+#endif
creat (buf, 0600);
key = ftok (buf, 1); /* unlikely to be anyone else using it */
s = msgget (key, 0600 | IPC_CREAT);
}
else
{
- fprintf (stderr, cwd);
+ fprintf (stderr, "%s: %s\n", argv[0], cwd);
exit (1);
}
while (argc)
{
int need_cwd = 0;
- if (*argv[0] == '+')
+ char *modified_arg = argv[0];
+ if (*modified_arg == '+')
{
- char *p = argv[0] + 1;
+ char *p = modified_arg + 1;
while (*p >= '0' && *p <= '9') p++;
if (*p != 0)
need_cwd = 1;
}
- else if (*argv[0] != '/')
+ else if (*modified_arg != '/')
need_cwd = 1;
if (need_cwd)
used += strlen (cwd);
- used += strlen (argv[0]) + 1;
+ used += strlen (modified_arg) + 1;
while (used + 2 > size_allocated)
{
size_allocated *= 2;
if (need_cwd)
strcat (msgp->mtext, cwd);
- strcat (msgp->mtext, argv[0]);
+ strcat (msgp->mtext, modified_arg);
strcat (msgp->mtext, " ");
argv++; argc--;
}
#ifdef HPUX /* HPUX has a bug. */
if (strlen (msgp->mtext) >= 512)
{
- fprintf (stderr, "emacsclient: args too long for msgsnd\n");
+ fprintf (stderr, "%s: args too long for msgsnd\n", progname);
exit (1);
}
#endif
msgp->mtype = 1;
if (msgsnd (s, msgp, strlen (msgp->mtext)+1, 0) < 0)
{
- fprintf (stderr, "%s: ", argv[0]);
+ fprintf (stderr, "%s: ", progname);
perror ("msgsnd");
exit (1);
}