changeset 1728:d7e43cc0f525

Add -m to mknod
author Rob Landley <rob@landley.net>
date Tue, 10 Mar 2015 14:37:03 -0500
parents c0ef9b7976f0
children 801eba977271
files toys/lsb/mknod.c
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/toys/lsb/mknod.c	Tue Mar 10 11:07:28 2015 -0500
+++ b/toys/lsb/mknod.c	Tue Mar 10 14:37:03 2015 -0500
@@ -4,28 +4,32 @@
  *
  * http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/mknod.html
 
-USE_MKNOD(NEWTOY(mknod, "<2>4", TOYFLAG_BIN))
+USE_MKNOD(NEWTOY(mknod, "<2>4m(mode):", TOYFLAG_BIN|TOYFLAG_UMASK))
 
 config MKNOD
   bool "mknod"
   default y
   help
-    usage: mknod NAME TYPE [MAJOR MINOR]
+    usage: mknod [-m MODE] NAME TYPE [MAJOR MINOR]
 
-    Create a special file NAME with a given type, possible types are
-    b	block device
-    c or u	character device
-    p	named pipe (ignores MAJOR/MINOR)
+    Create a special file NAME with a given type. TYPE is b for block device,
+    c or u for character device, p for named pipe (which ignores MAJOR/MINOR).
+
+    -m	Mode (file permissions) of new device, in octal or u+x format
 */
 
 #define FOR_mknod
 #include "toys.h"
 
+GLOBALS(
+  char *m;
+)
+
 void mknod_main(void)
 {
   mode_t modes[] = {S_IFIFO, S_IFCHR, S_IFCHR, S_IFBLK};
   int major=0, minor=0, type;
-  int mode = 0660;
+  int mode = TT.m ? string_to_mode(TT.m, 0777) : 0660;
 
   type = stridx("pcub", *toys.optargs[1]);
   if (type == -1) perror_exit("bad type '%c'", *toys.optargs[1]);