util.subp: do not attach stdin cloud-init's stdin to subprocesses (LP: 831505)
Fix issue where 'isatty' would return true for apt-add-repository. It would get stdin which was attached to a terminal (/dev/console) and would thus hang when running during boot. This was done by changing all users of util.subp to have None input unless input was given. In that case, the input will be the string passed in.
This commit is contained in:
		@@ -38,6 +38,11 @@
 | 
			
		||||
   * boothooks will now run more than once as they were intended (and as bootcmd
 | 
			
		||||
     commands do)
 | 
			
		||||
   * cloud-config and user-scripts will be updated from user data every boot
 | 
			
		||||
 - Fix issue where 'isatty' would return true for apt-add-repository.
 | 
			
		||||
   apt-add-repository would get stdin which was attached to a terminal
 | 
			
		||||
  (/dev/console) and would thus hang when running during boot.  (LP: 831505)
 | 
			
		||||
   This was done by changing all users of util.subp to have None input unless specified
 | 
			
		||||
  
 | 
			
		||||
0.6.1:
 | 
			
		||||
 - fix bug in fixing permission on /var/log/cloud-init.log (LP: #704509)
 | 
			
		||||
 - improve comment strings in rsyslog file tools/21-cloudinit.conf
 | 
			
		||||
 
 | 
			
		||||
@@ -127,7 +127,7 @@ def add_sources(srclist, searchList={ }):
 | 
			
		||||
 | 
			
		||||
        source=ent['source']
 | 
			
		||||
        if source.startswith("ppa:"):
 | 
			
		||||
            try: util.subp(["add-apt-repository",source], "/dev/null")
 | 
			
		||||
            try: util.subp(["add-apt-repository",source])
 | 
			
		||||
            except:
 | 
			
		||||
                elst.append([source, "add-apt-repository failed"])
 | 
			
		||||
            continue
 | 
			
		||||
 
 | 
			
		||||
@@ -141,10 +141,8 @@ def runparts(dirp, skip_no_exist=True):
 | 
			
		||||
    return
 | 
			
		||||
 | 
			
		||||
def subp(args, input=None):
 | 
			
		||||
    s_in = None
 | 
			
		||||
    if input is not None:
 | 
			
		||||
        s_in = subprocess.PIPE
 | 
			
		||||
    sp = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=s_in)
 | 
			
		||||
    sp = subprocess.Popen(args, stdout=subprocess.PIPE,
 | 
			
		||||
        stderr=subprocess.PIPE, stdin=subprocess.PIPE)
 | 
			
		||||
    out,err = sp.communicate(input)
 | 
			
		||||
    if sp.returncode is not 0:
 | 
			
		||||
        raise subprocess.CalledProcessError(sp.returncode,args, (out,err))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user