Skip to contentSkip to conversation

build: fix umask test

PATCH New Kurt Van Dijck 4 participants 12 messages May 30, 2016 – May 31, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 build: fix umask test

Some shells' builtin umask does not print 2 leading 0's for the umask. Not doing so would break the comparison.
This patch makes sure that the umask has (at least) 4 digits.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 63502d0..9a36769 100644
@@ -26,7 +26,7 @@
 
 # Trick for always running with a fixed umask
 UMASK = 0022
-ifneq ($(shell umask),$(UMASK))
+ifneq ($(shell printf "%04o\n" `umask`),$(UMASK))
 .PHONY: _all $(MAKECMDGOALS)
 
 $(MAKECMDGOALS): _all
#1 lore raw

PATCH 1/1 build: fix umask test

Quoted 16 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Kurt" == Kurt Van Dijck <[email protected]> writes:

Some shells' builtin umask does not print 2 leading 0's for the umask. Not doing so would break the comparison.
This patch makes sure that the umask has (at least) 4 digits.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +0 -0
index 63502d0..9a36769 100644

Makefile line 29

Quoted 5 lines
Makefile +1 -1
@@ -26,7 +26,7 @@
 
 # Trick for always running with a fixed umask
 UMASK = 0022
-ifneq ($(shell umask),$(UMASK))
+ifneq ($(shell printf "%04o\n" `umask`),$(UMASK))

Thanks, but with at least zsh this doesn't work:

zsh --version
zsh 5.0.7 (x86_64-pc-linux-gnu)

umask
022

printf "%04o\n" $(umask)
0026

It seems like the printf arguments are always handled as decimal.

It does work on bash though:

