aboutsummarylogtreecommitdiffstats
path: root/st.c
diff options
context:
space:
mode:
authorDevin J. Pohly2018-02-24 16:16:12 -0600
committerDevin J. Pohly2018-02-25 21:56:26 -0600
commitda33531ed1b5a7a28f192b0b9d8f58aea3187b64 (patch)
tree1f004bb4b9e24e21652ec45b36d636386092d169 /st.c
parent84ceac99b68d7b5408325832465a5d33bb40b677 (diff)
downloadaur-da33531ed1b5a7a28f192b0b9d8f58aea3187b64.tar.gz
Limit usage of extern to config.h globals
Prefer passing arguments to declaring external global variables. The only remaining usage of extern is for config.h variables which are needed in st.c instead of x.c (where it is now included). Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
Diffstat (limited to 'st.c')
-rw-r--r--st.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/st.c b/st.c
index da832ed693c5..ce32cc0d3fe6 100644
--- a/st.c
+++ b/st.c
@@ -136,8 +136,7 @@ typedef struct {
int narg; /* nb of args */
} STREscape;
-
-static void execsh(char **);
+static void execsh(char *, char **);
static void stty(char **);
static void sigchld(int);
static void ttywriteraw(const char *, size_t);
@@ -201,15 +200,13 @@ static char *base64dec(const char *);
static ssize_t xwrite(int, const char *, size_t);
/* Globals */
-int cmdfd;
-pid_t pid;
-int oldbutton = 3; /* button event on startup: 3 = release */
-
static Term term;
static Selection sel;
static CSIEscape csiescseq;
static STREscape strescseq;
static int iofd = 1;
+static int cmdfd;
+static pid_t pid;
static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
@@ -659,7 +656,7 @@ die(const char *errstr, ...)
}
void
-execsh(char **args)
+execsh(char *cmd, char **args)
{
char *sh, *prog;
const struct passwd *pw;
@@ -673,7 +670,7 @@ execsh(char **args)
}
if ((sh = getenv("SHELL")) == NULL)
- sh = (pw->pw_shell[0]) ? pw->pw_shell : shell;
+ sh = (pw->pw_shell[0]) ? pw->pw_shell : cmd;
if (args)
prog = args[0];
@@ -745,8 +742,8 @@ stty(char **args)
perror("Couldn't call stty");
}
-void
-ttynew(char *line, char *out, char **args)
+int
+ttynew(char *line, char *cmd, char *out, char **args)
{
int m, s;
@@ -765,7 +762,7 @@ ttynew(char *line, char *out, char **args)
die("open line failed: %s\n", strerror(errno));
dup2(cmdfd, 0);
stty(args);
- return;
+ return cmdfd;
}
/* seems to work fine on linux, openbsd and freebsd */
@@ -786,7 +783,7 @@ ttynew(char *line, char *out, char **args)
die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
close(s);
close(m);
- execsh(args);
+ execsh(cmd, args);
break;
default:
close(s);
@@ -794,6 +791,7 @@ ttynew(char *line, char *out, char **args)
signal(SIGCHLD, sigchld);
break;
}
+ return cmdfd;
}
size_t
@@ -916,6 +914,13 @@ ttyresize(int tw, int th)
fprintf(stderr, "Couldn't set window size: %s\n", strerror(errno));
}
+void
+ttyhangup()
+{
+ /* Send SIGHUP to shell */
+ kill(pid, SIGHUP);
+}
+
int
tattrset(int attr)
{