diff options
-rw-r--r-- | config.def.h | 2 | ||||
-rw-r--r-- | st.c | 29 | ||||
-rw-r--r-- | st.h | 9 | ||||
-rw-r--r-- | x.c | 16 |
4 files changed, 29 insertions, 27 deletions
diff --git a/config.def.h b/config.def.h index 616616a..82b1b09 100644 --- a/config.def.h +++ b/config.def.h | |||
@@ -16,7 +16,7 @@ static int borderpx = 2; | |||
16 | * 4: value of shell in /etc/passwd | 16 | * 4: value of shell in /etc/passwd |
17 | * 5: value of shell in config.h | 17 | * 5: value of shell in config.h |
18 | */ | 18 | */ |
19 | char *shell = "/bin/sh"; | 19 | static char *shell = "/bin/sh"; |
20 | char *utmp = NULL; | 20 | char *utmp = NULL; |
21 | char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400"; | 21 | char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400"; |
22 | 22 | ||
@@ -136,8 +136,7 @@ typedef struct { | |||
136 | int narg; /* nb of args */ | 136 | int narg; /* nb of args */ |
137 | } STREscape; | 137 | } STREscape; |
138 | 138 | ||
139 | 139 | static void execsh(char *, char **); | |
140 | static void execsh(char **); | ||
141 | static void stty(char **); | 140 | static void stty(char **); |
142 | static void sigchld(int); | 141 | static void sigchld(int); |
143 | static void ttywriteraw(const char *, size_t); | 142 | static void ttywriteraw(const char *, size_t); |
@@ -201,15 +200,13 @@ static char *base64dec(const char *); | |||
201 | static ssize_t xwrite(int, const char *, size_t); | 200 | static ssize_t xwrite(int, const char *, size_t); |
202 | 201 | ||
203 | /* Globals */ | 202 | /* Globals */ |
204 | int cmdfd; | ||
205 | pid_t pid; | ||
206 | int oldbutton = 3; /* button event on startup: 3 = release */ | ||
207 | |||
208 | static Term term; | 203 | static Term term; |
209 | static Selection sel; | 204 | static Selection sel; |
210 | static CSIEscape csiescseq; | 205 | static CSIEscape csiescseq; |
211 | static STREscape strescseq; | 206 | static STREscape strescseq; |
212 | static int iofd = 1; | 207 | static int iofd = 1; |
208 | static int cmdfd; | ||
209 | static pid_t pid; | ||
213 | 210 | ||
214 | static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; | 211 | static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; |
215 | static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; | 212 | static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; |
@@ -659,7 +656,7 @@ die(const char *errstr, ...) | |||
659 | } | 656 | } |
660 | 657 | ||
661 | void | 658 | void |
662 | execsh(char **args) | 659 | execsh(char *cmd, char **args) |
663 | { | 660 | { |
664 | char *sh, *prog; | 661 | char *sh, *prog; |
665 | const struct passwd *pw; | 662 | const struct passwd *pw; |
@@ -673,7 +670,7 @@ execsh(char **args) | |||
673 | } | 670 | } |
674 | 671 | ||
675 | if ((sh = getenv("SHELL")) == NULL) | 672 | if ((sh = getenv("SHELL")) == NULL) |
676 | sh = (pw->pw_shell[0]) ? pw->pw_shell : shell; | 673 | sh = (pw->pw_shell[0]) ? pw->pw_shell : cmd; |
677 | 674 | ||
678 | if (args) | 675 | if (args) |
679 | prog = args[0]; | 676 | prog = args[0]; |
@@ -745,8 +742,8 @@ stty(char **args) | |||
745 | perror("Couldn't call stty"); | 742 | perror("Couldn't call stty"); |
746 | } | 743 | } |
747 | 744 | ||
748 | void | 745 | int |
749 | ttynew(char *line, char *out, char **args) | 746 | ttynew(char *line, char *cmd, char *out, char **args) |
750 | { | 747 | { |
751 | int m, s; | 748 | int m, s; |
752 | 749 | ||
@@ -765,7 +762,7 @@ ttynew(char *line, char *out, char **args) | |||
765 | die("open line failed: %s\n", strerror(errno)); | 762 | die("open line failed: %s\n", strerror(errno)); |
766 | dup2(cmdfd, 0); | 763 | dup2(cmdfd, 0); |
767 | stty(args); | 764 | stty(args); |
768 | return; | 765 | return cmdfd; |
769 | } | 766 | } |
770 | 767 | ||
771 | /* seems to work fine on linux, openbsd and freebsd */ | 768 | /* seems to work fine on linux, openbsd and freebsd */ |
@@ -786,7 +783,7 @@ ttynew(char *line, char *out, char **args) | |||
786 | die("ioctl TIOCSCTTY failed: %s\n", strerror(errno)); | 783 | die("ioctl TIOCSCTTY failed: %s\n", strerror(errno)); |
787 | close(s); | 784 | close(s); |
788 | close(m); | 785 | close(m); |
789 | execsh(args); | 786 | execsh(cmd, args); |
790 | break; | 787 | break; |
791 | default: | 788 | default: |
792 | close(s); | 789 | close(s); |
@@ -794,6 +791,7 @@ ttynew(char *line, char *out, char **args) | |||
794 | signal(SIGCHLD, sigchld); | 791 | signal(SIGCHLD, sigchld); |
795 | break; | 792 | break; |
796 | } | 793 | } |
794 | return cmdfd; | ||
797 | } | 795 | } |
798 | 796 | ||
799 | size_t | 797 | size_t |
@@ -916,6 +914,13 @@ ttyresize(int tw, int th) | |||
916 | fprintf(stderr, "Couldn't set window size: %s\n", strerror(errno)); | 914 | fprintf(stderr, "Couldn't set window size: %s\n", strerror(errno)); |
917 | } | 915 | } |
918 | 916 | ||
917 | void | ||
918 | ttyhangup() | ||
919 | { | ||
920 | /* Send SIGHUP to shell */ | ||
921 | kill(pid, SIGHUP); | ||
922 | } | ||
923 | |||
919 | int | 924 | int |
920 | tattrset(int attr) | 925 | tattrset(int attr) |
921 | { | 926 | { |
@@ -125,7 +125,8 @@ int tattrset(int); | |||
125 | void tnew(int, int); | 125 | void tnew(int, int); |
126 | void tresize(int, int); | 126 | void tresize(int, int); |
127 | void tsetdirtattr(int); | 127 | void tsetdirtattr(int); |
128 | void ttynew(char *, char *, char **); | 128 | void ttyhangup(void); |
129 | int ttynew(char *, char *, char *, char **); | ||
129 | size_t ttyread(void); | 130 | size_t ttyread(void); |
130 | void ttyresize(int, int); | 131 | void ttyresize(int, int); |
131 | void ttywrite(const char *, size_t, int); | 132 | void ttywrite(const char *, size_t, int); |
@@ -147,13 +148,7 @@ void *xmalloc(size_t); | |||
147 | void *xrealloc(void *, size_t); | 148 | void *xrealloc(void *, size_t); |
148 | char *xstrdup(char *); | 149 | char *xstrdup(char *); |
149 | 150 | ||
150 | /* Globals */ | ||
151 | extern int cmdfd; | ||
152 | extern pid_t pid; | ||
153 | extern int oldbutton; | ||
154 | |||
155 | /* config.h globals */ | 151 | /* config.h globals */ |
156 | extern char *shell; | ||
157 | extern char *utmp; | 152 | extern char *utmp; |
158 | extern char *stty_args; | 153 | extern char *stty_args; |
159 | extern char *vtiden; | 154 | extern char *vtiden; |
@@ -227,6 +227,8 @@ static char *opt_line = NULL; | |||
227 | static char *opt_name = NULL; | 227 | static char *opt_name = NULL; |
228 | static char *opt_title = NULL; | 228 | static char *opt_title = NULL; |
229 | 229 | ||
230 | static int oldbutton = 3; /* button event on startup: 3 = release */ | ||
231 | |||
230 | void | 232 | void |
231 | clipcopy(const Arg *dummy) | 233 | clipcopy(const Arg *dummy) |
232 | { | 234 | { |
@@ -1733,8 +1735,7 @@ cmessage(XEvent *e) | |||
1733 | win.mode &= ~MODE_FOCUSED; | 1735 | win.mode &= ~MODE_FOCUSED; |
1734 | } | 1736 | } |
1735 | } else if (e->xclient.data.l[0] == xw.wmdeletewin) { | 1737 | } else if (e->xclient.data.l[0] == xw.wmdeletewin) { |
1736 | /* Send SIGHUP to shell */ | 1738 | ttyhangup(); |
1737 | kill(pid, SIGHUP); | ||
1738 | exit(0); | 1739 | exit(0); |
1739 | } | 1740 | } |
1740 | } | 1741 | } |
@@ -1755,6 +1756,7 @@ run(void) | |||
1755 | int w = win.w, h = win.h; | 1756 | int w = win.w, h = win.h; |
1756 | fd_set rfd; | 1757 | fd_set rfd; |
1757 | int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0; | 1758 | int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0; |
1759 | int ttyfd; | ||
1758 | struct timespec drawtimeout, *tv = NULL, now, last, lastblink; | 1760 | struct timespec drawtimeout, *tv = NULL, now, last, lastblink; |
1759 | long deltatime; | 1761 | long deltatime; |
1760 | 1762 | ||
@@ -1774,7 +1776,7 @@ run(void) | |||
1774 | } | 1776 | } |
1775 | } while (ev.type != MapNotify); | 1777 | } while (ev.type != MapNotify); |
1776 | 1778 | ||
1777 | ttynew(opt_line, opt_io, opt_cmd); | 1779 | ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd); |
1778 | cresize(w, h); | 1780 | cresize(w, h); |
1779 | 1781 | ||
1780 | clock_gettime(CLOCK_MONOTONIC, &last); | 1782 | clock_gettime(CLOCK_MONOTONIC, &last); |
@@ -1782,15 +1784,15 @@ run(void) | |||
1782 | 1784 | ||
1783 | for (xev = actionfps;;) { | 1785 | for (xev = actionfps;;) { |
1784 | FD_ZERO(&rfd); | 1786 | FD_ZERO(&rfd); |
1785 | FD_SET(cmdfd, &rfd); | 1787 | FD_SET(ttyfd, &rfd); |
1786 | FD_SET(xfd, &rfd); | 1788 | FD_SET(xfd, &rfd); |
1787 | 1789 | ||
1788 | if (pselect(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) { | 1790 | if (pselect(MAX(xfd, ttyfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) { |
1789 | if (errno == EINTR) | 1791 | if (errno == EINTR) |
1790 | continue; | 1792 | continue; |
1791 | die("select failed: %s\n", strerror(errno)); | 1793 | die("select failed: %s\n", strerror(errno)); |
1792 | } | 1794 | } |
1793 | if (FD_ISSET(cmdfd, &rfd)) { | 1795 | if (FD_ISSET(ttyfd, &rfd)) { |
1794 | ttyread(); | 1796 | ttyread(); |
1795 | if (blinktimeout) { | 1797 | if (blinktimeout) { |
1796 | blinkset = tattrset(ATTR_BLINK); | 1798 | blinkset = tattrset(ATTR_BLINK); |
@@ -1834,7 +1836,7 @@ run(void) | |||
1834 | 1836 | ||
1835 | if (xev && !FD_ISSET(xfd, &rfd)) | 1837 | if (xev && !FD_ISSET(xfd, &rfd)) |
1836 | xev--; | 1838 | xev--; |
1837 | if (!FD_ISSET(cmdfd, &rfd) && !FD_ISSET(xfd, &rfd)) { | 1839 | if (!FD_ISSET(ttyfd, &rfd) && !FD_ISSET(xfd, &rfd)) { |
1838 | if (blinkset) { | 1840 | if (blinkset) { |
1839 | if (TIMEDIFF(now, lastblink) \ | 1841 | if (TIMEDIFF(now, lastblink) \ |
1840 | > blinktimeout) { | 1842 | > blinktimeout) { |