From: mestre Date: Sat, 23 Oct 2021 11:22:48 +0000 (+0000) Subject: if both stdout and stderr are redirected to a non-tty, pledge(2) will kill X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=bda84ce940729ea62ecb251ada05533d1b1163fc;p=openbsd if both stdout and stderr are redirected to a non-tty, pledge(2) will kill ncurses applications, e.g.: /usr/games/worms 2>&1 | cat solve this by only calling pledge(2) after initscr(3) is set and done, or whatever function that calls it. since pledge(2) is called later now the promises might be reduced, but this a diff for another day. found by naddy@ almost a year ago, discussed with him deraadt@ and tb@ ok tb@ --- diff --git a/games/atc/main.c b/games/atc/main.c index 8c38160b1cc..b83cf5c7206 100644 --- a/games/atc/main.c +++ b/games/atc/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.30 2016/09/11 14:21:17 tb Exp $ */ +/* $OpenBSD: main.c,v 1.31 2021/10/23 11:22:48 mestre Exp $ */ /* $NetBSD: main.c,v 1.4 1995/04/27 21:22:25 mycroft Exp $ */ /*- @@ -64,8 +64,6 @@ main(int argc, char *argv[]) struct sigaction sa; struct itimerval itv; - if (pledge("stdio rpath wpath cpath flock tty", NULL) == -1) - err(1, "pledge"); open_score_file(); start_time = time(0); @@ -141,6 +139,9 @@ main(int argc, char *argv[]) setup_screen(sp); + if (pledge("stdio rpath wpath cpath flock tty", NULL) == -1) + err(1, "pledge"); + addplane(); signal(SIGINT, quit); diff --git a/games/backgammon/backgammon/main.c b/games/backgammon/backgammon/main.c index ebcbb725192..c8f9208da0b 100644 --- a/games/backgammon/backgammon/main.c +++ b/games/backgammon/backgammon/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.24 2017/07/11 14:32:16 fcambus Exp $ */ +/* $OpenBSD: main.c,v 1.25 2021/10/23 11:22:48 mestre Exp $ */ /* * Copyright (c) 1980, 1993 @@ -85,9 +85,6 @@ main (int argc, char **argv) int i,l; /* non-descript indices */ char c; /* non-descript character storage */ - if (pledge("stdio rpath wpath cpath tty exec", NULL) == -1) - err(1, "pledge"); - signal(SIGINT, getout); /* trap interrupts */ /* use whole screen for text */ @@ -107,6 +104,9 @@ main (int argc, char **argv) if (cturn == 0) rflag = 0; } else { + if (pledge("stdio rpath wpath cpath tty exec", NULL) == -1) + err(1, "pledge"); + rscore = wscore = 0; /* zero score */ if (aflag) { /* print rules */ diff --git a/games/battlestar/battlestar.c b/games/battlestar/battlestar.c index 02ab795bb9e..fa7755ca8ec 100644 --- a/games/battlestar/battlestar.c +++ b/games/battlestar/battlestar.c @@ -1,4 +1,4 @@ -/* $OpenBSD: battlestar.c,v 1.22 2018/02/07 20:22:23 tedu Exp $ */ +/* $OpenBSD: battlestar.c,v 1.23 2021/10/23 11:22:48 mestre Exp $ */ /* $NetBSD: battlestar.c,v 1.3 1995/03/21 15:06:47 cgd Exp $ */ /* @@ -50,9 +50,6 @@ main(int argc, char *argv[]) char mainbuf[LINELENGTH]; char *next; - if (pledge("stdio rpath wpath cpath tty", NULL) == -1) - err(1, "pledge"); - open_score_file(); if (argc < 2) @@ -63,6 +60,10 @@ main(int argc, char *argv[]) initialize(argv[1]); newlocation(); + + if (pledge("stdio rpath wpath cpath tty", NULL) == -1) + err(1, "pledge"); + for (;;) { stop_cypher = 0; next = getcom(mainbuf, sizeof mainbuf, ">-: ", diff --git a/games/boggle/boggle/bog.c b/games/boggle/boggle/bog.c index 4955bc8c9ac..c0e19454a27 100644 --- a/games/boggle/boggle/bog.c +++ b/games/boggle/boggle/bog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bog.c,v 1.33 2016/09/12 20:11:10 tb Exp $ */ +/* $OpenBSD: bog.c,v 1.34 2021/10/23 11:22:48 mestre Exp $ */ /* $NetBSD: bog.c,v 1.5 1995/04/24 12:22:32 cgd Exp $ */ /*- @@ -90,9 +90,6 @@ main(int argc, char *argv[]) int ch, done; char *bspec, *p; - if (pledge("stdio rpath tty", NULL) == -1) - err(1, "pledge"); - batch = debug = reuse = selfuse; bspec = NULL; minlength = -1; @@ -164,6 +161,10 @@ main(int argc, char *argv[]) return 0; } setup(); + + if (pledge("stdio rpath tty", NULL) == -1) + err(1, "pledge"); + prompt("Loading the dictionary..."); if ((dictfp = opendict(DICT)) == NULL) { warn("%s", DICT); diff --git a/games/bs/bs.c b/games/bs/bs.c index 188933f5aa8..8358ac7dd7a 100644 --- a/games/bs/bs.c +++ b/games/bs/bs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bs.c,v 1.41 2018/08/24 11:14:49 mestre Exp $ */ +/* $OpenBSD: bs.c,v 1.42 2021/10/23 11:22:48 mestre Exp $ */ /* * Copyright (c) 1986, Bruce Holloway * All rights reserved. @@ -1335,9 +1335,6 @@ scount(int who) int main(int argc, char *argv[]) { - if (pledge("stdio rpath tty", NULL) == -1) - err(1, "pledge"); - do_options(argc, argv); intro(); diff --git a/games/cribbage/crib.c b/games/cribbage/crib.c index e45fbd2c335..75f4ca27044 100644 --- a/games/cribbage/crib.c +++ b/games/cribbage/crib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crib.c,v 1.23 2016/03/07 12:07:56 mestre Exp $ */ +/* $OpenBSD: crib.c,v 1.24 2021/10/23 11:22:48 mestre Exp $ */ /* $NetBSD: crib.c,v 1.7 1997/07/10 06:47:29 mikel Exp $ */ /*- @@ -44,9 +44,6 @@ main(int argc, char *argv[]) bool playing; int ch; - if (pledge("stdio rpath tty proc exec", NULL) == -1) - err(1, "pledge"); - while ((ch = getopt(argc, argv, "ehmqr")) != -1) switch (ch) { case 'e': diff --git a/games/gomoku/main.c b/games/gomoku/main.c index cfae259b279..5e79e6a6d44 100644 --- a/games/gomoku/main.c +++ b/games/gomoku/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.32 2016/01/08 21:38:33 mestre Exp $ */ +/* $OpenBSD: main.c,v 1.33 2021/10/23 11:22:48 mestre Exp $ */ /* * Copyright (c) 1994 * The Regents of the University of California. All rights reserved. @@ -80,9 +80,6 @@ main(int argc, char **argv) }; char *tmpname; - if (pledge("stdio rpath wpath cpath tty", NULL) == -1) - err(1, "pledge"); - if ((tmpname = getlogin()) != NULL) strlcpy(you, tmpname, sizeof(you)); else @@ -123,6 +120,10 @@ main(int argc, char **argv) if (interactive) cursinit(); /* initialize curses */ + + if (pledge("stdio rpath wpath cpath tty", NULL) == -1) + err(1, "pledge"); + again: bdinit(board); /* initialize board contents */ diff --git a/games/grdc/grdc.c b/games/grdc/grdc.c index 567e60d710a..287fb14e95f 100644 --- a/games/grdc/grdc.c +++ b/games/grdc/grdc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grdc.c,v 1.33 2020/06/06 17:03:16 cheloha Exp $ */ +/* $OpenBSD: grdc.c,v 1.34 2021/10/23 11:22:49 mestre Exp $ */ /* * * Copyright 2002 Amos Shapir. Public domain. @@ -79,9 +79,6 @@ main(int argc, char *argv[]) int ybase; int wintoosmall; - if (pledge("stdio rpath tty", NULL) == -1) - err(1, "pledge"); - scrol = wintoosmall = 0; while ((i = getopt(argc, argv, "sh")) != -1) { switch (i) { diff --git a/games/hangman/main.c b/games/hangman/main.c index 5f6ed15aa8e..fffbe83a452 100644 --- a/games/hangman/main.c +++ b/games/hangman/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.19 2016/02/28 06:24:06 tb Exp $ */ +/* $OpenBSD: main.c,v 1.20 2021/10/23 11:22:49 mestre Exp $ */ /* $NetBSD: main.c,v 1.3 1995/03/23 08:32:50 cgd Exp $ */ /* @@ -49,9 +49,6 @@ main(int argc, char *argv[]) { int ch; - if (pledge("stdio rpath tty", NULL) == -1) - err(1, "pledge"); - while ((ch = getopt(argc, argv, "d:hk")) != -1) { switch (ch) { case 'd': diff --git a/games/mille/mille.c b/games/mille/mille.c index 5b8684cd9ee..8ab0a082056 100644 --- a/games/mille/mille.c +++ b/games/mille/mille.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mille.c,v 1.25 2016/01/08 18:09:59 mestre Exp $ */ +/* $OpenBSD: mille.c,v 1.26 2021/10/23 11:22:49 mestre Exp $ */ /* $NetBSD: mille.c,v 1.4 1995/03/24 05:01:48 cgd Exp $ */ /* @@ -50,9 +50,6 @@ main(int ac, char *av[]) bool restore; extern char *__progname; - if (pledge("stdio rpath wpath cpath tty", NULL) == -1) - err(1, "pledge"); - #ifdef DEBUG if (strcmp(av[0], "a.out") == 0) { outf = fopen("q", "w"); @@ -73,6 +70,10 @@ main(int ac, char *av[]) } Play = PLAYER; initscr(); + + if (pledge("stdio rpath wpath cpath tty", NULL) == -1) + err(1, "pledge"); + if ((LINES < 24) || (COLS < 80)) { endwin(); fprintf(stderr, "Screen must be at least 24x80\n"); diff --git a/games/rain/rain.c b/games/rain/rain.c index 6a10c49d251..1873fa2b917 100644 --- a/games/rain/rain.c +++ b/games/rain/rain.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rain.c,v 1.21 2016/01/07 16:00:33 tb Exp $ */ +/* $OpenBSD: rain.c,v 1.22 2021/10/23 11:22:49 mestre Exp $ */ /* * Copyright (c) 1980, 1993 @@ -59,9 +59,6 @@ main(int argc, char *argv[]) int ch; int xpos[5], ypos[5]; - if (pledge("stdio rpath tty", NULL) == -1) - err(1, "pledge"); - /* set default delay based on terminal baud rate */ if (tcgetattr(STDOUT_FILENO, &term) == 0 && (speed = cfgetospeed(&term)) > B9600) diff --git a/games/robots/main.c b/games/robots/main.c index 76454474b76..97b941f0da1 100644 --- a/games/robots/main.c +++ b/games/robots/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.29 2020/02/14 19:17:33 schwarze Exp $ */ +/* $OpenBSD: main.c,v 1.30 2021/10/23 11:22:49 mestre Exp $ */ /* $NetBSD: main.c,v 1.5 1995/04/22 10:08:54 cgd Exp $ */ /* @@ -61,9 +61,6 @@ main(int ac, char *av[]) char *sp; #endif - if (pledge("stdio rpath wpath cpath tty", NULL) == -1) - err(1, "pledge"); - home = getenv("HOME"); if (home == NULL || *home == '\0') err(1, "getenv"); diff --git a/games/worms/worms.c b/games/worms/worms.c index 869e9311a30..1942cf6a448 100644 --- a/games/worms/worms.c +++ b/games/worms/worms.c @@ -1,4 +1,4 @@ -/* $OpenBSD: worms.c,v 1.29 2018/08/06 06:27:32 mestre Exp $ */ +/* $OpenBSD: worms.c,v 1.30 2021/10/23 11:22:49 mestre Exp $ */ /* * Copyright (c) 1980, 1993 @@ -180,9 +180,6 @@ main(int argc, char *argv[]) speed_t speed; time_t delay = 0; - if (pledge("stdio rpath tty", NULL) == -1) - err(1, "pledge"); - /* set default delay based on terminal baud rate */ if (tcgetattr(STDOUT_FILENO, &term) == 0 && (speed = cfgetospeed(&term)) > B9600)