Skip to contentSkip to conversation

Makedevs: add recursive option

PATCH New Angelo Compagnucci 3 participants 12 messages Mar 13, 2015 – Apr 11, 2015

lore
Share & tools
lore
#0 lore raw

cover Makedevs: add recursive option

This patch series add the recursive option to makedevs.

With recursive option will be possible to apply owner/permission recursively to folders.

Angelo Compagnucci (2):
package/makedevs: add recursive option docs/manual: documentation for recursive makedevs syntax

 docs/manual/makedev-syntax.txt | 10 +++++++++-
 package/makedevs/makedevs.c    | 23 +++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/2 package/makedevs: add recursive option

This patch adds the possibilty to change owner/permission of a folder recursively.

---
 package/makedevs/makedevs.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
package/makedevs/makedevs.c +23 -0
index ab90b93..e575427 100644
@@ -34,6 +34,8 @@
 #ifndef __APPLE__
 #include <sys/sysmacros.h>     /* major() and minor() */
 #endif
+#include <ftw.h>
+
 
 const char *bb_applet_name;
 
@@ -332,6 +334,7 @@ void bb_show_usage(void)
 	fprintf(stderr, "Where name is the file name,  type can be one of:\n");
 	fprintf(stderr, "      f       A regular file\n");
 	fprintf(stderr, "      d       Directory\n");
+	fprintf(stderr, "      r       Directory recursively\n");
 	fprintf(stderr, "      c       Character special device file\n");
 	fprintf(stderr, "      b       Block special device file\n");
 	fprintf(stderr, "      p       Fifo (named pipe)\n");
@@ -364,6 +367,20 @@ void bb_show_usage(void)
 	exit(1);
 }
 
+bb_recursive(const char *full_name, uid_t uid, gid_t gid, unsigned int mode){
+
+	int chmod_chown(const char *fpath, const struct stat *sb,
+		int tflag, struct FTW *ftwbuf) {
+		if (chown(fpath, uid, gid) == -1) return -1;
+		if ((mode != -1)) {
+			if (chmod(fpath, mode) < 0) return -1;
+		}
+		return 0;
+	}
+
+	return nftw(full_name, chmod_chown, 20, FTW_MOUNT | FTW_PHYS);
+}
+
 int main(int argc, char **argv)
 {
 	int opt;
@@ -474,6 +491,12 @@ int main(int argc, char **argv)
 				ret = EXIT_FAILURE;
 				goto loop;
 			}
