diff mbox

Fix some portability issues

Message ID CAEtFKsu5bR9syCNcueiSnE+fh=ngQd6tp211e4MdVetjKL6=Ew@mail.gmail.com (mailing list archive)
State Changes Requested
Delegated to: Herbert Xu
Headers show

Commit Message

Devin Hussey May 24, 2018, 6:20 p.m. UTC
This patch makes Dash more patch-generic. It replaces /tmp with
$TMPDIR, uses SYSCONFDIR instead of /etc for the profile path, and
includes <string.h> for fewer implicit declaration warnings.

This allows dash to be compiled and run without issues on the very
unorthodox Android Termux environment, which has no /etc or writable
/tmp.

--Devin Hussey

From af7daf9f6268c0879d227e8d06cfbc6b46b6fefd Mon Sep 17 00:00:00 2001
From: Devin Hussey <husseydevin@gmail.com>
Date: Wed, 23 May 2018 12:05:53 -0400
Subject: [PATCH] Fix some portability issues.

Signed-off-by: Devin Hussey <husseydevin@gmail.com>
---
 src/Makefile.am |  2 +-
 src/main.c      |  2 +-
 src/mktokens    | 16 ++++++++--------
 src/system.h    |  1 +
 4 files changed, 11 insertions(+), 10 deletions(-)

Comments

Herbert Xu May 26, 2018, 8:09 a.m. UTC | #1
Devin Hussey <husseydevin@gmail.com> wrote:
>
> -nl=`wc -l /tmp/ka$$`
> +nl=`wc -l $TMPDIR/ka$$`

Please quote TMPDIR since it's from the environment and can contain
arbitrary values.

> diff --git a/src/system.h b/src/system.h
> index a8d09b3..6b2e06a 100644
> --- a/src/system.h
> +++ b/src/system.h
> @@ -29,6 +29,7 @@
> #include <limits.h>
> #include <signal.h>
> #include <sys/types.h>
> +#include <string.h>
> 
> #ifndef SSIZE_MAX
> #define SSIZE_MAX ((ssize_t)((size_t)-1 >> 1))

Hmm, what in system.h uses string functions? Headers should be
added to the file that actually uses them.

Thanks,
diff mbox

Patch

diff --git a/src/Makefile.am b/src/Makefile.am
index 46399c7..bbeed15 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,7 +6,7 @@  COMMON_CPPFLAGS = \
  -DBSD=1 -DSHELL

 AM_CFLAGS = $(COMMON_CFLAGS)
-AM_CPPFLAGS = $(COMMON_CPPFLAGS)
+AM_CPPFLAGS = $(COMMON_CPPFLAGS) -DSYSCONFDIR=$(sysconfdir)
 AM_CFLAGS_FOR_BUILD = -g -O2 $(COMMON_CFLAGS)
 AM_CPPFLAGS_FOR_BUILD = $(COMMON_CPPFLAGS)

diff --git a/src/main.c b/src/main.c
index e8e4256..e83d8e0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -148,7 +148,7 @@  main(int argc, char **argv)
  login = procargs(argc, argv);
  if (login) {
  state = 1;
- read_profile("/etc/profile");
+ read_profile(SYSCONFDIR "/profile");
 state1:
  state = 2;
  read_profile("$HOME/.profile");
diff --git a/src/mktokens b/src/mktokens
index cd52241..7eef8cd 100644
--- a/src/mktokens
+++ b/src/mktokens
@@ -37,7 +37,8 @@ 
 # token marks the end of a list.  The third column is the name to print in
 # error messages.

-cat > /tmp/ka$$ <<\!
+TMPDIR=${TMPDIR:-/tmp}
+cat > $TMPDIR/ka$$ <<\!
 TEOF 1 end of file
 TNL 0 newline
 TSEMI 0 ";"
@@ -68,28 +69,27 @@  TWHILE 0 "while"
 TBEGIN 0 "{"
 TEND 1 "}"
 !
-nl=`wc -l /tmp/ka$$`
+nl=`wc -l $TMPDIR/ka$$`
 exec > token.h
-awk '{print "#define " $1 " " NR-1}' /tmp/ka$$
-
+awk '{print "#define " $1 " " NR-1}' $TMPDIR/ka$$
 exec > token_vars.h

 echo '
 /* Array indicating which tokens mark the end of a list */
 static const char tokendlist[] = {'
-awk '{print "\t" $2 ","}' /tmp/ka$$
+awk '{print "\t" $2 ","}' $TMPDIR/ka$$
 echo '};

 static const char *const tokname[] = {'
 sed -e 's/"/\\"/g' \
     -e 's/[^ ]*[ ][ ]*[^ ]*[ ][ ]*\(.*\)/ "\1",/' \
-    /tmp/ka$$
+    $TMPDIR/ka$$
 echo '};
 '
-sed 's/"//g' /tmp/ka$$ | awk '
+sed 's/"//g' $TMPDIR/ka$$ | awk '
 /TNOT/{print "#define KWDOFFSET " NR-1; print "";
       print "static const char *const parsekwd[] = {"}
 /TNOT/,/neverfound/{if (last) print " \"" last "\","; last = $3}
 END{print " \"" last "\"\n};"}'

-rm /tmp/ka$$
+rm $TMPDIR/ka$$
diff --git a/src/system.h b/src/system.h
index a8d09b3..6b2e06a 100644
--- a/src/system.h
+++ b/src/system.h
@@ -29,6 +29,7 @@ 
 #include <limits.h>
 #include <signal.h>
 #include <sys/types.h>
+#include <string.h>

 #ifndef SSIZE_MAX
 #define SSIZE_MAX ((ssize_t)((size_t)-1 >> 1))