rpm  4.5
poptI.c
Go to the documentation of this file.
1 
6 #include "system.h"
7 
8 #include <rpmcli.h>
9 
10 #include "debug.h"
11 
12 /*@-redecl@*/
13 extern time_t get_date(const char * p, void * now); /* XXX expedient lies */
14 /*@=redecl@*/
15 
16 /*@-fullinitblock@*/
17 /*@unchecked@*/
19  .probFilter = 0,
20 };
21 /*@=fullinitblock@*/
22 
23 #define POPT_RELOCATE -1021
24 #define POPT_EXCLUDEPATH -1022
25 #define POPT_ROLLBACK -1023
26 #define POPT_ROLLBACK_EXCLUDE -1024
27 /* -1025 thrugh -1033 are common in rpmcli.h. */
28 #define POPT_AUTOROLLBACK_GOAL -1036
29 
30 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
31 
37 /*@exits@*/
38 static void argerror(const char * desc)
39  /*@globals stderr, fileSystem @*/
40  /*@modifies stderr, fileSystem @*/
41 {
42  /*@-modfilesys -globs @*/
43  fprintf(stderr, _("%s: %s\n"), __progname, desc);
44  /*@=modfilesys =globs @*/
45  exit(EXIT_FAILURE);
46 }
47 
50 /*@-bounds@*/
51 static void installArgCallback( /*@unused@*/ poptContext con,
52  /*@unused@*/ enum poptCallbackReason reason,
53  const struct poptOption * opt, const char * arg,
54  /*@unused@*/ const void * data)
55  /*@globals rpmIArgs, stderr, fileSystem @*/
56  /*@modifies rpmIArgs, stderr, fileSystem @*/
57 {
58  QVA_t ia = &rpmIArgs;
59 
60  /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
61  /*@-branchstate@*/
62  if (opt->arg == NULL)
63  switch (opt->val) {
64 
65  case 'i':
67  break;
68 
69  case POPT_EXCLUDEPATH:
70  if (arg == NULL || *arg != '/')
71  argerror(_("exclude paths must begin with a /"));
72  ia->relocations = xrealloc(ia->relocations,
73  sizeof(*ia->relocations) * (ia->numRelocations + 1));
74 /*@-temptrans@*/
75  ia->relocations[ia->numRelocations].oldPath = xstrdup(arg);
76 /*@=temptrans@*/
77  ia->relocations[ia->numRelocations].newPath = NULL;
78  ia->numRelocations++;
79  break;
80  case POPT_RELOCATE:
81  { char * oldPath = NULL;
82  char * newPath = NULL;
83 
84  if (arg == NULL)
85  argerror(_("Option --relocate needs /old/path=/new/path argument"));
86  if (*arg != '/')
87  argerror(_("relocations must begin with a /"));
88  oldPath = xstrdup(arg);
89  if (!(newPath = strchr(oldPath, '=')))
90  argerror(_("relocations must contain a ="));
91  *newPath++ = '\0';
92  if (*newPath != '/')
93  argerror(_("relocations must have a / following the ="));
94  ia->relocations = xrealloc(ia->relocations,
95  sizeof(*ia->relocations) * (ia->numRelocations + 1));
96 /*@-temptrans@*/
97  ia->relocations[ia->numRelocations].oldPath = oldPath;
98 /*@=temptrans@*/
99 /*@-kepttrans -usereleased @*/
100  ia->relocations[ia->numRelocations].newPath = newPath;
101 /*@=kepttrans =usereleased @*/
102  ia->numRelocations++;
103  } break;
104 
106  { int_32 tid;
107  char *t, *te;
108 
109  /* Make sure we were given the proper number of args */
110  if (arg == NULL)
111  argerror(_("Option --rbexclude needs transaction id argument(s)"));
112 
113  te = alloca_strdup(arg);
114  while (*te != '\0' && strchr(" \t\n,", *te) != NULL)
115  *te++ = '\0';
116  while ((t = te++) != NULL && *t != '\0') {
117  /* Find next tid. */
118  while (*te != '\0' && strchr(" \t\n,", *te) == NULL)
119  te++;
120  while (*te != '\0' && strchr(" \t\n,", *te) != NULL)
121  *te++ = '\0';
122 
123  /* Convert arg to TID which happens to be time_t */
124  /* XXX: Need check for arg to be an integer */
125  tid = (int_32) strtol(t, NULL, 0);
126 
127  /* Allocate space for new exclude tid */
129  sizeof(*ia->rbtidExcludes) * (ia->numrbtidExcludes + 1));
130 
131  /* Add it to the list and iterate count*/
132 /*@-temptrans@*/
133  ia->rbtidExcludes[ia->numrbtidExcludes] = tid;
134 /*@=temptrans@*/
135  ia->numrbtidExcludes++;
136  }
137  } break;
138 
139  case POPT_ROLLBACK:
140  { time_t tid;
141  if (arg == NULL)
142  argerror(_("Option --rollback needs a time/date stamp argument"));
143 
144  /*@-moduncon@*/
145  tid = get_date(arg, NULL);
146  rpmMessage(RPMMESS_VERBOSE, _("Rollback goal: %-24.24s (0x%08x)\n"), ctime(&tid), (int)tid);
147  /*@=moduncon@*/
148 
149  if (tid == (time_t)-1 || tid == (time_t)0)
150  argerror(_("malformed rollback time/date stamp argument"));
151  ia->rbtid = tid;
152  } break;
153 
155  { time_t tid;
156  if (arg == NULL)
157  argerror(_("arbgoal takes a time/date stamp argument"));
158 
159  /*@-moduncon@*/
160  tid = get_date(arg, NULL);
161  /*@=moduncon@*/
162 
163  if (tid == (time_t)-1 || tid == (time_t)0)
164  argerror(_("malformed arbgoal time/date stamp argument"));
165  ia->arbtid = tid;
166  } break;
167 
169  ia->qva_flags |= VERIFY_DIGEST;
170  break;
171 
174  break;
175 
177  ia->qva_flags |= VERIFY_HDRCHK;
178  break;
179 
180  case RPMCLI_POPT_NODEPS:
181  ia->noDeps = 1;
182  break;
183 
186  break;
187 
190  break;
191 
192  case RPMCLI_POPT_FORCE:
193  ia->probFilter |=
198  break;
199 
202  break;
203 
204  }
205  /*@=branchstate@*/
206 }
207 /*@=bounds@*/
208 
211 /*@-bitwisesigned -compmempass @*/
212 /*@unchecked@*/
213 struct poptOption rpmInstallPoptTable[] = {
214 /*@-type@*/ /* FIX: cast? */
215  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
216  installArgCallback, 0, NULL, NULL },
217 /*@=type@*/
218 
219  { "allfiles", '\0', POPT_BIT_SET,
221  N_("install all files, even configurations which might otherwise be skipped"),
222  NULL},
223  { "allmatches", '\0', POPT_BIT_SET,
225  N_("remove all packages which match <package> (normally an error is generated if <package> specified multiple packages)"),
226  NULL},
227 
228  { "apply", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
231  N_("do not execute package scriptlet(s)"), NULL },
232 
233  { "badreloc", '\0', POPT_BIT_SET,
235  N_("relocate files in non-relocatable package"), NULL},
236 
237  { "dirstash", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
239  N_("save erased package files by renaming into sub-directory"), NULL},
240  { "erase", 'e', POPT_BIT_SET,
242  N_("erase (uninstall) package"), N_("<package>+") },
243  { "excludeconfigs", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
245  N_("do not install configuration files"), NULL},
246  { "excludedocs", '\0', POPT_BIT_SET,
247  &rpmIArgs.transFlags, RPMTRANS_FLAG_NODOCS,
248  N_("do not install documentation"), NULL},
249  { "excludepath", '\0', POPT_ARG_STRING, 0, POPT_EXCLUDEPATH,
250  N_("skip files with leading component <path> "),
251  N_("<path>") },
252 
253  { "force", '\0', 0, NULL, RPMCLI_POPT_FORCE,
254  N_("short hand for --replacepkgs --replacefiles"), NULL},
255 
256  { "freshen", 'F', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags,
258  N_("upgrade package(s) if already installed"),
259  N_("<packagefile>+") },
260  { "hash", 'h', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags, INSTALL_HASH,
261  N_("print hash marks as package installs (good with -v)"), NULL},
262 #ifndef DIEDIEDIE
263  { "ignorearch", '\0', POPT_BIT_SET,
265  N_("don't verify package architecture"), NULL},
266  { "ignoreos", '\0', POPT_BIT_SET,
268  N_("don't verify package operating system"), NULL},
269 #endif
270  { "ignoresize", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
272  N_("don't check disk space before installing"), NULL},
273  { "includedocs", '\0', POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.incldocs, 0,
274  N_("install documentation"), NULL},
275 
276  { "install", 'i', 0, NULL, 'i',
277  N_("install package(s)"), N_("<packagefile>+") },
278 
279  { "justdb", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_JUSTDB,
280  N_("update the database, but do not modify the filesystem"), NULL},
281 
282  { "noconfigs", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
284  N_("do not install configuration files"), NULL},
285  { "nodeps", '\0', 0, NULL, RPMCLI_POPT_NODEPS,
286  N_("do not verify package dependencies"), NULL },
287  { "nodocs", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
288  &rpmIArgs.transFlags, RPMTRANS_FLAG_NODOCS,
289  N_("do not install documentation"), NULL},
290 
291  { "nomd5", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NOFDIGESTS,
292  N_("don't verify file digests"), NULL },
293  { "nofdigests", '\0', 0, NULL, RPMCLI_POPT_NOFDIGESTS,
294  N_("don't verify file digests"), NULL },
295  { "nocontexts", '\0',0, NULL, RPMCLI_POPT_NOCONTEXTS,
296  N_("don't install file security contexts"), NULL},
297 
298  { "noorder", '\0', POPT_BIT_SET,
300  N_("do not reorder package installation to satisfy dependencies"),
301  NULL},
302 
303  { "noscripts", '\0', 0, NULL, RPMCLI_POPT_NOSCRIPTS,
304  N_("do not execute package scriptlet(s)"), NULL },
305 
306  { "nopre", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
308  N_("do not execute %%pre scriptlet (if any)"), NULL },
309  { "nopost", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
311  N_("do not execute %%post scriptlet (if any)"), NULL },
312  { "nopreun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
314  N_("do not execute %%preun scriptlet (if any)"), NULL },
315  { "nopostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
317  N_("do not execute %%postun scriptlet (if any)"), NULL },
318 
319  { "nodigest", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NODIGEST,
320  N_("don't verify package digest(s)"), NULL },
321  { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOHDRCHK,
322  N_("don't verify database header(s) when retrieved"), NULL },
323  { "nosignature", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOSIGNATURE,
324  N_("don't verify package signature(s)"), NULL },
325 
326  { "notriggers", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, _noTransTriggers,
327  N_("do not execute any scriptlet(s) triggered by this package"), NULL},
328  { "notriggerprein", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
330  N_("do not execute any %%triggerprein scriptlet(s)"), NULL},
331  { "notriggerin", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
333  N_("do not execute any %%triggerin scriptlet(s)"), NULL},
334  { "notriggerun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
336  N_("do not execute any %%triggerun scriptlet(s)"), NULL},
337  { "notriggerpostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
339  N_("do not execute any %%triggerpostun scriptlet(s)"), NULL},
340 
341  { "oldpackage", '\0', POPT_BIT_SET,
343  N_("upgrade to an old version of the package (--force on upgrades does this automatically)"),
344  NULL},
345  { "percent", '\0', POPT_BIT_SET,
347  N_("print percentages as package installs"), NULL},
348  { "prefix", '\0', POPT_ARG_STRING, &rpmIArgs.qva_prefix, 0,
349  N_("relocate the package to <dir>, if relocatable"),
350  N_("<dir>") },
351  { "relocate", '\0', POPT_ARG_STRING, 0, POPT_RELOCATE,
352  N_("relocate files from path <old> to <new>"),
353  N_("<old>=<new>") },
354  { "repackage", '\0', POPT_BIT_SET,
356  N_("save erased package files by repackaging"), NULL},
357  { "replacefiles", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
359  N_("ignore file conflicts between packages"), NULL},
360  { "replacepkgs", '\0', POPT_BIT_SET,
362  N_("reinstall if the package is already present"), NULL},
363  { "rollback", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_ROLLBACK,
364  N_("deinstall new, reinstall old, package(s), back to <date>"),
365  N_("<date>") },
366  { "arbgoal", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_AUTOROLLBACK_GOAL,
367  N_("If transaction fails rollback to <date>"),
368  N_("<date>") },
369  { "rbexclude", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_ROLLBACK_EXCLUDE,
370  N_("Exclude Transaction I.D. from rollback"),
371  N_("<tid>") },
372  { "test", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_TEST,
373  N_("don't install, but tell if it would work or not"), NULL},
374  { "upgrade", 'U', POPT_BIT_SET,
376  N_("upgrade package(s)"),
377  N_("<packagefile>+") },
378 
379  POPT_TABLEEND
380 };
381 /*@=bitwisesigned =compmempass @*/