rpm  5.4.14
poptI.c
Go to the documentation of this file.
1 
6 #include "system.h"
7 
8 #include <rpmio.h>
9 #include <rpmiotypes.h>
10 #include <rpmlog.h>
11 
12 #include <rpmtag.h>
13 #include <rpmcli.h>
14 
15 #include "debug.h"
16 
17 /*@-redecl@*/
18 extern time_t get_date(const char * p, void * now); /* XXX expedient lies */
19 /*@=redecl@*/
20 
21 /*@-fullinitblock@*/
22 /*@unchecked@*/
24 #if defined(RPM_VENDOR_MANDRIVA) || defined(RPM_VENDOR_PLD) /* dont-filter-install-file-conflicts */
26 #else
28 #endif
29 };
30 /*@=fullinitblock@*/
31 
32 #define POPT_RELOCATE -1021
33 #define POPT_EXCLUDEPATH -1022
34 #define POPT_ROLLBACK -1023
35 #define POPT_ROLLBACK_EXCLUDE -1024
36 /* -1025 thrugh -1033 are common in rpmcli.h. */
37 #define POPT_AUTOROLLBACK_GOAL -1036
38 
39 #define alloca_strdup(_s) strcpy((char *)alloca(strlen(_s)+1), (_s))
40 
46 static void argerror(const char * desc) __attribute__((__noreturn__));
47 /*@exits@*/
48 static void argerror(const char * desc)
49  /*@globals stderr, fileSystem @*/
50  /*@modifies stderr, fileSystem @*/
51 {
52  /*@-modfilesys -globs @*/
53  fprintf(stderr, _("%s: %s\n"), __progname, desc);
54  /*@=modfilesys =globs @*/
56 }
57 
60 static void installArgCallback(/*@unused@*/ poptContext con,
61  /*@unused@*/ enum poptCallbackReason reason,
62  const struct poptOption * opt, const char * arg,
63  /*@unused@*/ const void * data)
64  /*@globals rpmIArgs, stderr @*/
65  /*@modifies rpmIArgs, stderr @*/
66 {
67  QVA_t ia = &rpmIArgs;
68  int xx;
69 
70  /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
71  if (opt->arg == NULL)
72  switch (opt->val) {
73 
74  case 'i':
77  break;
78 
79  case POPT_EXCLUDEPATH:
80  if (arg == NULL || *arg != '/')
81  argerror(_("exclude paths must begin with a /"));
82  xx = rpmfiAddRelocation(&ia->relocations, &ia->nrelocations, arg, NULL);
83  break;
84  case POPT_RELOCATE:
85  { char * oldPath = NULL;
86  char * newPath = NULL;
87 
88  if (arg == NULL)
89  argerror(_("Option --relocate needs /old/path=/new/path argument"));
90  if (*arg != '/')
91  argerror(_("relocations must begin with a /"));
92  oldPath = xstrdup(arg);
93  if (!(newPath = strchr(oldPath, '=')))
94  argerror(_("relocations must contain a ="));
95  *newPath++ = '\0';
96  if (*newPath != '/')
97  argerror(_("relocations must have a / following the ="));
99  oldPath, newPath);
100  oldPath = _free(oldPath);
101  } break;
102 
104  { rpmuint32_t tid;
105  char *t, *te;
106 
107  /* Make sure we were given the proper number of args */
108  if (arg == NULL)
109  argerror(_("Option --rbexclude needs transaction id argument(s)"));
110 
111  te = alloca_strdup(arg);
112  while (*te != '\0' && strchr(" \t\n,", *te) != NULL)
113  *te++ = '\0';
114  while ((t = te++) != NULL && *t != '\0') {
115  /* Find next tid. */
116  while (*te != '\0' && strchr(" \t\n,", *te) == NULL)
117  te++;
118  while (*te != '\0' && strchr(" \t\n,", *te) != NULL)
119  *te++ = '\0';
120 
121  /* Convert arg to TID which happens to be time_t */
122  /* XXX: Need check for arg to be an integer */
123  tid = (rpmuint32_t) strtol(t, NULL, 0);
124 
125  /* Allocate space for new exclude tid */
127  sizeof(*ia->rbtidExcludes) * (ia->numrbtidExcludes + 1));
128 
129  /* Add it to the list and iterate count*/
130 /*@-temptrans@*/
131  ia->rbtidExcludes[ia->numrbtidExcludes] = tid;
132 /*@=temptrans@*/
133  ia->numrbtidExcludes++;
134  }
135  } break;
136 
137  case POPT_ROLLBACK:
138  { time_t tid;
139  if (arg == NULL)
140  argerror(_("Option --rollback needs a time/date stamp argument"));
141 
142  /*@-moduncon@*/
143  tid = get_date(arg, NULL);
144  rpmlog(RPMLOG_INFO, _("Rollback goal: %-24.24s (0x%08x)\n"), ctime(&tid), (int)tid);
145  /*@=moduncon@*/
146 
147  if (tid == (time_t)-1 || tid == (time_t)0)
148  argerror(_("malformed rollback time/date stamp argument"));
149  ia->rbtid = (rpmuint32_t)tid;
150  } break;
151 
153  { time_t tid;
154  if (arg == NULL)
155  argerror(_("arbgoal takes a time/date stamp argument"));
156 
157  /*@-moduncon@*/
158  tid = get_date(arg, NULL);
159  /*@=moduncon@*/
160 
161  if (tid == (time_t)-1 || tid == (time_t)0)
162  argerror(_("malformed arbgoal time/date stamp argument"));
163  ia->arbtid = (rpmuint32_t)tid;
164  } break;
165 
168  break;
169 
172  break;
173 
176  break;
177 
178  case RPMCLI_POPT_NODEPS:
179  ia->noDeps = 1;
180  break;
181 
183  ia->transFlags = (rpmtransFlags)
185  break;
186 
188  ia->transFlags = (rpmtransFlags)
190  break;
191 
193  ia->transFlags = (rpmtransFlags)
195  break;
196 
197  }
198 }
199 
202 /*@-bitwisesigned -compmempass @*/
203 /*@unchecked@*/
204 struct poptOption rpmInstallPoptTable[] = {
205 /*@-type@*/ /* FIX: cast? */
206  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
207  (void *) installArgCallback, 0, NULL, NULL },
208 /*@=type@*/
209 
210  { "allfiles", '\0', POPT_BIT_SET,
212  N_("install all files, even configurations which might otherwise be skipped"),
213  NULL},
214  { "apply", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
217  N_("do not execute package scriptlet(s)"), NULL },
218  { "dirstash", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
220  N_("save erased package files by renaming into sub-directory"), NULL},
221  { "excludeconfigs", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
223  N_("do not install configuration files"), NULL},
224  { "excludedocs", '\0', POPT_BIT_SET,
225  &rpmIArgs.transFlags, RPMTRANS_FLAG_NODOCS,
226  N_("do not install documentation"), NULL},
227  { "justdb", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_JUSTDB,
228  N_("update the database, but do not modify the filesystem"), NULL},
229  { "noconfigs", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
231  N_("do not install configuration files"), NULL},
232  { "nodocs", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
233  &rpmIArgs.transFlags, RPMTRANS_FLAG_NODOCS,
234  N_("do not install documentation"), NULL},
235 #ifdef NOTYET /* XXX multiple identical options forces popt callback. */
236  { "nocontexts", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
238  N_("don't install file security contexts"), NULL},
239  { "nofdigests", '\0', POPT_BIT_SET,
241  N_("don't verify file digests"), NULL },
242 #else
243  { "nocontexts", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NOCONTEXTS,
244  N_("don't verify file security contexts"), NULL },
245  { "nofdigests", '\0', 0, NULL, RPMCLI_POPT_NOFDIGESTS,
246  N_("don't verify file digests"), NULL },
247 #endif
248  { "norpmdb", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
250  N_("don't register headers in rpmdb"), NULL},
251 
252 #ifdef NOTYET /* XXX multiple identical options forces popt callback. */
253  { "noscripts", '\0', POPT_BIT_SET,
255  N_("do not execute package scriptlet(s)"), NULL },
256 #else
257  { "noscripts", '\0', 0, NULL, RPMCLI_POPT_NOSCRIPTS,
258  N_("do not execute package scriptlet(s)"), NULL },
259 #endif
260  { "nopretrans", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
262  N_("do not execute %%pretrans scriptlet (if any)"), NULL },
263  { "nopre", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
264  &rpmIArgs.transFlags, RPMTRANS_FLAG_NOPRE,
265  N_("do not execute %%pre scriptlet (if any)"), NULL },
266  { "nopost", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
267  &rpmIArgs.transFlags, RPMTRANS_FLAG_NOPOST,
268  N_("do not execute %%post scriptlet (if any)"), NULL },
269  { "nopreun", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
271  N_("do not execute %%preun scriptlet (if any)"), NULL },
272  { "nopostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
274  N_("do not execute %%postun scriptlet (if any)"), NULL },
275  { "noposttrans", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
277  N_("do not execute %%postrans scriptlet (if any)"), NULL },
278 
279  { "notriggers", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, _noTransTriggers,
280  N_("do not execute any scriptlet(s) triggered by this package"), NULL},
281  { "notriggerprein", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
283  N_("do not execute any %%triggerprein scriptlet(s)"), NULL},
284  { "notriggerin", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
286  N_("do not execute any %%triggerin scriptlet(s)"), NULL},
287  { "notriggerun", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
289  N_("do not execute any %%triggerun scriptlet(s)"), NULL},
290  { "notriggerpostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
292  N_("do not execute any %%triggerpostun scriptlet(s)"), NULL},
293 
294  { "repackage", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE,
296  N_("save erased package files by repackaging"), NULL},
297  { "test", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_TEST,
298  N_("don't install, but tell if it would work or not"), NULL},
299 
300  { "allmatches", '\0', POPT_BIT_SET,
302  N_("remove all packages which match <package> (normally an error is generated if <package> specified multiple packages)"),
303  NULL},
304 
305  { "badreloc", '\0', POPT_BIT_SET,
307  N_("relocate files in non-relocatable package"), NULL},
308 
309  { "erase", 'e', POPT_BIT_SET,
311  N_("erase (uninstall) package"), N_("<package>+") },
312  { "excludepath", '\0', POPT_ARG_STRING, NULL, POPT_EXCLUDEPATH,
313  N_("skip files with leading component <path> "),
314  N_("<path>") },
315 
316  { "fileconflicts", '\0', POPT_BIT_CLR, &rpmIArgs.probFilter,
318  N_("detect file conflicts between packages"), NULL},
319 
320  { "freshen", 'F', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags,
322  N_("upgrade package(s) if already installed"),
323  N_("<packagefile>+") },
324  { "hash", 'h', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags, INSTALL_HASH,
325  N_("print hash marks as package installs (good with -v)"), NULL},
326 #ifndef DIEDIEDIE
327  { "ignorearch", '\0', POPT_BIT_SET,
329  N_("don't verify package architecture"), NULL},
330  { "ignoreos", '\0', POPT_BIT_SET,
332  N_("don't verify package operating system"), NULL},
333 #endif
334  { "ignoresize", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
336  N_("don't check disk space before installing"), NULL},
337  { "includedocs", '\0', POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.incldocs, 0,
338  N_("install documentation"), NULL},
339 
340  { "install", 'i', 0, NULL, 'i',
341  N_("install package(s)"), N_("<packagefile>+") },
342 
343  { "nodeps", '\0', 0, NULL, RPMCLI_POPT_NODEPS,
344  N_("do not verify package dependencies"), NULL },
345 
346  { "noorder", '\0', POPT_BIT_SET,
348  N_("do not reorder package installation to satisfy dependencies"),
349  NULL},
350 
351  { "nodigest", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NODIGEST,
352  N_("don't verify package digest(s)"), NULL },
353  { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NOHDRCHK,
354  N_("don't verify database header(s) when retrieved"), NULL },
355  { "nosignature", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NOSIGNATURE,
356  N_("don't verify package signature(s)"), NULL },
357 
358  { "oldpackage", '\0', POPT_BIT_SET,
360  N_("upgrade to an old version of the package (--force on upgrades does this automatically)"),
361  NULL},
362  { "percent", '\0', POPT_BIT_SET,
364  N_("print percentages as package installs"), NULL},
365  { "prefix", '\0', POPT_ARG_STRING, &rpmIArgs.qva_prefix, 0,
366  N_("relocate the package to <dir>, if relocatable"),
367  N_("<dir>") },
368  { "relocate", '\0', POPT_ARG_STRING, NULL, POPT_RELOCATE,
369  N_("relocate files from path <old> to <new>"),
370  N_("<old>=<new>") },
371  { "replacefiles", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
373  N_("ignore file conflicts between packages"), NULL},
374  { "replacepkgs", '\0', POPT_BIT_SET,
376  N_("reinstall if the package is already present"), NULL},
377  { "rollback", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, NULL, POPT_ROLLBACK,
378  N_("deinstall new, reinstall old, package(s), back to <date>"),
379  N_("<date>") },
380  { "arbgoal", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, NULL, POPT_AUTOROLLBACK_GOAL,
381  N_("If transaction fails rollback to <date>"),
382  N_("<date>") },
383  { "rbexclude", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, NULL, POPT_ROLLBACK_EXCLUDE,
384  N_("Exclude Transaction I.D. from rollback"),
385  N_("<tid>") },
386  { "upgrade", 'U', POPT_BIT_SET,
388  N_("upgrade package(s)"),
389  N_("<packagefile>+") },
390 
391  POPT_TABLEEND
392 };
393 /*@=bitwisesigned =compmempass @*/
rpmRelocation relocations
Definition: rpmcli.h:683
#define POPT_AUTOROLLBACK_GOAL
Definition: poptI.c:37
int xx
Definition: spec.c:744
rpmlog(RPMLOG_ERR,"%s\n", buf)
const char * qva_prefix
Definition: rpmcli.h:657
#define EXIT_FAILURE
char * xstrdup(const char *str)
Definition: rpmmalloc.c:321
#define POPT_ROLLBACK
Definition: poptI.c:34
#define __progname
Definition: system.h:363
rpmQueryFlags qva_flags
Definition: rpmcli.h:633
rpmuint32_t arbtid
Definition: rpmcli.h:675
#define alloca_strdup(_s)
Definition: poptI.c:39
#define _noTransScripts
Definition: rpmts.h:103
#define RPMCLI_POPT_NODIGEST
Definition: rpmcli.h:100
Command line option information.
Definition: rpmcli.h:630
#define RPMCLI_POPT_NOCONTEXTS
Definition: rpmcli.h:102
#define RPMCLI_POPT_NOSCRIPTS
Definition: rpmcli.h:98
int numrbtidExcludes
Definition: rpmcli.h:678
#define _noTransTriggers
Definition: rpmts.h:112
#define POPT_EXCLUDEPATH
Definition: poptI.c:33
Yet Another syslog(3) API clone.
goto exit
Definition: db3.c:1903
unsigned int rpmuint32_t
Definition: rpmiotypes.h:28
#define RPMCLI_POPT_NOHDRCHK
Definition: rpmcli.h:101
struct poptOption rpmInstallPoptTable[]
Definition: poptI.c:204
char * p
Definition: macro.c:413
fprintf(stderr,"--> %s(%p,%p,%p) sig %p sigp %p\n", __FUNCTION__, dig, t, rsactx, sig, sigp)
#define N_(Text)
Definition: system.h:531
time_t get_date(const char *p, void *now)
#define POPT_ARGFLAG_TOGGLE
Definition: poptIO.c:68
int rpmfiAddRelocation(rpmRelocation *relp, int *nrelp, const char *oldPath, const char *newPath)
Add relocation element to array.
Definition: rpmfi.c:1726
rpmtransFlags transFlags
Definition: rpmcli.h:672
rpmuint32_t rbtid
Definition: rpmcli.h:676
#define POPT_RELOCATE
Definition: poptI.c:32
rpmuint32_t * rbtidExcludes
Definition: rpmcli.h:677
rpmInstallInterfaceFlags installInterfaceFlags
Definition: rpmcli.h:674
rpmprobFilterFlags probFilter
Definition: rpmcli.h:673
#define RPMCLI_POPT_NOFDIGESTS
Definition: rpmcli.h:97
static void installArgCallback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data)
Definition: poptI.c:60
#define RPMCLI_POPT_NOSIGNATURE
Definition: rpmcli.h:99
char * t
Definition: rpmds.c:2716
enum rpmInstallInterfaceFlags_e rpmInstallInterfaceFlags
Bit(s) to control rpmcliInstall() and rpmErase() operation.
#define POPT_ROLLBACK_EXCLUDE
Definition: poptI.c:35
#define RPMCLI_POPT_NODEPS
Common/global popt tokens used for command line option tables.
Definition: rpmcli.h:96
enum rpmtransFlags_e rpmtransFlags
Bit(s) to control rpmtsRun() operation.
struct rpmQVKArguments_s rpmIArgs
Definition: poptI.c:23
te
Definition: macro.c:552
enum rpmQueryFlags_e rpmQueryFlags
Bit(s) to control rpmQuery() operation, stored in qva_flags.
return NULL
Definition: poptALL.c:613
#define _(Text)
Definition: system.h:29
poptContext
Definition: poptALL.c:525
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:647
#define xrealloc
Definition: system.h:35
static void argerror(const char *desc) __attribute__((__noreturn__))
Print a message and exit.
Definition: poptI.c:48