Xinqi Bao's Git
projects
/
st.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
code-style for pledge(2)
[st.git]
/
st.c
diff --git
a/st.c
b/st.c
index
543c615
..
76bb3ea
100644
(file)
--- a/
st.c
+++ b/
st.c
@@
-13,6
+13,7
@@
#include <sys/select.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <termios.h>
#include <unistd.h>
#include <wchar.h>
#include <unistd.h>
#include <wchar.h>
@@
-255,10
+256,10
@@
xwrite(int fd, const char *s, size_t len)
void *
xmalloc(size_t len)
{
void *
xmalloc(size_t len)
{
- void *p
= malloc(len)
;
+ void *p;
- if (!
p
)
- die("
Out of memory\n"
);
+ if (!
(p = malloc(len))
)
+ die("
malloc: %s\n", strerror(errno)
);
return p;
}
return p;
}
@@
-267,7
+268,7
@@
void *
xrealloc(void *p, size_t len)
{
if ((p = realloc(p, len)) == NULL)
xrealloc(void *p, size_t len)
{
if ((p = realloc(p, len)) == NULL)
- die("
Out of memory\n"
);
+ die("
realloc: %s\n", strerror(errno)
);
return p;
}
return p;
}
@@
-276,7
+277,7
@@
char *
xstrdup(char *s)
{
if ((s = strdup(s)) == NULL)
xstrdup(char *s)
{
if ((s = strdup(s)) == NULL)
- die("
Out of memory\n"
);
+ die("
strdup: %s\n", strerror(errno)
);
return s;
}
return s;
}
@@
-445,6
+446,7
@@
selstart(int col, int row, int snap)
selclear();
sel.mode = SEL_EMPTY;
sel.type = SEL_REGULAR;
selclear();
sel.mode = SEL_EMPTY;
sel.type = SEL_REGULAR;
+ sel.alt = IS_SET(MODE_ALTSCREEN);
sel.snap = snap;
sel.oe.x = sel.ob.x = col;
sel.oe.y = sel.ob.y = row;
sel.snap = snap;
sel.oe.x = sel.ob.x = col;
sel.oe.y = sel.ob.y = row;
@@
-460,7
+462,7
@@
selextend(int col, int row, int type, int done)
{
int oldey, oldex, oldsby, oldsey, oldtype;
{
int oldey, oldex, oldsby, oldsey, oldtype;
- if (
!sel.mode
)
+ if (
sel.mode == SEL_IDLE
)
return;
if (done && sel.mode == SEL_EMPTY) {
selclear();
return;
if (done && sel.mode == SEL_EMPTY) {
selclear();
@@
-473,7
+475,6
@@
selextend(int col, int row, int type, int done)
oldsey = sel.ne.y;
oldtype = sel.type;
oldsey = sel.ne.y;
oldtype = sel.type;
- sel.alt = IS_SET(MODE_ALTSCREEN);
sel.oe.x = col;
sel.oe.y = row;
selnormalize();
sel.oe.x = col;
sel.oe.y = row;
selnormalize();
@@
-686,7
+687,7
@@
execsh(char *cmd, char **args)
errno = 0;
if ((pw = getpwuid(getuid())) == NULL) {
if (errno)
errno = 0;
if ((pw = getpwuid(getuid())) == NULL) {
if (errno)
- die("getpwuid:%s\n", strerror(errno));
+ die("getpwuid:
%s\n", strerror(errno));
else
die("who are you?\n");
}
else
die("who are you?\n");
}
@@
-729,7
+730,7
@@
sigchld(int a)
pid_t p;
if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
pid_t p;
if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
- die("
W
aiting for pid %hd failed: %s\n", pid, strerror(errno));
+ die("
w
aiting for pid %hd failed: %s\n", pid, strerror(errno));
if (pid != p)
return;
if (pid != p)
return;
@@
-739,7
+740,6
@@
sigchld(int a)
exit(0);
}
exit(0);
}
-
void
stty(char **args)
{
void
stty(char **args)
{
@@
-761,7
+761,7
@@
stty(char **args)
}
*q = '\0';
if (system(cmd) != 0)
}
*q = '\0';
if (system(cmd) != 0)
- perror("Couldn't call stty");
+
perror("Couldn't call stty");
}
int
}
int
@@
-781,7
+781,8
@@
ttynew(char *line, char *cmd, char *out, char **args)
if (line) {
if ((cmdfd = open(line, O_RDWR)) < 0)
if (line) {
if ((cmdfd = open(line, O_RDWR)) < 0)
- die("open line failed: %s\n", strerror(errno));
+ die("open line '%s' failed: %s\n",
+ line, strerror(errno));
dup2(cmdfd, 0);
stty(args);
return cmdfd;
dup2(cmdfd, 0);
stty(args);
return cmdfd;
@@
-793,7
+794,7
@@
ttynew(char *line, char *cmd, char *out, char **args)
switch (pid = fork()) {
case -1:
switch (pid = fork()) {
case -1:
- die("fork failed
\n"
);
+ die("fork failed
: %s\n", strerror(errno)
);
break;
case 0:
close(iofd);
break;
case 0:
close(iofd);
@@
-805,9
+806,17
@@
ttynew(char *line, char *cmd, char *out, char **args)
die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
close(s);
close(m);
die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
close(s);
close(m);
+#ifdef __OpenBSD__
+ if (pledge("stdio getpw proc exec", NULL) == -1)
+ die("pledge\n");
+#endif
execsh(cmd, args);
break;
default:
execsh(cmd, args);
break;
default:
+#ifdef __OpenBSD__
+ if (pledge("stdio rpath tty proc", NULL) == -1)
+ die("pledge\n");
+#endif
close(s);
cmdfd = m;
signal(SIGCHLD, sigchld);
close(s);
cmdfd = m;
signal(SIGCHLD, sigchld);
@@
-826,7
+835,7
@@
ttyread(void)
/* append read bytes to unprocessed bytes */
if ((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0)
/* append read bytes to unprocessed bytes */
if ((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0)
- die("
C
ouldn't read from shell: %s\n", strerror(errno));
+ die("
c
ouldn't read from shell: %s\n", strerror(errno));
buflen += ret;
written = twrite(buf, buflen, 0);
buflen += ret;
written = twrite(buf, buflen, 0);
@@
-1693,7
+1702,6
@@
csihandle(void)
tputtab(csiescseq.arg[0]);
break;
case 'J': /* ED -- Clear screen */
tputtab(csiescseq.arg[0]);
break;
case 'J': /* ED -- Clear screen */
- selclear();
switch (csiescseq.arg[0]) {
case 0: /* below */
tclearregion(term.c.x, term.c.y, term.col-1, term.c.y);
switch (csiescseq.arg[0]) {
case 0: /* below */
tclearregion(term.c.x, term.c.y, term.col-1, term.c.y);