mock ChangeLog, 1.8, 1.9 Makefile, 1.8, 1.9 mock.py, 1.53, 1.54 mock.spec, 1.16, 1.17

John Clark Williams (jcwillia) fedora-extras-commits at redhat.com
Wed Jun 28 15:14:48 UTC 2006


Author: jcwillia

Update of /cvs/fedora/mock
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv31610

Modified Files:
	ChangeLog Makefile mock.py mock.spec 
Log Message:
updated version to 0.7 (new launcher mechanism)


Index: ChangeLog
===================================================================
RCS file: /cvs/fedora/mock/ChangeLog,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ChangeLog	13 Jun 2006 05:36:07 -0000	1.8
+++ ChangeLog	28 Jun 2006 15:14:45 -0000	1.9
@@ -1,3 +1,37 @@
+2006-06-28  Clark Williams  <williams at redhat.com>
+
+	* mock.py
+	added code in Root class to save uid/gid
+	added elevate and drop methods to Root
+	changed most invocations of self.do() to self.do_elevated()
+	added flocking and flushing around status writes
+	moved cache logic from mock-helper into pack and unpack methods
+	added -n to mount and unmount of chroot entities (proc, sys, etc)
+	bracketed _mount, _umount and RPM calls with elevate and drop
+	removed commented out /boot/kernel manipulations
+	removed /usr/sbin/mock-helper from config_opts initializations
+	removed check for root and mock group membership
+
+	* mock.spec
+	changed version to 0.7
+	removed /usr/sbin/mock-helper
+	added /usr/bin/mock
+	
+	* Makefile
+	Changed install commands to use -D to create path components
+	
+	* ChangeLog
+	updated and check in changelog
+	
+	* etc/defaults.cfg
+	pared down options
+	
+2006-06-27  Clark Williams  <williams at redhat.com>
+
+	* src/:
+	check in new launcher source (mock.c)
+	modified Makefile to build new source
+
 2006-06-13 01:31  skvidal
 
 	* etc/defaults.cfg: 


Index: Makefile
===================================================================
RCS file: /cvs/fedora/mock/Makefile,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Makefile	12 Apr 2006 14:23:17 -0000	1.8
+++ Makefile	28 Jun 2006 15:14:45 -0000	1.9
@@ -19,10 +19,8 @@
 	for d in $(SUBDIRS); do make -C $$d; [ $$? = 0 ] || exit 1 ; done
 
 install:
-	mkdir -p $(DESTDIR)/usr/bin/
-	mkdir -p $(DESTDIR)/usr/libexec
-	install -m 755 mock.py $(DESTDIR)/usr/bin/mock
-	install -m 755 mock-yum $(DESTDIR)/usr/libexec/mock-yum
+	install -D -m 755 mock.py $(DESTDIR)/usr/bin/mock.py
+	install -D -m 755 mock-yum $(DESTDIR)/usr/libexec/mock-yum
 	mkdir -p $(DESTDIR)/var/lib/mock
 	for d in $(SUBDIRS); do make  DESTDIR=`cd $(DESTDIR); pwd` -C $$d install; [ $$? = 0 ] || exit 1; done
 


Index: mock.py
===================================================================
RCS file: /cvs/fedora/mock/mock.py,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- mock.py	8 Jun 2006 21:28:46 -0000	1.53
+++ mock.py	28 Jun 2006 15:14:45 -0000	1.54
@@ -26,6 +26,7 @@
 import grp
 import stat
 import time
+import fcntl
 from exceptions import Exception
 
 from optparse import OptionParser
@@ -106,6 +107,17 @@
         self._state = 'unstarted'
         self.tmplog = LogBuffer()
         self.config = config
+
+        # save our uids
+        self.highuid = os.geteuid()
+        self.lowuid = os.getuid()
+
+        # set gid to mock group
+        os.setgid(os.getegid())
+            
+        # insure we're *not* running privileged
+        self.drop()
+        
         root = config['root']
         if config.has_key('unique-ext'):
             root = "%s-%s" % (root, config['unique-ext'])
@@ -151,6 +163,14 @@
         cfgout.flush()
         cfgout.close()
     
