configure.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. * dpkg - main program for package management
  3. * configure.c - configure packages
  4. *
  5. * Copyright 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright 1999,2002 Wichert Akkerman <wichert@deephackmode.org>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2,
  11. * or (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with dpkg; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <config.h>
  23. #include <errno.h>
  24. #include <signal.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <stdlib.h>
  28. #include <unistd.h>
  29. #include <fcntl.h>
  30. #include <sys/stat.h>
  31. #include <sys/types.h>
  32. #include <dirent.h>
  33. #include <ctype.h>
  34. #include <unistd.h>
  35. #include <string.h>
  36. #include <assert.h>
  37. #include <sys/wait.h>
  38. #include <time.h>
  39. #include <sys/termios.h>
  40. #include <dpkg.h>
  41. #include <dpkg-db.h>
  42. #include "filesdb.h"
  43. #include "main.h"
  44. int conffoptcells[2][2]= { CONFFOPTCELLS };
  45. static void md5hash(struct pkginfo *pkg, char **hashbuf, const char *fn);
  46. static void copyfileperm(const char* source, const char* target);
  47. static void showdiff(const char* old, const char* new);
  48. static void suspend(void);
  49. static enum conffopt promptconfaction(const char* cfgfile, const char* realold,
  50. const char* realnew, int useredited, int distedited,
  51. enum conffopt what);
  52. extern struct pipef *status_pipes;
  53. void deferred_configure(struct pkginfo *pkg) {
  54. /* The algorithm for deciding what to configure first is as follows:
  55. * Loop through all packages doing a `try 1' until we've been round
  56. * and nothing has been done, then do `try 2' and `try 3' likewise.
  57. * The incrementing of `dependtry' is done by process_queue().
  58. * Try 1:
  59. * Are all dependencies of this package done ? If so, do it.
  60. * Are any of the dependencies missing or the wrong version ?
  61. * If so, abort (unless --force-depends, in which case defer)
  62. * Will we need to configure a package we weren't given as an
  63. * argument ? If so, abort - except if --force-configure-any,
  64. * in which case we add the package to the argument list.
  65. * If none of the above, defer the package.
  66. * Try 2:
  67. * Find a cycle and break it (see above).
  68. * Do as for try 1.
  69. * Try 3 (only if --force-depends-version).
  70. * Same as for try 2, but don't mind version number in dependencies.
  71. * Try 4 (only if --force-depends).
  72. * Do anyway.
  73. */
  74. struct varbuf aemsgs, cdr, cdr2;
  75. char *cdr2rest;
  76. int ok, r, useredited, distedited;
  77. struct conffile *conff;
  78. char *currenthash= 0, *newdisthash= 0;
  79. struct stat stab;
  80. enum conffopt what;
  81. static const char *EMPTY_HASH = "-";
  82. if (pkg->status == stat_notinstalled)
  83. ohshit(_("no package named `%s' is installed, cannot configure"),pkg->name);
  84. if (pkg->status == stat_installed)
  85. ohshit(_("package %.250s is already installed and configured"), pkg->name);
  86. if (pkg->status != stat_unpacked && pkg->status != stat_halfconfigured)
  87. ohshit(_("package %.250s is not ready for configuration\n"
  88. " cannot configure (current status `%.250s')"),
  89. pkg->name, statusinfos[pkg->status].name);
  90. if (dependtry > 1)
  91. if (findbreakcycle(pkg))
  92. sincenothing= 0;
  93. varbufinit(&aemsgs);
  94. ok= dependencies_ok(pkg,0,&aemsgs);
  95. if (ok == 1) {
  96. varbuffree(&aemsgs);
  97. pkg->clientdata->istobe= itb_installnew;
  98. add_to_queue(pkg);
  99. return;
  100. }
  101. ok = breakses_ok(pkg, &aemsgs) ? ok : 0;
  102. if (ok == 0) {
  103. sincenothing= 0;
  104. varbufaddc(&aemsgs,0);
  105. fprintf(stderr,
  106. _("dpkg: dependency problems prevent configuration of %s:\n%s"),
  107. pkg->name, aemsgs.buf);
  108. varbuffree(&aemsgs);
  109. ohshit(_("dependency problems - leaving unconfigured"));
  110. } else if (aemsgs.used) {
  111. varbufaddc(&aemsgs,0);
  112. fprintf(stderr,
  113. _("dpkg: %s: dependency problems, but configuring anyway as you request:\n%s"),
  114. pkg->name, aemsgs.buf);
  115. }
  116. varbuffree(&aemsgs);
  117. sincenothing= 0;
  118. if (pkg->eflag & eflagf_reinstreq)
  119. forcibleerr(fc_removereinstreq,
  120. _("Package is in a very bad inconsistent state - you should\n"
  121. " reinstall it before attempting configuration."));
  122. printf(_("Setting up %s (%s) ...\n"),pkg->name,
  123. versiondescribe(&pkg->installed.version, vdew_nonambig));
  124. if (f_noact) {
  125. pkg->status= stat_installed;
  126. pkg->clientdata->istobe= itb_normal;
  127. return;
  128. }
  129. if (pkg->status == stat_unpacked) {
  130. debug(dbg_general,"deferred_configure updating conffiles");
  131. /* This will not do at all the right thing with overridden conffiles
  132. * or conffiles that are the `target' of an override; all the references
  133. * here would be to the `contested' filename, and in any case there'd
  134. * only be one hash for both `versions' of the conffile.
  135. *
  136. * Overriding conffiles is a silly thing to do anyway :-).
  137. */
  138. modstatdb_note(pkg);
  139. /* On entry, the `new' version of each conffile has been
  140. * unpacked as *.dpkg-new, and the `installed' version is
  141. * as-yet untouched in `*'. The hash of the `old distributed'
  142. * version is in the conffiles data for the package.
  143. * If `*.dpkg-new' no longer exists we assume that we've already
  144. * processed this one.
  145. */
  146. varbufinit(&cdr);
  147. varbufinit(&cdr2);
  148. for (conff= pkg->installed.conffiles; conff; conff= conff->next) {
  149. r= conffderef(pkg, &cdr, conff->name);
  150. if (r == -1) {
  151. conff->hash= EMPTY_HASH;
  152. continue;
  153. }
  154. md5hash(pkg,&currenthash,cdr.buf);
  155. varbufreset(&cdr2);
  156. varbufaddstr(&cdr2,cdr.buf);
  157. cdr2.used+=50; varbufaddc(&cdr2,0); cdr2rest= cdr2.buf+strlen(cdr.buf);
  158. /* From now on we can just strcpy(cdr2rest,extension); */
  159. strcpy(cdr2rest,DPKGNEWEXT);
  160. /* If the .dpkg-new file is no longer there, ignore this one. */
  161. if (lstat(cdr2.buf,&stab)) {
  162. if (errno == ENOENT) continue;
  163. ohshite(_("unable to stat new dist conffile `%.250s'"),cdr2.buf);
  164. }
  165. md5hash(pkg,&newdisthash,cdr2.buf);
  166. /* Copy the permissions from the installed version to the new
  167. * distributed version.
  168. */
  169. if (!stat(cdr.buf,&stab))
  170. copyfileperm(cdr.buf, cdr2.buf);
  171. else if (errno != ENOENT)
  172. ohshite(_("unable to stat current installed conffile `%.250s'"),cdr.buf);
  173. /* Select what the do */
  174. if (!strcmp(currenthash,newdisthash)) {
  175. /* They're both the same so there's no point asking silly questions. */
  176. useredited= -1;
  177. distedited= -1;
  178. what= cfo_identical;
  179. } else if (!strcmp(currenthash,NONEXISTENTFLAG) && fc_conff_miss) {
  180. fprintf(stderr, _("\nConfiguration file `%s', does not exist on system.\n"
  181. "Installing new config file as you request.\n"), conff->name);
  182. what= cfo_newconff;
  183. useredited= -1;
  184. distedited= -1;
  185. } else if (!strcmp(conff->hash,NEWCONFFILEFLAG)) {
  186. if (!strcmp(currenthash,NONEXISTENTFLAG)) {
  187. what= cfo_newconff;
  188. useredited= -1;
  189. distedited= -1;
  190. } else {
  191. useredited= 1;
  192. distedited= 1;
  193. what= conffoptcells[useredited][distedited] | cfof_isnew;
  194. }
  195. } else {
  196. useredited= strcmp(conff->hash,currenthash) != 0;
  197. distedited= strcmp(conff->hash,newdisthash) != 0;
  198. what= conffoptcells[useredited][distedited];
  199. if (!strcmp(currenthash,NONEXISTENTFLAG))
  200. what |= cfof_userrmd;
  201. }
  202. debug(dbg_conff,
  203. "deferred_configure `%s' (= `%s') useredited=%d distedited=%d what=%o",
  204. conff->name, cdr.buf, useredited, distedited, what);
  205. what=promptconfaction(conff->name, cdr.buf, cdr2.buf, useredited, distedited, what);
  206. switch (what & ~(cfof_isnew|cfof_userrmd)) {
  207. case cfo_keep | cfof_backup:
  208. strcpy(cdr2rest,DPKGOLDEXT);
  209. if (unlink(cdr2.buf) && errno != ENOENT)
  210. fprintf(stderr,
  211. _("dpkg: %s: warning - failed to remove old backup `%.250s': %s\n"),
  212. pkg->name, cdr2.buf, strerror(errno));
  213. cdr.used--;
  214. varbufaddstr(&cdr,DPKGDISTEXT);
  215. varbufaddc(&cdr,0);
  216. strcpy(cdr2rest,DPKGNEWEXT);
  217. if (rename(cdr2.buf,cdr.buf))
  218. fprintf(stderr,
  219. _("dpkg: %s: warning - failed to rename `%.250s' to `%.250s': %s\n"),
  220. pkg->name, cdr2.buf, cdr.buf, strerror(errno));
  221. break;
  222. case cfo_keep:
  223. strcpy(cdr2rest,DPKGNEWEXT);
  224. if (unlink(cdr2.buf))
  225. fprintf(stderr,
  226. _("dpkg: %s: warning - failed to remove `%.250s': %s\n"),
  227. pkg->name, cdr2.buf, strerror(errno));
  228. break;
  229. case cfo_install | cfof_backup:
  230. strcpy(cdr2rest,DPKGDISTEXT);
  231. if (unlink(cdr2.buf) && errno != ENOENT)
  232. fprintf(stderr,
  233. _("dpkg: %s: warning - failed to remove old distrib version `%.250s': %s\n"),
  234. pkg->name, cdr2.buf, strerror(errno));
  235. strcpy(cdr2rest,DPKGOLDEXT);
  236. if (unlink(cdr2.buf) && errno != ENOENT)
  237. fprintf(stderr,
  238. _("dpkg: %s: warning - failed to remove `%.250s' (before overwrite): %s\n"),
  239. pkg->name, cdr2.buf, strerror(errno));
  240. if (!(what & cfof_userrmd))
  241. if (link(cdr.buf,cdr2.buf))
  242. fprintf(stderr,
  243. _("dpkg: %s: warning - failed to link `%.250s' to `%.250s': %s\n"),
  244. pkg->name, cdr.buf, cdr2.buf, strerror(errno));
  245. /* fall through */
  246. case cfo_install:
  247. printf(_("Installing new version of config file %s ...\n"),conff->name);
  248. case cfo_newconff:
  249. strcpy(cdr2rest,DPKGNEWEXT);
  250. if (rename(cdr2.buf,cdr.buf))
  251. ohshite(_("unable to install `%.250s' as `%.250s'"),cdr2.buf,cdr.buf);
  252. break;
  253. default:
  254. internerr("unknown what");
  255. }
  256. conff->hash= nfstrsave(newdisthash);
  257. modstatdb_note(pkg);
  258. free(newdisthash);
  259. free(currenthash);
  260. } /* for (conff= ... */
  261. varbuffree(&cdr);
  262. varbuffree(&cdr2);
  263. pkg->status= stat_halfconfigured;
  264. }
  265. assert(pkg->status == stat_halfconfigured);
  266. modstatdb_note(pkg);
  267. maintainer_script_installed(pkg, POSTINSTFILE, "post-installation",
  268. "configure",
  269. informativeversion(&pkg->configversion) ?
  270. versiondescribe(&pkg->configversion,
  271. vdew_nonambig) : "",
  272. NULL);
  273. pkg->status= stat_installed;
  274. pkg->eflag= eflagv_ok;
  275. modstatdb_note(pkg);
  276. }
  277. /* Dereference a file by following all possibly used symlinks.
  278. * Returns 0 if everything went ok, -1 otherwise.
  279. */
  280. int conffderef(struct pkginfo *pkg, struct varbuf *result, const char *in) {
  281. static char* linkreadbuf = 0;
  282. static int linkreadbufsize = 0;
  283. struct stat stab;
  284. int r, need;
  285. int loopprotect;
  286. varbufreset(result);
  287. varbufaddstr(result,instdir);
  288. if (*in != '/') varbufaddc(result,'/');
  289. varbufaddstr(result,in);
  290. varbufaddc(result,0);
  291. loopprotect= 0;
  292. for (;;) {
  293. debug(dbg_conffdetail,"conffderef in=`%s' current working=`%s'", in, result->buf);
  294. if (lstat(result->buf,&stab)) {
  295. if (errno != ENOENT)
  296. fprintf(stderr, _("dpkg: %s: warning - unable to stat config file `%s'\n"
  297. " (= `%s'): %s\n"),
  298. pkg->name, in, result->buf, strerror(errno));
  299. debug(dbg_conffdetail,"conffderef nonexistent");
  300. return 0;
  301. } else if (S_ISREG(stab.st_mode)) {
  302. debug(dbg_conff,"conffderef in=`%s' result=`%s'", in, result->buf);
  303. return 0;
  304. } else if (S_ISLNK(stab.st_mode)) {
  305. debug(dbg_conffdetail,"conffderef symlink loopprotect=%d",loopprotect);
  306. if (loopprotect++ >= 25) {
  307. fprintf(stderr, _("dpkg: %s: warning - config file `%s' is a circular link\n"
  308. " (= `%s')\n"), pkg->name, in, result->buf);
  309. return -1;
  310. }
  311. need= 255;
  312. for (;;) {
  313. if (need > linkreadbufsize) {
  314. linkreadbuf= m_realloc(linkreadbuf,need);
  315. linkreadbufsize= need;
  316. debug(dbg_conffdetail,"conffderef readlink realloc(%d)=%p",need,linkreadbuf);
  317. }
  318. r= readlink(result->buf,linkreadbuf,linkreadbufsize-1);
  319. if (r < 0) {
  320. fprintf(stderr, _("dpkg: %s: warning - unable to readlink conffile `%s'\n"
  321. " (= `%s'): %s\n"),
  322. pkg->name, in, result->buf, strerror(errno));
  323. return -1;
  324. }
  325. debug(dbg_conffdetail,"conffderef readlink gave %d, `%.*s'",
  326. r, r>0 ? r : 0, linkreadbuf);
  327. if (r < linkreadbufsize-1) break;
  328. need= r<<2;
  329. }
  330. linkreadbuf[r]= 0;
  331. if (linkreadbuf[0] == '/') {
  332. varbufreset(result);
  333. varbufaddstr(result,instdir);
  334. debug(dbg_conffdetail,"conffderef readlink absolute");
  335. } else {
  336. for (r=result->used-2; r>0 && result->buf[r] != '/'; r--)
  337. ;
  338. if (r < 0) {
  339. fprintf(stderr,
  340. _("dpkg: %s: warning - conffile `%.250s' resolves to degenerate filename\n"
  341. " (`%s' is a symlink to `%s')\n"),
  342. pkg->name, in, result->buf, linkreadbuf);
  343. return -1;
  344. }
  345. if (result->buf[r] == '/') r++;
  346. result->used= r;
  347. debug(dbg_conffdetail,"conffderef readlink relative to `%.*s'",
  348. (int)result->used, result->buf);
  349. }
  350. varbufaddstr(result,linkreadbuf);
  351. varbufaddc(result,0);
  352. } else {
  353. fprintf(stderr, _("dpkg: %s: warning - conffile `%.250s' is not a plain"
  354. " file or symlink (= `%s')\n"),
  355. pkg->name, in, result->buf);
  356. return -1;
  357. }
  358. }
  359. }
  360. /* Generate a MD5 hash for fn and store it in *hashbuf. Memory is allocated
  361. * by this function and should be freed manually.
  362. */
  363. static void md5hash(struct pkginfo *pkg, char **hashbuf, const char *fn) {
  364. static int fd;
  365. fd=open(fn,O_RDONLY);
  366. if (fd>=0) {
  367. push_cleanup(cu_closefd,ehflag_bombout, 0,0, 1,&fd);
  368. fd_md5(fd, hashbuf, -1, _("md5hash"));
  369. pop_cleanup(ehflag_normaltidy); /* fd= open(cdr.buf) */
  370. close(fd);
  371. } else if (errno==ENOENT) {
  372. *hashbuf= strdup(NONEXISTENTFLAG);
  373. } else {
  374. fprintf(stderr, _("dpkg: %s: warning - unable to open conffile %s for hash: %s\n"),
  375. pkg->name, fn, strerror(errno));
  376. *hashbuf= strdup("-");
  377. }
  378. }
  379. /* Copy file ownership and permissions from one file to another
  380. */
  381. static void copyfileperm(const char* source, const char* target) {
  382. struct stat stab;
  383. if (stat(source, &stab)==-1) {
  384. if (errno==ENOENT)
  385. return;
  386. ohshite(_("unable to stat current installed conffile `%.250s'"), source);
  387. }
  388. if (chown(target, stab.st_uid, stab.st_gid)==-1)
  389. ohshite(_("unable to change ownership of new dist conffile `%.250s'"), target);
  390. if (chmod(target, (stab.st_mode & 07777))==-1)
  391. ohshite(_("unable to set mode of new dist conffile `%.250s'"), target);
  392. }
  393. /* Show a diff between two files
  394. */
  395. static void showdiff(const char* old, const char* new) {
  396. int pid;
  397. int r;
  398. int status;
  399. if (!(pid=m_fork())) {
  400. /* Child process */
  401. const char* p; /* pager */
  402. const char* s; /* shell */
  403. char cmdbuf[1024]; /* command to run */
  404. p=getenv(PAGERENV);
  405. if (!p || !*p)
  406. p=DEFAULTPAGER;
  407. sprintf(cmdbuf, DIFF " -Nu %.250s %.250s | %.250s", old, new, p);
  408. s=getenv(SHELLENV);
  409. if (!s || !*s)
  410. s=DEFAULTSHELL;
  411. execlp(s,s,"-c", cmdbuf, NULL);
  412. ohshite(_("failed to run %s (%.250s)"), DIFF, cmdbuf);
  413. }
  414. /* Parent process */
  415. while (((r=waitpid(pid,&status,0))==-1) && (errno==EINTR))
  416. ;
  417. if (r!=pid) {
  418. onerr_abort++;
  419. ohshite(_("wait for shell failed"));
  420. }
  421. }
  422. /* Suspend dpkg temporarily
  423. */
  424. static void suspend(void) {
  425. const char* s;
  426. int pid;
  427. s= getenv(NOJOBCTRLSTOPENV);
  428. if (s && *s) {
  429. /* Do not job control to suspend but fork and start a new shell
  430. * instead.
  431. */
  432. int status; /* waitpid status */
  433. int r; /* waitpid result */
  434. fputs(_("Type `exit' when you're done.\n"), stderr);
  435. if (!(pid= m_fork())) {
  436. /* Child process */
  437. s= getenv(SHELLENV);
  438. if (!s || !*s)
  439. s=DEFAULTSHELL;
  440. execlp(s, s, "-i", NULL);
  441. ohshite(_("failed to exec shell (%.250s)"),s);
  442. }
  443. /* Parent process */
  444. while (((r=waitpid(pid,&status,0))==-1) && (errno==EINTR))
  445. ;
  446. if (r!=pid) {
  447. onerr_abort++;
  448. ohshite(_("wait for shell failed"));
  449. }
  450. } else {
  451. fputs(_("Don't forget to foreground (`fg') this "
  452. "process when you're done !\n"), stderr);
  453. kill(-getpgid(0),SIGTSTP);
  454. }
  455. }
  456. /* Select what to do with a configuration file.
  457. */
  458. static enum conffopt promptconfaction(const char* cfgfile, const char* realold,
  459. const char* realnew, int useredited, int distedited,
  460. enum conffopt what) {
  461. const char *s;
  462. int c, cc;
  463. if (!(what&cfof_prompt))
  464. return what;
  465. /* if there is a status pipe, send conffile-prompt there */
  466. if (status_pipes) {
  467. static struct varbuf *status= NULL;
  468. struct pipef *pipef= status_pipes;
  469. int r;
  470. if (status == NULL) {
  471. status = nfmalloc(sizeof(struct varbuf));
  472. varbufinit(status);
  473. } else
  474. varbufreset(status);
  475. r= varbufprintf(status, "status: %s : %s : '%s' '%s' %i %i \n",
  476. cfgfile, "conffile-prompt",
  477. realold, realnew, useredited, distedited);
  478. while (pipef) {
  479. write(pipef->fd, status->buf, r);
  480. pipef= pipef->next;
  481. }
  482. }
  483. do {
  484. /* Flush the terminal's input in case the user
  485. * involuntarily typed some characters.
  486. */
  487. tcflush(STDIN_FILENO, TCIFLUSH);
  488. fprintf(stderr, _("\nConfiguration file `%s'"), cfgfile);
  489. if (strcmp(cfgfile, realold))
  490. fprintf(stderr,_(" (actually `%s')"), realold);
  491. if (what & cfof_isnew) {
  492. fprintf(stderr,
  493. _("\n"
  494. " ==> File on system created by you or by a script.\n"
  495. " ==> File also in package provided by package maintainer.\n"));
  496. } else {
  497. fprintf(stderr, !useredited ?
  498. _("\n Not modified since installation.\n") :
  499. !(what & cfof_userrmd) ?
  500. _("\n ==> Modified (by you or by a script) since installation.\n") :
  501. _("\n ==> Deleted (by you or by a script) since installation.\n"));
  502. fprintf(stderr, distedited ?
  503. _(" ==> Package distributor has shipped an updated version.\n") :
  504. _(" Version in package is the same as at last installation.\n"));
  505. }
  506. /* No --force-confdef but a forcible situtation */
  507. /* TODO: check if this condition can not be simplified to just !fc_conff_def */
  508. if (!(fc_conff_def && (what&(cfof_install|cfof_keep)))) {
  509. if (fc_conff_new) {
  510. fprintf(stderr, _(" ==> Using new file as you requested.\n"));
  511. cc = 'y';
  512. break;
  513. } else if (fc_conff_old) {
  514. fprintf(stderr, _(" ==> Using current old file as you requested.\n"));
  515. cc = 'n';
  516. break;
  517. }
  518. }
  519. /* Force the default action (if there is one */
  520. if (fc_conff_def) {
  521. if (what&cfof_keep) {
  522. fprintf(stderr, _(" ==> Keeping old config file as default.\n"));
  523. cc = 'n';
  524. break;
  525. } else if (what&cfof_install) {
  526. fprintf(stderr, _(" ==> Using new config file as default.\n"));
  527. cc = 'y';
  528. break;
  529. }
  530. }
  531. fprintf(stderr,
  532. _(" What would you like to do about it ? Your options are:\n"
  533. " Y or I : install the package maintainer's version\n"
  534. " N or O : keep your currently-installed version\n"
  535. " D : show the differences between the versions\n"
  536. " Z : background this process to examine the situation\n"));
  537. if (what & cfof_keep)
  538. fprintf(stderr, _(" The default action is to keep your current version.\n"));
  539. else if (what & cfof_install)
  540. fprintf(stderr, _(" The default action is to install the new version.\n"));
  541. s= strrchr(cfgfile,'/');
  542. if (!s || !*++s) s= cfgfile;
  543. fprintf(stderr, "*** %s (Y/I/N/O/D/Z) %s ? ",
  544. s,
  545. (what & cfof_keep) ? _("[default=N]") :
  546. (what & cfof_install) ? _("[default=Y]") : _("[no default]"));
  547. if (ferror(stderr))
  548. ohshite(_("error writing to stderr, discovered before conffile prompt"));
  549. cc= 0;
  550. while ((c= getchar()) != EOF && c != '\n')
  551. if (!isspace(c) && !cc) cc= tolower(c);
  552. if (c == EOF) {
  553. if (ferror(stdin)) ohshite(_("read error on stdin at conffile prompt"));
  554. ohshit(_("EOF on stdin at conffile prompt"));
  555. }
  556. if (!cc) {
  557. if (what & cfof_keep) { cc= 'n'; break; }
  558. else if (what & cfof_install) { cc= 'y'; break; }
  559. }
  560. /* fixme: say something if silently not install */
  561. if (cc == 'd')
  562. showdiff(realold, realnew);
  563. if (cc == 'z')
  564. suspend();
  565. } while (!strchr("yino",cc));
  566. log_message("conffile %s %s", cfgfile,
  567. (cc == 'i' || cc == 'y') ? "install" : "keep");
  568. what &= cfof_userrmd;
  569. switch (cc) {
  570. case 'i':
  571. case 'y':
  572. what |= cfof_install|cfof_backup;
  573. break;
  574. case 'n':
  575. case 'o':
  576. what |= cfof_keep|cfof_backup;
  577. break;
  578. default:
  579. internerr("unknown response");
  580. }
  581. return what;
  582. }