+		} else if (type == 'r') {
+			if (bb_recursive(full_name, uid, gid, mode) < 0) {
+				bb_perror_msg("line %d: recursive failed for %s", linenum, full_name);
+				ret = EXIT_FAILURE;
+				goto loop;
+			}
 		} else
 		{
 			dev_t rdev;
Signature · 1 line
1.9.1
#2 lore raw

PATCH 1/2 package/makedevs: add recursive option

Dear Buildroot developers,
Il 13/mar/2015 11:50, "Angelo Compagnucci" <[email protected]> ha scritto:

Quoted 6 lines

This patch adds the possibilty to change owner/permission of a folder recursively.

---

Anybody willing to review this patch? I think it's very important to have the option to set permission on folders recursively!

I think this patch is really simple and could be reviewed/accepted with a minimal effort.

Quoted 17 lines
 package/makedevs/makedevs.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
package/makedevs/makedevs.c +2 -0
index ab90b93..e575427 100644
@@ -34,6 +34,8 @@
 #ifndef __APPLE__
 #include <sys/sysmacros.h>     /* major() and minor() */
 #endif
+#include <ftw.h>
+
 
 const char *bb_applet_name;
 

package/makedevs/makedevs.c void bb_show_usage(void) · line 334

Quoted 1 line
package/makedevs/makedevs.c +0 -0
@@ -332,6 +334,7 @@ void bb_show_usage(void)
        fprintf(stderr, "Where name is the file name,  type can be one

of:\n");

package/makedevs/makedevs.c void bb_show_usage(void) · line 370

Quoted 11 lines
package/makedevs/makedevs.c +2 -0
        fprintf(stderr, "      f       A regular file\n");
        fprintf(stderr, "      d       Directory\n");
+       fprintf(stderr, "      r       Directory recursively\n");
        fprintf(stderr, "      c       Character special device file\n");
        fprintf(stderr, "      b       Block special device file\n");
        fprintf(stderr, "      p       Fifo (named pipe)\n");
@@ -364,6 +367,20 @@ void bb_show_usage(void)
        exit(1);
 }
 
+bb_recursive(const char *full_name, uid_t uid, gid_t gid, unsigned int

mode){

Quoted 17 lines
package/makedevs/makedevs.c +13 -0
+
+       int chmod_chown(const char *fpath, const struct stat *sb,
+               int tflag, struct FTW *ftwbuf) {
+               if (chown(fpath, uid, gid) == -1) return -1;
+               if ((mode != -1)) {
+                       if (chmod(fpath, mode) < 0) return -1;
+               }
+               return 0;
+       }
+
+       return nftw(full_name, chmod_chown, 20, FTW_MOUNT | FTW_PHYS);
+}
+
 int main(int argc, char **argv)
 {
        int opt;

package/makedevs/makedevs.c int main(int argc, char **argv) · line 496

Quoted 6 lines
package/makedevs/makedevs.c +3 -0
@@ -474,6 +491,12 @@ int main(int argc, char **argv)
                                ret = EXIT_FAILURE;
                                goto loop;
                        }
+               } else if (type == 'r') {
+                       if (bb_recursive(full_name, uid, gid, mode) < 0) {
+                               bb_perror_msg("line %d: recursive failed

for %s", linenum, full_name);

Quoted 9 lines
package/makedevs/makedevs.c +3 -1
+                               ret = EXIT_FAILURE;
+                               goto loop;
+                       }
                } else
                {
                        dev_t rdev;
--

1.9.1

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20150405/257df3f5/attachment.html>

#3 lore raw

PATCH 1/2 package/makedevs: add recursive option

Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Angelo" == Angelo Compagnucci <[email protected]> writes:

Dear Buildroot developers,
Il 13/mar/2015 11:50, "Angelo Compagnucci" <[email protected]> ha scritto:

Quoted 4 lines

This patch adds the possibilty to change owner/permission of a folder recursively.

Quoted 8 lines
Quoted 2 lines

---

Anybody willing to review this patch? I think it's very important to have the option to set permission on folders recursively!

I think this patch is really simple and could be reviewed/accepted with a minimal effort.

Sorry, I've been away quite a bit lately, I'll try to find time to review later today.

Signature · 1 line
Bye, Peter Korsgaard
#4 lore raw

PATCH 1/2 package/makedevs: add recursive option

In reply to Angelo Compagnucci

Angelo, All,

On 2015-03-13 11:50 +0100, Angelo Compagnucci spake thusly:

Quoted 4 lines

This patch adds the possibilty to change owner/permission of a folder recursively.

[I really only did a review and no actual tests]

As a side comment: maybe that would be interesting to submit a similar patch for busybox (where makedevs originated); note however that busybox has changed quite a lot since we forked makedevs...

Regards,
Yann E. MORIN.

Quoted 66 lines
---
 package/makedevs/makedevs.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
package/makedevs/makedevs.c +23 -0
index ab90b93..e575427 100644
@@ -34,6 +34,8 @@
 #ifndef __APPLE__
 #include <sys/sysmacros.h>     /* major() and minor() */
 #endif
+#include <ftw.h>
+
 
 const char *bb_applet_name;
 
@@ -332,6 +334,7 @@ void bb_show_usage(void)
 	fprintf(stderr, "Where name is the file name,  type can be one of:\n");
 	fprintf(stderr, "      f       A regular file\n");
 	fprintf(stderr, "      d       Directory\n");
+	fprintf(stderr, "      r       Directory recursively\n");
 	fprintf(stderr, "      c       Character special device file\n");
 	fprintf(stderr, "      b       Block special device file\n");
 	fprintf(stderr, "      p       Fifo (named pipe)\n");
@@ -364,6 +367,20 @@ void bb_show_usage(void)
 	exit(1);
 }
 
+bb_recursive(const char *full_name, uid_t uid, gid_t gid, unsigned int mode){
+
+	int chmod_chown(const char *fpath, const struct stat *sb,
+		int tflag, struct FTW *ftwbuf) {
+		if (chown(fpath, uid, gid) == -1) return -1;
+		if ((mode != -1)) {
+			if (chmod(fpath, mode) < 0) return -1;
+		}
+		return 0;
+	}
+
+	return nftw(full_name, chmod_chown, 20, FTW_MOUNT | FTW_PHYS);
+}
+
 int main(int argc, char **argv)
 {
 	int opt;
@@ -474,6 +491,12 @@ int main(int argc, char **argv)
 				ret = EXIT_FAILURE;
 				goto loop;
 			}
+		} else if (type == 'r') {
+			if (bb_recursive(full_name, uid, gid, mode) < 0) {
+				bb_perror_msg("line %d: recursive failed for %s", linenum, full_name);
+				ret = EXIT_FAILURE;
+				goto loop;
+			}
 		} else
 		{
 			dev_t rdev;
Signature · 6 lines
1.9.1

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#5 lore raw

PATCH 1/2 package/makedevs: add recursive option

Dear Yann E. MORIN,

2015-04-09 23:23 GMT+02:00 Yann E. MORIN <[email protected]>:

Quoted 8 lines

Angelo, All,

On 2015-03-13 11:50 +0100, Angelo Compagnucci spake thusly:

Quoted 4 lines

This patch adds the possibilty to change owner/permission of a folder recursively.

Quoted 7 lines

[I really only did a review and no actual tests]

As a side comment: maybe that would be interesting to submit a similar patch for busybox (where makedevs originated); note however that busybox has changed quite a lot since we forked makedevs...

I've not submitted upstream cause the code for makedevs is in buildroot source tree ...
If you think it's important, I will submit not later the patch will accepted.

Thank you!

Quoted 78 lines

Regards,
Yann E. MORIN.

Quoted 62 lines
---
 package/makedevs/makedevs.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
package/makedevs/makedevs.c +23 -1
index ab90b93..e575427 100644
@@ -34,6 +34,8 @@
 #ifndef __APPLE__
 #include <sys/sysmacros.h>     /* major() and minor() */
 #endif
+#include <ftw.h>
+
 
 const char *bb_applet_name;
 
@@ -332,6 +334,7 @@ void bb_show_usage(void)
      fprintf(stderr, "Where name is the file name,  type can be one of:\n");
      fprintf(stderr, "      f       A regular file\n");
      fprintf(stderr, "      d       Directory\n");
+     fprintf(stderr, "      r       Directory recursively\n");
      fprintf(stderr, "      c       Character special device file\n");
      fprintf(stderr, "      b       Block special device file\n");
      fprintf(stderr, "      p       Fifo (named pipe)\n");
@@ -364,6 +367,20 @@ void bb_show_usage(void)
      exit(1);
 }
 