+    def elevate(self):
+        self.debug("elevate: setting uid to %d" % self.highuid)
+        os.setreuid(self.highuid, self.lowuid)
+
+    def drop(self):
+        self.debug("drop: setting uid to %d" % self.lowuid)
+        os.setreuid(self.lowuid, self.highuid)
+        
     def log(self, msg):
         if self.config['quiet']: return
         print msg
@@ -184,8 +204,7 @@
             
         if os.path.exists(self.basedir):
             cmd = '%s -rf %s' % (self.config['rm'], self.basedir)
-            (retval, output) = self.do(cmd)
-
+            (retval, output) = self.do_elevated(cmd)
             if retval != 0:
                 error("Errors cleaning out chroot: %s" % output)
                 if os.path.exists(self.rootdir):
@@ -200,7 +219,9 @@
         if curstate:
             sf = os.path.join(self.statedir, 'status')
             sfo = open(sf, 'w')
+            fcntl.flock(sfo, fcntl.LOCK_EX)
             sfo.write('%s\n' % curstate)
+            fcntl.flock(sfo, fcntl.LOCK_UN)
             sfo.close()
             self._state = curstate
             self.log(curstate)
@@ -208,15 +229,31 @@
             return self._state
 
     def unpack(self):
-        self.state('unpack cache')
-        cmd = '%s %s %s' % (self.config['unpack_cmd'], self.basedir, self.cache_file)
-        self.do(cmd)
+        self.state('unpack_cache')
+        if self.cache_file.find(".bz2") != -1:
+            opts = "-jxpf"
+        elif self.cache_file.find(".gz") != -1:
+            opts = "-zxpf"
+        else:
+            opts = "-xpf"
+        cmd = '%s %s %s %s' % (self.config['unpack_cmd'], opts, self.basedir, self.cache_file)
+        self.debug("unpacking cache: %s" % cmd)
+        (retval, output) = self.do_elevated(cmd)
+        return retval
 
     def pack(self):
-        self.state('create cache')
+        self.state('create_cache')
         self._ensure_dir(os.path.join(self.config['basedir'], self.config['cache_topdir']))
-        cmd = '%s %s %s root' % (self.config['pack_cmd'], self.basedir, self.cache_file)
-        self.do(cmd)
+        if self.cache_file.find(".bz2") != -1:
+            opts = "-jlcf"
+        elif self.cache_file.find(".gz") != -1:
+            opts = "-zlcf"
+        else:
+            opts = "-clf"
+        cmd = '%s %s %s root' % (self.config['pack_cmd'], opts, self.cache_file)
+        self.debug("creating cache: %s" % cmd)
+        (retval, output) = self.do_elevated(cmd)
+        return retval
     
     def prep(self):
         self.state("prep")
@@ -260,7 +297,7 @@
         command = '%s %s' % (basecmd, cmd)
         self.debug("yum: command %s" % command)
 
-        (retval, output) = self.do(command)
+        (retval, output) = self.do_elevated(command)
 
         if retval != 0:
             raise YumError, "Error performing yum command: %s" % command
@@ -412,10 +449,10 @@
         self._ensure_dir(procdir)
 
         self.debug("mounting proc in %s" % procdir)
