nologin(8): write -> dprintf

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

nologin(8): write -> dprintf

Scott Cheloha
Use dprintf for the DEFAULT_MESG string instead of the more awkward
write+strlen combo.

ok?

--
Scott Cheloha

Index: sbin/nologin/nologin.c
===================================================================
RCS file: /cvs/src/sbin/nologin/nologin.c,v
retrieving revision 1.7
diff -u -p -r1.7 nologin.c
--- sbin/nologin/nologin.c 14 Aug 2018 18:13:11 -0000 1.7
+++ sbin/nologin/nologin.c 15 Aug 2018 14:07:28 -0000
@@ -30,7 +30,6 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 #include <unistd.h>
 
 /* Distinctly different from _PATH_NOLOGIN. */
@@ -52,8 +51,8 @@ main(int argc, char *argv[])
  err(1, "pledge");
 
  nfd = open(_PATH_NOLOGIN_TXT, O_RDONLY);
- if (nfd < 0) {
- write(STDOUT_FILENO, DEFAULT_MESG, strlen(DEFAULT_MESG));
+ if (nfd == -1) {
+ dprintf(STDOUT_FILENO, DEFAULT_MESG);
  exit (1);
  }
 

Reply | Threaded
Open this post in threaded view
|

Re: nologin(8): write -> dprintf

Todd C. Miller-2
On Wed, 15 Aug 2018 09:27:24 -0500, Scott Cheloha wrote:

> Use dprintf for the DEFAULT_MESG string instead of the more awkward
> write+strlen combo.

I don't object to this but I also wouldn't object to rewriting
nologin.c to use stdio.

 - todd

Reply | Threaded
Open this post in threaded view
|

Re: nologin(8): write -> dprintf

Theo de Raadt-2
Todd C. Miller <[hidden email]> wrote:

> > Use dprintf for the DEFAULT_MESG string instead of the more awkward
> > write+strlen combo.
>
> I don't object to this but I also wouldn't object to rewriting
> nologin.c to use stdio.

I wonder if nologin was written in this ignore-errors-from-write
style, such that if a tty stops behaving right nologin can reach
termination reliably rather than getting stuck

Reply | Threaded
Open this post in threaded view
|

Re: nologin(8): write -> dprintf

Alexander Hall
In reply to this post by Scott Cheloha


On August 15, 2018 4:27:24 PM GMT+02:00, Scott Cheloha <[hidden email]> wrote:

>Use dprintf for the DEFAULT_MESG string instead of the more awkward
>write+strlen combo.
>
>ok?
>
>--
>Scott Cheloha
>
>Index: sbin/nologin/nologin.c
>===================================================================
>RCS file: /cvs/src/sbin/nologin/nologin.c,v
>retrieving revision 1.7
>diff -u -p -r1.7 nologin.c
>--- sbin/nologin/nologin.c 14 Aug 2018 18:13:11 -0000 1.7
>+++ sbin/nologin/nologin.c 15 Aug 2018 14:07:28 -0000
>@@ -30,7 +30,6 @@
> #include <fcntl.h>
> #include <stdio.h>
> #include <stdlib.h>
>-#include <string.h>
> #include <unistd.h>
>
> /* Distinctly different from _PATH_NOLOGIN. */
>@@ -52,8 +51,8 @@ main(int argc, char *argv[])
> err(1, "pledge");
>
> nfd = open(_PATH_NOLOGIN_TXT, O_RDONLY);
>- if (nfd < 0) {
>- write(STDOUT_FILENO, DEFAULT_MESG, strlen(DEFAULT_MESG));
>+ if (nfd == -1) {
>+ dprintf(STDOUT_FILENO, DEFAULT_MESG);

"%s" at the very least.

/Alexander
> exit (1);
> }
>