bash --version
GNU bash, version 4.3.33(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

umask
0022

printf "%04o\n" $(umask)
0022

It seems we need to use the base#number syntax, E.G. 8#umask to get zsh to interprete it as octal, but bash doesn't seem to like it :/

But the real question is why this happens in the first place? We do set SHELL=bash, so all of this should be running under bash where it works.

What shell are you using and how is your setup?

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

PATCH 1/1 build: fix umask test

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

"Peter" == Peter Korsgaard <[email protected]> writes:

Hi,

Quoted 5 lines

It seems we need to use the base#number syntax, E.G. 8#umask to get zsh to interprete it as octal, but bash doesn't seem to like it :/

But the real question is why this happens in the first place? We do set SHELL=bash, so all of this should be running under bash where it works.

Sorry, I misremembered. This logic is above the line where we assign bash to SHELL, so it runs with /bin/sh as shell. On my system, this is dash and it behaves like bash in this regard. What shell do you use?

In any case, I think the proper fix is to simply move the SHELL= line above here to ensure we get consistent results.

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

PATCH 1/1 build: fix umask test

Hello,

Quoted 3 lines · Peter Korsgaard

Sorry, I misremembered. This logic is above the line where we assign bash to SHELL, so it runs with /bin/sh as shell. On my system, this is dash and it behaves like bash in this regard. What shell do you use?

From the Kurt's previous e-mails, I believe he is using mksh as his shell.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#4 lore raw

PATCH 1/1 build: fix umask test

Quoted 10 lines

Hello,

Quoted 3 lines · Peter Korsgaard

Sorry, I misremembered. This logic is above the line where we assign bash to SHELL, so it runs with /bin/sh as shell. On my system, this is dash and it behaves like bash in this regard. What shell do you use?

From the Kurt's previous e-mails, I believe he is using mksh as his shell.

indeed, mksh it is.

I understand the zsh problem, on the other hand,
any number prefixed with a 0 is octal, isn't it?

Anyway, I'll re-think the patch too...

Kurt

#5 lore raw

PATCH 1/1 build: fix umask test

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

"Kurt" == Kurt Van Dijck <[email protected]> writes:

Hi,

Quoted 2 lines

I understand the zsh problem, on the other hand,
any number prefixed with a 0 is octal, isn't it?

Apparently not to zsh. I haven't found any official notice about it, but googling around shows this (old!) patch:

http://www.zsh.org/mla/workers/1995/msg00518.html

Quoted 1 line

Anyway, I'll re-think the patch too...

Just moving up the SHELL= line above this check should be enough.

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

PATCH 1/1 build: fix umask test

Quoted 6 lines

Hi,

Quoted 2 lines

I understand the zsh problem, on the other hand,
any number prefixed with a 0 is octal, isn't it?

Quoted 8 lines

Apparently not to zsh. I haven't found any official notice about it, but googling around shows this (old!) patch:

http://www.zsh.org/mla/workers/1995/msg00518.html

Quoted 1 line

Anyway, I'll re-think the patch too...

Just moving up the SHELL= line above this check should be enough.

I see, but how would that help when bash is not on the system? Is bash a prerequisite?

I was thinking on using /bin/printf to avoid using the shell builtin.

Kurt

#7 lore raw

PATCH 1/1 build: fix umask test

Quoted 9 lines · Kurt Van Dijck
Quoted 9 lines

Hi,

Quoted 2 lines

I understand the zsh problem, on the other hand,
any number prefixed with a 0 is octal, isn't it?

Apparently not to zsh. I haven't found any official notice about it, but googling around shows this (old!) patch:

Quoted 8 lines
Quoted 5 lines

http://www.zsh.org/mla/workers/1995/msg00518.html

Quoted 1 line

Anyway, I'll re-think the patch too...

Just moving up the SHELL= line above this check should be enough.

I see, but how would that help when bash is not on the system? Is bash a prerequisite?

Yes, bash is a prerequisite. Some of our own scripts are bash scripts.
Moreover, quite a few packages just assume that the shell is bash. Requiring bash and setting is as SHELL is the simplest way to handle that.

Quoted 2 lines

I was thinking on using /bin/printf to avoid using the shell builtin.

I don't have /bin/printf, only /usr/bin/printf...

Regards,
Arnout

Quoted 7 lines

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

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#8 lore raw

PATCH 1/1 build: fix umask test

Quoted 7 lines
Quoted 3 lines

I see, but how would that help when bash is not on the system? Is bash a prerequisite?

Yes, bash is a prerequisite. Some of our own scripts are bash scripts.
Moreover, quite a few packages just assume that the shell is bash. Requiring bash and setting is as SHELL is the simplest way to handle that.

The Makefile only recommends /bin/bash, it falls back to 'sh' when bash is not present.

Quoted 5 lines
Quoted 3 lines

I was thinking on using /bin/printf to avoid using the shell builtin.

I don't have /bin/printf, only /usr/bin/printf...

Thanks for mentioning, I'll address the problem without printf.

Kurt

#9 lore raw

PATCH 1/1 build: fix umask test

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line

"Kurt" == Kurt Van Dijck <[email protected]> writes:

I see, but how would that help when bash is not on the system? Is bash a prerequisite?

Quoted 6 lines
Quoted 3 lines

Yes, bash is a prerequisite. Some of our own scripts are bash scripts. Moreover, quite a few packages just assume that the shell is bash. Requiring bash and setting is as SHELL is the simplest way to handle that.

The Makefile only recommends /bin/bash, it falls back to 'sh' when bash is not present.

Yes, but support/dependencies/dependencies.sh checks for bash and bails out if not available.

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

PATCH 1/1 build: fix umask test

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line

"Kurt" == Kurt Van Dijck <[email protected]> writes:

I see, but how would that help when bash is not on the system? Is bash a prerequisite?

Yes, bash is a prerequisite. Some of our own scripts are bash scripts. Moreover, quite a few packages just assume that the shell is bash. Requiring bash and setting is as SHELL is the simplest way to handle that.

Quoted 5 lines
Quoted 2 lines

The Makefile only recommends /bin/bash, it falls back to 'sh' when bash is not present.

Yes, but support/dependencies/dependencies.sh checks for bash and bails out if not available.

I wasn't aware of this :-)

I already sent out a v2 of the patch which makes it shell-independant.

Kurt

#11 lore raw

PATCH 1/1 build: fix umask test

In reply to Thomas Petazzoni
Quoted 11 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Thomas" == Thomas Petazzoni <[email protected]> writes:

Hello,

Quoted 3 lines · Peter Korsgaard

Sorry, I misremembered. This logic is above the line where we assign bash to SHELL, so it runs with /bin/sh as shell. On my system, this is dash and it behaves like bash in this regard. What shell do you use?

From the Kurt's previous e-mails, I believe he is using mksh as his shell.

Yes, I noticed as well. I should stop reading my mails in reverse order ;)

Signature · 2 lines
Venlig hilsen,
Peter Korsgaard