-        command = '%s -t proc proc %s/proc' % (self.config['mount'], 
+        command = '%s -n -t proc proc %s/proc' % (self.config['mount'], 
                                                self.rootdir)
         track.write('proc\n')
-        (retval, output) = self.do(command)
+        (retval, output) = self.do_elevated(command)
         track.flush()
         
         if retval != 0:
@@ -427,9 +464,9 @@
         devptsdir = os.path.join(self.rootdir, 'dev/pts')
         self._ensure_dir(devptsdir)
         self.debug("mounting devpts in %s" % devptsdir)
-        command = '%s -t devpts devpts %s' % (self.config['mount'], devptsdir)
+        command = '%s -n -t devpts devpts %s' % (self.config['mount'], devptsdir)
         track.write('dev/pts\n')
-        (retval, output) = self.do(command)
+        (retval, output) = self.do_elevated(command)
         track.flush()
         track.close()
 
@@ -441,8 +478,8 @@
     def _umount(self, path):
     
         item = '%s/%s' % (self.rootdir, path)
-        command = '%s %s' % (self.config['umount'], item)
-        (retval, output) = self.do(command)
+        command = '%s -n %s' % (self.config['umount'], item)
+        (retval, output) = self.do_elevated(command)
     
         if retval != 0:
             if output.find('not mounted') == -1: # this probably won't work in other LOCALES
@@ -464,7 +501,9 @@
             if len(item.strip()) < 1:
                 continue
             
+            self.elevate()
             self._umount(item)
+            self.drop()
             
         # poof, no more file
         if os.path.exists(mf):
@@ -504,6 +543,30 @@
 
         return (retval, output)
 
+    def do_elevated(self, cmd):
+        if os.getuid() != self.highuid:
+            need_drop = 1
+        else:
+            need_drop = 0
+        try:
+            self.elevate()
+            (retval, output) = self.do(cmd)
+        finally:
+            if need_drop: self.drop()
+        return (retval, output)
+
+    def do_asuser(self, cmd):
+        if os.getuid() != self.lowuid:
+            need_elevate = 1
+        else:
+            need_elevate = 0
+        try:
+            self.drop()
+            (retval, output) = self.do(cmd)
+        finally:
+            if need_elevate: self.elevate()
+        return (retval, output)
+
     def do_chroot(self, command, fatal = False, exitcode=None):
         """execute given command in root"""
         cmd = ""
@@ -518,7 +581,7 @@
                                                  self.rootdir,
                                                  self.config['runuser'],
                                                  command)
-        (ret, output) = self.do(cmd)
+        (ret, output) = self.do_elevated(cmd)
         if (ret != 0) and fatal:
             self.close()
             if exitcode:
@@ -544,13 +607,17 @@
             if n.startswith('rpmlib'):
                 continue
 
+            self.elevate()
             req = rpmUtils.miscutils.formatRequire(n, v, f)
+            self.drop()
             reqlist.append(req)
         
         # Extract SRPM name components - still not nice, shouldn't this
         # be somewhere in the "hdr" parameter?
         fname = os.path.split(str(srpm))[1]
+        self.elevate()
         name, ver, rel, epoch, arch = rpmUtils.miscutils.splitFilename(fname)
