skip to Main Content

I want to get the source code of an RPM package, with all patches applied. (what the apt source do)

For example, bash. Here is something I’ve tried.

Firstly, I download the src RPM package via yumdownloader:

yumdownloader --source bash

Then, I got a package named bash-4.2.46-35.el7_9.src.rpm. I used the following command to extract this file:

rpm2cpio bash-4.2.46-35.el7_9.src.rpm | cpio -ivdm

Then, I got the following files:

[root@ce944fc560a2 src]# ls
bash-2.02-security.patch       bash-3.2-ssh_source_bash.patch        bash-4.2-cve-2014-7169-0.patch            bash-4.2-man-ulimit.patch      bash-4.3-cve-2016-0634.patch         bash-5.0-syslog-history.patch  bash42-003  bash42-013  bash42-023  bash42-033  bash42-043
bash-2.03-paths.patch          bash-4.0-nobits.patch                 bash-4.2-cve-2014-7169-1.patch            bash-4.2-manpage.patch         bash-4.3-cve-2016-7543.patch         bash-bashbug.patch             bash42-004  bash42-014  bash42-024  bash42-034  bash42-044
bash-2.03-profile.patch        bash-4.1-broken_pipe.patch            bash-4.2-cve-2014-7169-2.patch            bash-4.2-manpage_trap.patch    bash-4.3-dircomp-append-slash.patch  bash-cve-2016-9401.patch       bash42-005  bash42-015  bash42-025  bash42-035  bash42-045
bash-2.05a-interpreter.patch   bash-4.1-defer-sigchld-trap.patch     bash-4.2-double-alloc.patch               bash-4.2-missing-opt-cd.patch  bash-4.3-pipefd-leak.patch           bash-infotags.patch            bash42-006  bash42-016  bash42-026  bash42-036  bash42-046
bash-2.05b-debuginfo.patch     bash-4.1-examples.patch               bash-4.2-enable-hyphened-fn-export.patch  bash-4.2-missing_closes.patch  bash-4.3-trapped-signals.patch       bash-requires.patch            bash42-007  bash42-017  bash42-027  bash42-037  bash42-052
bash-2.05b-manso.patch         bash-4.1-trap.patch                   bash-4.2-env-inject.patch                 bash-4.2-noecho.patch          bash-4.3-wshouldquote.patch          bash-setlocale.patch           bash42-008  bash42-018  bash42-028  bash42-038  bash42-053
bash-2.05b-pgrp_sync.patch     bash-4.2-brace-expand.patch           bash-4.2-extglob-man.patch                bash-4.2-rc2-logout.patch      bash-4.4-bracketed-paste.patch       bash-tty-tests.patch           bash42-009  bash42-019  bash42-029  bash42-039  dot-bash_logout
bash-2.05b-readline-oom.patch  bash-4.2-case-in-command-subst.patch  bash-4.2-history-hang.patch               bash-4.2-signal.patch          bash-4.4-cve-2019-9924.patch         bash.spec                      bash42-010  bash42-020  bash42-030  bash42-040  dot-bash_profile
bash-2.05b-xcc.patch           bash-4.2-check-debugger.patch         bash-4.2-ifs-in-temp-env.patch            bash-4.2-size_type.patch       bash-4.4-param-expansion.patch       bash42-001                     bash42-011  bash42-021  bash42-031  bash42-041  dot-bashrc
bash-3.2-audit.patch           bash-4.2-coverity.patch               bash-4.2-leak-compound.patch              bash-4.2.tar.gz                bash-4.4-pipeline-pgrp.patch         bash42-002                     bash42-012  bash42-022  bash42-032  bash42-042  fix-shopt-lastpipe-mode-crash.patch

There is a tgz file bash-4.2.tar.gz which is the original bash source code and lots of patch files.

How to patch these files to the original source code? If my steps are wrong, is there a simple way to solve my question?

2