+bb_recursive(const char *full_name, uid_t uid, gid_t gid, unsigned int mode){
+
+     int chmod_chown(const char *fpath, const struct stat *sb,
+             int tflag, struct FTW *ftwbuf) {
+             if (chown(fpath, uid, gid) == -1) return -1;
+             if ((mode != -1)) {
+                     if (chmod(fpath, mode) < 0) return -1;
+             }
+             return 0;
+     }
+
+     return nftw(full_name, chmod_chown, 20, FTW_MOUNT | FTW_PHYS);
+}
+
 int main(int argc, char **argv)
 {
      int opt;
@@ -474,6 +491,12 @@ int main(int argc, char **argv)
                              ret = EXIT_FAILURE;
                              goto loop;
                      }
+             } else if (type == 'r') {
+                     if (bb_recursive(full_name, uid, gid, mode) < 0) {
+                             bb_perror_msg("line %d: recursive failed for %s", linenum, full_name);
+                             ret = EXIT_FAILURE;
+                             goto loop;
+                     }
              } else
              {
                      dev_t rdev;
--

1.9.1

Quoted 4 lines

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

--
.-----------------.--------------------.------------------.--------------------.

|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |

'------------------------------^-------^------------------^--------------------'

Signature · 1 line
Profile: http://it.linkedin.com/in/compagnucciangelo
#6 lore raw

PATCH 1/2 package/makedevs: add recursive option

Angelo, All,

On 2015-04-10 07:39 +0200, Angelo Compagnucci spake thusly:

Quoted 11 lines

2015-04-09 23:23 GMT+02:00 Yann E. MORIN <[email protected]>:

Quoted 10 lines

On 2015-03-13 11:50 +0100, Angelo Compagnucci spake thusly:

Quoted 4 lines

This patch adds the possibilty to change owner/permission of a folder recursively.

[I really only did a review and no actual tests]

Quoted 7 lines
Quoted 3 lines

As a side comment: maybe that would be interesting to submit a similar patch for busybox (where makedevs originated); note however that busybox has changed quite a lot since we forked makedevs...

I've not submitted upstream cause the code for makedevs is in buildroot source tree ...
If you think it's important, I will submit not later the patch will accepted.

Well, I won't say it is "important". It all really depends from the perspective.

For one, I believe this is an interesting feature, from which busybox could well benefit. So it makes sense to submit it to busybox. Of course, this is not really correlated to our own makedevs, except by ancestry.

So, if you have spare CPU cycles, please go ahead. If not, then no problem. That was just a suggestion! ;-)