+        self.drop()
 
         # Add the 'more_buildreqs' for this SRPM (if defined)
         for this_srpm in ['-'.join([name,ver,rel]),
@@ -564,7 +631,10 @@
                     reqlist.append(req)
                 break
         
-        return rpmUtils.miscutils.unique(reqlist)
+        self.elevate()
+        ret = rpmUtils.miscutils.unique(reqlist)
+        self.drop()
+        return ret
     
     def _prep_install(self):
         """prep chroot for installation"""
@@ -597,7 +667,7 @@
             cmd = '%s %s -m %s %s %s %s' % (self.config['mknod'], 
                       devpath, perm, devtype, major, minor)
             if not os.path.exists(devpath):
-                (retval, output) = self.do(cmd)
+                (retval, output) = self.do_elevated(cmd)
                 if retval != 0:
                     raise RootError, "could not mknod error was: %s" % output
 
@@ -715,14 +785,6 @@
         self._build_dir_setup()
         self._mount() # check it again
         
-        # FIXME - do we need this still?
-        # create /boot/kernel.h with a warning
-        #self.do_chroot ("mkdir -p /boot", fatal = True)
-        #self.do_chroot ("echo '#ifndef __BOOT_KERNEL_H_' > /boot/kernel.h", fatal = True)
-        #self.do_chroot ("echo '#define __BOOT_KERNEL_H_' >> /boot/kernel.h", fatal = True)
-        #self.do_chroot ("echo '#error This is a kernel.h generated by mock, including this indicates a build error !' >> /boot/kernel.h", fatal = True)
-        #self.do_chroot ("echo '#endif /* __BOOT_KERNEL_H_ */' >> /boot/kernel.h", fatal = True)
-        
 def command_parse():
     """return options and args from parsing the command line"""
     
@@ -760,12 +822,12 @@
 
 def setup_default_config_opts(config_opts):
     config_opts['basedir'] = '/var/lib/mock/' # root name is automatically added to this
-    config_opts['chroot'] = '/usr/sbin/mock-helper chroot'
-    config_opts['mount'] = '/usr/sbin/mock-helper mount'
-    config_opts['umount'] = '/usr/sbin/mock-helper umount'
-    config_opts['rm'] = '/usr/sbin/mock-helper rm'
-    config_opts['mknod'] = '/usr/sbin/mock-helper mknod'
-    config_opts['yum'] = '/usr/sbin/mock-helper yum'
+    config_opts['chroot'] = 'chroot'
+    config_opts['mount'] = 'mount'
+    config_opts['umount'] = 'umount'
+    config_opts['rm'] = 'rm'
+    config_opts['mknod'] = 'mknod'
+    config_opts['yum'] = 'yum'
     config_opts['runuser'] = '/sbin/runuser'
     config_opts['chroot_setup_cmd'] = 'install buildsys-build'
     config_opts['chrootuser'] = 'mockbuild'
@@ -792,8 +854,8 @@
     # caching-related config options
     config_opts['rebuild_cache'] = False
     config_opts['use_cache'] = False
-    config_opts['pack_cmd'] = "/usr/sbin/mock-helper pack"
-    config_opts['unpack_cmd'] = "/usr/sbin/mock-helper unpack"
+    config_opts['pack_cmd'] = "tar"
+    config_opts['unpack_cmd'] = "tar"
     config_opts['cache_ext'] = ".tar.gz"
     config_opts['cache_topdir'] = "root-cache"
     config_opts['max_cache_age_days'] = 15
@@ -888,25 +950,7 @@
     print "Results and/or logs in: %s" % my.resultdir
 
 def main():
-    # before we go on, make sure the user is a member of the 'mock' group.
-    member = False
-    for item in os.getgroups():
-        try:
-            grptup = grp.getgrgid(item)
-        except KeyError, e:
-            continue
-        if grptup[0] == 'mock':
-            member = True
-
-    if not member:
-        print "You need to be a member of the mock group for this to work"
-        sys.exit(1)
 
-    # and make sure they're not root
-    if os.geteuid() == 0:
-        error("Don't try to run mock as root!")
-        sys.exit(1)
-        
     # defaults
     config_opts = {}
     setup_default_config_opts(config_opts)


Index: mock.spec
===================================================================
RCS file: /cvs/fedora/mock/mock.spec,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- mock.spec	7 Jun 2006 12:29:15 -0000	1.16
+++ mock.spec	28 Jun 2006 15:14:45 -0000	1.17
@@ -1,6 +1,6 @@
 Summary: Builds packages inside chroots
 Name: mock
-Version: 0.6
+Version: 0.7
 Release: 1
 License: GPL
 Group: Development/Tools
@@ -28,7 +28,7 @@
 # make the default.cfg link
 cd $RPM_BUILD_ROOT/%{_sysconfdir}/%{name}
 ln -s fedora-development-i386-core.cfg default.cfg
-
+cd $RPM_BUILD_ROOT/%{_bindir}
 
 %clean
 rm -rf $RPM_BUILD_ROOT
@@ -45,15 +45,20 @@
 %doc README ChangeLog
 %dir  %{_sysconfdir}/%{name}
 %config(noreplace) %{_sysconfdir}/%{name}/*.cfg
-%{_bindir}/%{name}
+%attr(04750, root, mock) %{_bindir}/%{name}
+%{_bindir}/%{name}.py*
 %{_libexecdir}/mock-yum
 %{_mandir}/man1/mock.1*
-%attr(04750, root, mock) %{_sbindir}/mock-helper
 %attr(02775, root, mock) %dir /var/lib/mock
 %{_libdir}/libselinux-mock.so
 
 
 %changelog
+* Wed Jun 28 2006 Clark Williams <williams at redhat.com> - 0.7-1
+- updated version to 0.7
+- removed /usr/sbin/mock-helper
+- added /usr/bin/mock launcher
+
 * Wed Jun  7 2006 Seth Vidal <skvidal at linux.duke.edu>
 - version update
 




More information about the scm-commits mailing list