Answers


  1. Chosen as BEST ANSWER

    After reading the Rebuild a Source RPM, I found an approach to solve the problem.

    Firstly, use the yumdownloader to download a source package:

    yumdownloader --source bash
    

    Then, use the rpmbuild to rebuild the package without build and dependency check:

    rpmbuild --nobuild --nodeps --rebuild bash-4.2.46-35.el7_9.src.rpm
    

    rpmbuild will help you deal with all the things. Then the source code is here: $HOME/rpmbuild/BUILD/bash-4.2/:

    [root@984f0a6b263e data]# ls /root/rpmbuild/BUILD/bash-4.2/
    ABOUT-NLS        aclocal.m4.pgrp_sync       bashtypes.h                   configure                    execute_cmd.c.026                      hashlib.c                  parse.y.005              patchlevel.h.006  patchlevel.h.027  pathexp.c.014           shell.h.053   subst.c.double-alloc     variables.c.006
    AUTHORS          alias.c                    bracecomp.c                   configure.in                 execute_cmd.c.coverity                 hashlib.h                  parse.y.012              patchlevel.h.007  patchlevel.h.028  pathexp.h               sig.c         subst.c.leak-compound    variables.c.7169-1
    CHANGES          alias.h                    braces.c                      configure.in.audit           execute_cmd.c.fix-shopt-lastpipe-mode  include                    parse.y.016              patchlevel.h.008  patchlevel.h.029  pathnames.h.in          sig.c.008     subst.c.noecho           variables.c.cve-2016-7543
    COMPAT           array.c                    braces.c.expand               configure.in.check-debugger  execute_cmd.c.interpreter              input.c                    parse.y.034              patchlevel.h.009  patchlevel.h.030  pcomplete.c             sig.h         subst.c.param-expansion  variables.c.cve-2019-9924
    COPYING          array.h                    builtins                      configure.in.interpreter     execute_cmd.c.nobits                   input.h                    parse.y.042              patchlevel.h.010  patchlevel.h.031  pcomplete.h             sig.h.signal  subst.c.pipeline-pgrp    variables.c.export
    CWRU             arrayfunc.c                builtins.h                    conftypes.h                  execute_cmd.c.pipefd-leak              jobs.c                     parse.y.053              patchlevel.h.011  patchlevel.h.032  pcomplib.c              siglist.c     subst.h                  variables.c.inject
    ChangeLog        arrayfunc.h                builtins.h.requires           copy_cmd.c                   execute_cmd.c.requires                 jobs.c.defer_sigchld_trap  parse.y.7169-0           patchlevel.h.012  patchlevel.h.033  po                      siglist.h     subst.h.001              variables.h
    INSTALL          assoc.c                    command.h                     copy_cmd.c.052               execute_cmd.h                          jobs.c.trapped-signals     parse.y.7169-2           patchlevel.h.013  patchlevel.h.034  print_cmd.c             stringlib.c   subst.h.param-expansion  variables.h.005
    MANIFEST         assoc.c.011                command.h.025                 cross-build                  execute_cmd.h.requires                 jobs.h                     parse.y.command-subst    patchlevel.h.014  patchlevel.h.035  print_cmd.c.010         subst.c       support                  variables.h.size_type
    MANIFEST.doc     assoc.h                    config-bot.h                  dispose_cmd.c                expr.c                                 lib                        parse.y.cve-2016-0634    patchlevel.h.015  patchlevel.h.036  quit.h                  subst.c.001   syntax.h                 version.c
    Makefile.in      bashansi.h                 config-top.h                  dispose_cmd.h                expr.c.015                             list.c                     parse.y.noecho           patchlevel.h.016  patchlevel.h.037  redir.c                 subst.c.004   test.c                   xmalloc.c
    Makefile.in.xcc  bashhist.c                 config-top.h.broken_pipe      doc                          expr.c.039                             locale.c                   parse.y.param-expansion  patchlevel.h.017  patchlevel.h.038  redir.c.040             subst.c.007   test.h                   xmalloc.h
    NEWS             bashhist.c.syslog-history  config-top.h.logout           error.c                      externs.h                              mailcheck.c                parse.y.security         patchlevel.h.018  patchlevel.h.039  redir.c.045             subst.c.013   tests                    y.tab.c
    NOTES            bashhist.h                 config-top.h.paths            error.c.023                  findcmd.c                              mailcheck.h                parser-built             patchlevel.h.019  patchlevel.h.040  redir.c.temp-env        subst.c.023   trap.c                   y.tab.c.cve-2016-0634
    POSIX            bashintl.h                 config-top.h.profile          error.h                      findcmd.h                              make_cmd.c                 parser.h                 patchlevel.h.020  patchlevel.h.041  redir.h                 subst.c.025   trap.c.signal            y.tab.c.param-expansion
    RBASH            bashjmp.h                  config-top.h.ssh_source_bash  eval.c                       flags.c                                make_cmd.c.052             patchlevel.h             patchlevel.h.021  patchlevel.h.042  shell.c                 subst.c.027   trap.c.trap              y.tab.h
    README           bashline.c                 config-top.h.syslog-history   eval.c.requires              flags.h                                make_cmd.c.requires        patchlevel.h.001         patchlevel.h.022  patchlevel.h.043  shell.c.bashbug         subst.c.028   trap.h
    Y2K              bashline.c.029             config.h.in                   examples                     general.c                              make_cmd.h                 patchlevel.h.002         patchlevel.h.023  patchlevel.h.044  shell.c.check-debugger  subst.c.032   unwind_prot.c
    _distribution    bashline.c.append-slash    config.h.in.audit             execute_cmd.c                general.h                              mksyntax.c                 patchlevel.h.003         patchlevel.h.024  patchlevel.h.045  shell.c.requires        subst.c.036   unwind_prot.h
    _patchlevel      bashline.h                 config.h.in.interpreter       execute_cmd.c.018            hashcmd.c                              nojobs.c                   patchlevel.h.004         patchlevel.h.025  patchlevel.h.046  shell.h                 subst.c.041   variables.c
    aclocal.m4       bashline.h.029             config.h.in.paths             execute_cmd.c.025            hashcmd.h                              parse.y                    patchlevel.h.005         patchlevel.h.026  pathexp.c         shell.h.012             subst.c.046   variables.c.005
    

  2. From the rpmbuild(1) man page

    -bp Unpack the sources and apply any patches – executes the %prep stage only.

    But -bX is for building from a .spec file, use -rX if you have the src.rpm. So the command

    rpmbuild -rp PACKAGENAME.src.rpm
    

    should work. I add the --verbose command-line option to see what’s going on, because neither the default rpmbuild output nor its man page give any hint that it puts the patched source in ~/rpmbuild/BUILD/PACKAGENAME .

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search