Thanks!

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#7 lore raw

PATCH 1/2 package/makedevs: add recursive option

In reply to Angelo Compagnucci
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Angelo" == Angelo Compagnucci <[email protected]> writes:

This patch adds the possibilty to change owner/permission of a folder recursively.

Thanks, a few comments:

package/makedevs/makedevs.c void bb_show_usage(void) · line 379

Quoted 10 lines
package/makedevs/makedevs.c +10 -0
+bb_recursive(const char *full_name, uid_t uid, gid_t gid, unsigned int mode){
+
+	int chmod_chown(const char *fpath, const struct stat *sb,
+		int tflag, struct FTW *ftwbuf) {
+		if (chown(fpath, uid, gid) == -1) return -1;
+		if ((mode != -1)) {
+			if (chmod(fpath, mode) < 0) return -1;
+		}
+		return 0;
+	}

I know you are doing this because nftw doesn't allow any extra arguments to be passed to the function, but using GCC specific nested functions isn't really nice.

Does E.G. clang support these? Alternatively we could port recursive_action() from busybox.

It would also be good to stick some bb_error_msg in there so people can get a hint about what fails.

Signature · 1 line
Bye, Peter Korsgaard
#8 lore raw

PATCH 1/2 package/makedevs: add recursive option

Dear Peter,

2015-04-10 23:41 GMT+02:00 Peter Korsgaard <[email protected]>:

Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Angelo" == Angelo Compagnucci <[email protected]> writes:

This patch adds the possibilty to change owner/permission of a folder recursively.

Thanks, a few comments:

Quoted 15 lines

package/makedevs/makedevs.c void bb_show_usage(void) · line 379

Quoted 10 lines
package/makedevs/makedevs.c +10 -0
+bb_recursive(const char *full_name, uid_t uid, gid_t gid, unsigned int mode){
+
+    int chmod_chown(const char *fpath, const struct stat *sb,
+            int tflag, struct FTW *ftwbuf) {
+            if (chown(fpath, uid, gid) == -1) return -1;
+            if ((mode != -1)) {
+                    if (chmod(fpath, mode) < 0) return -1;
+            }
+            return 0;
+    }

I know you are doing this because nftw doesn't allow any extra arguments to be passed to the function, but using GCC specific nested functions isn't really nice.
Does E.G. clang support these?

Doh! I thought nested function could be a more widespread feature! Of course, you are right, clang doesn't support nested functions.

The naive solution could be to add a global object, could be acceptable? There are only three variables and could be nested inside a nice structure.

Quoted 2 lines

Alternatively we could port
recursive_action() from busybox.

/ * Unfortunately, while nftw(3) could replace this and reduce
* code size a bit, nftw() wasn't supported before GNU libc 2.1,
* and so isn't sufficiently portable to take over since glibc2.1
* is so stinking huge.
*/

The only reason why they stick with an hand made recursive function instead of nftw is to support older glibc 2.1 (!) that doesn't have that function.
I think it's not our problem and backporting that old code is not a good idea!

What do you think?

Quoted 2 lines

It would also be good to stick some bb_error_msg in there so people can get a hint about what fails.

Ok!

Quoted 3 lines

--
Bye, Peter Korsgaard

Signature · 1 line
Profile: http://it.linkedin.com/in/compagnucciangelo
#9 lore raw

PATCH 1/2 package/makedevs: add recursive option

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Angelo" == Angelo Compagnucci <[email protected]> writes:

hi,

Quoted 10 lines
Quoted 4 lines

I know you are doing this because nftw doesn't allow any extra arguments to be passed to the function, but using GCC specific nested functions isn't really nice.
Does E.G. clang support these?

Doh! I thought nested function could be a more widespread feature! Of course, you are right, clang doesn't support nested functions.

The naive solution could be to add a global object, could be acceptable? There are only three variables and could be nested inside a nice structure.

Yes, or simply 3 globals (recursive_{uid,gid,mode}) to keep it simple.

Quoted 9 lines
Quoted 2 lines

Alternatively we could port
recursive_action() from busybox.

/ * Unfortunately, while nftw(3) could replace this and reduce
* code size a bit, nftw() wasn't supported before GNU libc 2.1,
* and so isn't sufficiently portable to take over since glibc2.1
* is so stinking huge.
*/

Quoted 4 lines

The only reason why they stick with an hand made recursive function instead of nftw is to support older glibc 2.1 (!) that doesn't have that function.
I think it's not our problem and backporting that old code is not a good idea!

Yes, that AND the fact that recursive_action takes a userData structure that gets forwarded to the callbacks.

But yeah, just using nftw with 3 globals is simpler.

Signature · 2 lines
Venlig hilsen,
Peter Korsgaard 
#10 lore raw

PATCH 2/2 docs/manual: documentation for recursive makedevs syntax

In reply to Angelo Compagnucci

This patch adds the necessary documentation for the new makedevs recursive syntax.

---
 docs/manual/makedev-syntax.txt | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
docs/manual/makedev-syntax.txt +9 -1
index e02b79d..afb4ae2 100644
@@ -24,6 +24,7 @@ There are a few non-trivial blocks:
 - +type+ is the type of the file, being one of:
   * f: a regular file
   * d: a directory
+  * r: a directory recursively
   * c: a character device file
   * b: a block device file
   * p: a named pipe
@@ -38,7 +39,14 @@ Let's say you want to change the permissions of a given file; using
 this syntax, you will need to put:
 
 ----
-/usr/bin/foobar f 644 0 0 - - -	- -
+/usr/bin/foobar f 644 0 0 - - - - -
+----
+
+Alternatively, if you want to change owner/permission of a folder
+recursively, you can put:
+
+----
+/usr/share/myapp r 750 myuser myuser - - - - -
 ----
 
 On the other hand, if you want to create the device file +/dev/hda+
Signature · 1 line
1.9.1
#11 lore raw

cover Makedevs: add recursive option

In reply to Angelo Compagnucci

Dear Buildroot Developers,

2015-03-13 11:50 GMT+01:00 Angelo Compagnucci <[email protected]>:

Quoted 8 lines

This patch series add the recursive option to makedevs.

With recursive option will be possible to apply owner/permission recursively to folders.

Angelo Compagnucci (2):
package/makedevs: add recursive option docs/manual: documentation for recursive makedevs syntax

Please give this patch series some love! I think that it iss very important to have an option to set permission recursively. Think of all that people that wants to serve html or any server side language content in a secure manner, they can't actually!

Sincerely, Angelo.

Signature · 1 line
Profile: http://it.linkedin.com/in/compagnucciangelo