Make sure to normalize path names for B. - sam - An updated version of the sam text editor.
(HTM) git clone git://vernunftzentrum.de/sam.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit 0677cef74fe4031e029131682a14838337d046c1
(DIR) parent 993a6b58e56e8a35a2834220ff552325814180ba
(HTM) Author: Rob King <jking@deadpixi.com>
Date: Tue, 10 Jan 2017 10:03:00 -0600
Make sure to normalize path names for B.
Diffstat:
sam/sam.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
---
(DIR) diff --git a/sam/sam.c b/sam/sam.c
@@ -1,9 +1,14 @@
/* Copyright (c) 1998 Lucent Technologies - All rights reserved. */
+/* Copyright (c) 2016 Rob King */
+
+#define _XOPEN_SOURCE 500
#include "sam.h"
#include <libgen.h>
+#include <limits.h>
#include <signal.h>
#include <stdbool.h>
+#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -111,8 +116,18 @@ bmain(int argc, char *argv[])
argc -= optind;
argv += optind;
- if (getbsocketname(machine) == NULL)
- return fputs("could not determine controlling socket name\n", stderr), EXIT_FAILURE;
+ if (getbsocketname(machine) == NULL){
+ argc += optind;
+ argv -= optind;
+
+ char *nargv[argc + 1];
+ fputs("could not determine controlling socket name, starting new instance\n", stderr);
+ nargv[0] = "sam";
+ for (int i = 1; i < argc; i++)
+ nargv[i] = argv[i];
+ nargv[argc] = NULL;
+ execvp("sam", nargv);
+ }
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
@@ -122,8 +137,13 @@ bmain(int argc, char *argv[])
strncat(cmd, "B ", B_CMD_MAX);
for (int i = 0; i < argc; i++){
- strncat(cmd, " ", B_CMD_MAX);
- strncat(cmd, argv[i], B_CMD_MAX);
+ char path[FILENAME_MAX + 1];
+ if (realpath(argv[i], path) == NULL)
+ perror(argv[i]);
+ else{
+ strncat(cmd, " ", B_CMD_MAX);
+ strncat(cmd, path, B_CMD_MAX);
+ }
}
strncat(cmd, "\n", B_CMD_MAX);