oxidecomputer/helios

build-illumos command could sanitize environment variables

jordanhendricks opened this issue · 1 comments

I had a build failure that was pretty confusing.

mail_msg said:

==== Build errors (non-DEBUG) ====                                                                       
                                                                                                         
The following command caused the error:                                                                  
The following command caused the error:                                                                  
dmake: Warning: Target `install' not remade because of errors                                            
The following command caused the error:                                                                  
dmake: Warning: Target `install' not remade because of errors                                            
dmake: Warning: Command failed for target `svc'                                                          
dmake: Warning: Target `install' not remade because of errors                                            
The following command caused the error:                                                                  
dmake: Warning: Target `install' not remade because of errors                                            
                                                                                                         
==== Build warnings (non-DEBUG) ====                                                                     
                                                                                                         
dmake: Warning: Target `install' not remade because of errors                                            
dmake: Warning: Target `install' not remade because of errors                                            
dmake: Warning: Command failed for target `svc'                                                          
dmake: Warning: Target `install' not remade because of errors                                            
dmake: Warning: Target `install' not remade because of errors  

After narrowing some things down, I started trying to build just usr/src/cmd/svc/profile in bldenv. It failed as such:

$ dmake install
Check for enabled open services not covered by limited profile
sh: /home/jordan/src/helios/projects/illumos/usr/src/test: cannot execute [Is a directory]
*** Error code 126
The following command caused the error:
/home/jordan/src/helios/projects/illumos/usr/src/test ! -s check_open.notcovered && /usr/bin/touch check_open
dmake: Fatal error: Command failed for target `check_open'
Current working directory /home/jordan/src/helios/projects/illumos/usr/src/cmd/svc/profile

The error message suggested it was trying to execute something that it shouldn't be. Looking at the Makefile here, we have:

TEST =  /usr/bin/test                                                                                    
...

#                                                                                                        
#       Enforce consistency between open and limited profiles per README                                 
#                                                                                                        
$(CHECK_OPEN) :=        PROFILES_CHECKED = open                                                          
$(CHECK_OPEN) :=        PROFILES_COVERING = limited                                                      
$(CHECK_LMTD) :=        PROFILES_CHECKED = limited                                                       
$(CHECK_LMTD) :=        PROFILES_COVERING = open                                                         
$(CHECK_OPEN) $(CHECK_LMTD): \                                                                           
        $(LISTSVCS) $(PROFILES_open) $(PROFILES_limited)                                                 
        @$(ECHO) Check for enabled $(PROFILES_CHECKED) services \                                        
                not covered by $(PROFILES_COVERING) profile                                              
        @$(PERL) -w $(LISTSVCS) -e $(PROFILES_$(PROFILES_CHECKED)) > $@.enabled                          
        @$(PERL) -w $(LISTSVCS) $(PROFILES_$(PROFILES_COVERING)) > $@.all                                
        @$(COMM) -23 $@.enabled $@.all | $(TEE) $@.notcovered                                            
        @$(TEST) ! -s $@.notcovered && $(TOUCH) $@ 

/usr/bin/test was on my system and appeared to be right. I went down a bunch of paths here, including noticing that $PATH in bldenv included . but did not seem to come from my shell. (Is this expected behavior?)

Ultimately, running dmake -n helped me see what the problem was:

/home/jordan/src/helios/projects/illumos/usr/src/test ! -s check_limited.notcovered && /usr/bin/touch check_limited

Instead of /usr/bin/test, it was trying to run: /home/jordan/src/helios/projects/illumos/usr/src/test. It turns out I had a shell variable called TEST that was defined to that path.

I was pretty surprised by this behavior -- that setting a shell variable could interfere with building in this way. The fact that we use MAKEFLAGS=e, which makes env variables override macro assignments, explains this behavior.

It might be nice to have build-illumos sanitize some of the user's environment to prevent goose chases like this in the future.

Because this is about build-time / developer pain and not product impact, I'm currently tagging this unscheduled, though that doesn't take away from the need to fix this.