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. } else if (ok == 0) {
  101. sincenothing= 0;
  102. varbufaddc(&aemsgs,0);
  103. fprintf(stderr,
  104. _("dpkg: dependency problems prevent configuration of %s:\n%s"),
  105. pkg->name, aemsgs.buf);
  106. varbuffree(&aemsgs);
  107. ohshit(_("dependency problems - leaving unconfigured"));
  108. } else if (aemsgs.used) {
  109. varbufaddc(&aemsgs,0);
  110. fprintf(stderr,
  111. _("dpkg: %s: dependency problems, but configuring anyway as you request:\n%s"),
  112. pkg->name, aemsgs.buf);
  113. }
  114. varbuffree(&aemsgs);
  115. sincenothing= 0;
  116. if (pkg->eflag & eflagf_reinstreq)
  117. forcibleerr(fc_removereinstreq,
  118. _("Package is in a very bad inconsistent state - you should\n"
  119. " reinstall it before attempting configuration."));
  120. printf(_("Setting up %s (%s) ...\n"),pkg->name,
  121. versiondescribe(&pkg->installed.version, vdew_nonambig));
  122. if (f_noact) {
  123. pkg->status= stat_installed;
  124. pkg->clientdata->istobe= itb_normal;
  125. return;
  126. }
  127. if (pkg->status == stat_unpacked) {
  128. debug(dbg_general,"deferred_configure updating conffiles");
  129. /* This will not do at all the right thing with overridden conffiles
  130. * or conffiles that are the `target' of an override; all the references
  131. * here would be to the `contested' filename, and in any case there'd
  132. * only be one hash for both `versions' of the conffile.
  133. *
  134. * Overriding conffiles is a silly thing to do anyway :-).
  135. */
  136. modstatdb_note(pkg);
  137. /* On entry, the `new' version of each conffile has been
  138. * unpacked as *.dpkg-new, and the `installed' version is
  139. * as-yet untouched in `*'. The hash of the `old distributed'
  140. * version is in the conffiles data for the package.
  141. * If `*.dpkg-new' no longer exists we assume that we've already
  142. * processed this one.
  143. */
  144. varbufinit(&cdr);
  145. varbufinit(&cdr2);
  146. for (conff= pkg->installed.conffiles; conff; conff= conff->next) {
  147. r= conffderef(pkg, &cdr, conff->name);
  148. if (r == -1) {
  149. conff->hash= EMPTY_HASH;
  150. continue;
  151. }
  152. md5hash(pkg,&currenthash,cdr.buf);
  153. varbufreset(&cdr2);
  154. varbufaddstr(&cdr2,cdr.buf);
  155. cdr2.used+=50; varbufaddc(&cdr2,0); cdr2rest= cdr2.buf+strlen(cdr.buf);
  156. /* From now on we can just strcpy(cdr2rest,extension); */
  157. strcpy(cdr2rest,DPKGNEWEXT);
  158. /* If the .dpkg-new file is no longer there, ignore this one. */
  159. if (lstat(cdr2.buf,&stab)) {
  160. if (errno == ENOENT) continue;
  161. ohshite(_("unable to stat new dist conffile `%.250s'"),cdr2.buf);
  162. }
  163. md5hash(pkg,&newdisthash,cdr2.buf);
  164. /* Copy the permissions from the installed version to the new
  165. * distributed version.
  166. */
  167. if (!stat(cdr.buf,&stab))
  168. copyfileperm(cdr.buf, cdr2.buf);
  169. else if (errno != ENOENT)
  170. ohshite(_("unable to stat current installed conffile `%.250s'"),cdr.buf);
  171. /* Select what the do */
  172. if (!strcmp(currenthash,newdisthash)) {
  173. /* They're both the same so there's no point asking silly questions. */
  174. useredited= -1;
  175. distedited= -1;
  176. what= cfo_identical;
  177. } else if (!strcmp(currenthash,NONEXISTENTFLAG) && fc_conff_miss) {
  178. fprintf(stderr, _("\nConfiguration file `%s', does not exist on system.\n"
  179. "Installing new config file as you request.\n"), conff->name);
  180. what= cfo_newconff;
  181. useredited= -1;
  182. distedited= -1;
  183. } else if (!strcmp(conff->hash,NEWCONFFILEFLAG)) {
  184. if (!strcmp(currenthash,NONEXISTENTFLAG)) {
  185. what= cfo_newconff;
  186. useredited= -1;
  187. distedited= -1;
  188. } else {
  189. useredited= 1;
  190. distedited= 1;
  191. what= conffoptcells[useredited][distedited] | cfof_isnew;
  192. }
  193. } else {
  194. useredited= strcmp(conff->hash,currenthash) != 0;
  195. distedited= strcmp(conff->hash,newdisthash) != 0;
  196. what= conffoptcells[useredited][distedited];
  197. if (!strcmp(currenthash,NONEXISTENTFLAG))
  198. what |= cfof_userrmd;
  199. }
  200. debug(dbg_conff,
  201. "deferred_configure `%s' (= `%s') useredited=%d distedited=%d what=%o",
  202. conff->name, cdr.buf, useredited, distedited, what);
  203. what=promptconfaction(conff->name, cdr.buf, cdr2.buf, useredited, distedited, what);
  204. switch (what & ~(cfof_isnew|cfof_userrmd)) {
  205. case cfo_keep | cfof_backup:
  206. strcpy(cdr2rest,DPKGOLDEXT);
  207. if (unlink(cdr2.buf) && errno != ENOENT)
  208. fprintf(stderr,
  209. _("dpkg: %s: warning - failed to remove old backup `%.250s': %s\n"),
  210. pkg->name, cdr2.buf, strerror(errno));
  211. cdr.used--;
  212. varbufaddstr(&cdr,DPKGDISTEXT);
  213. varbufaddc(&cdr,0);
  214. strcpy(cdr2rest,DPKGNEWEXT);
  215. if (rename(cdr2.buf,cdr.buf))
  216. fprintf(stderr,
  217. _("dpkg: %s: warning - failed to rename `%.250s' to `%.250s': %s\n"),
  218. pkg->name, cdr2.buf, cdr.buf, strerror(errno));
  219. break;
  220. case cfo_keep:
  221. strcpy(cdr2rest,DPKGNEWEXT);
  222. if (unlink(cdr2.buf))
  223. fprintf(stderr,
  224. _("dpkg: %s: warning - failed to remove `%.250s': %s\n"),
  225. pkg->name, cdr2.buf, strerror(errno));
  226. break;
  227. case cfo_install | cfof_backup:
  228. strcpy(cdr2rest,DPKGDISTEXT);
  229. if (unlink(cdr2.buf) && errno != ENOENT)
  230. fprintf(stderr,
  231. _("dpkg: %s: warning - failed to remove old distrib version `%.250s': %s\n"),
  232. pkg->name, cdr2.buf, strerror(errno));
  233. strcpy(cdr2rest,DPKGOLDEXT);
  234. if (unlink(cdr2.buf) && errno != ENOENT)
  235. fprintf(stderr,
  236. _("dpkg: %s: warning - failed to remove `%.250s' (before overwrite): %s\n"),
  237. pkg->name, cdr2.buf, strerror(errno));
  238. if (!(what & cfof_userrmd))
  239. if (link(cdr.buf,cdr2.buf))
  240. fprintf(stderr,
  241. _("dpkg: %s: warning - failed to link `%.250s' to `%.250s': %s\n"),
  242. pkg->name, cdr.buf, cdr2.buf, strerror(errno));
  243. /* fall through */
  244. case cfo_install:
  245. printf(_("Installing new version of config file %s ...\n"),conff->name);
  246. case cfo_newconff:
  247. strcpy(cdr2rest,DPKGNEWEXT);
  248. if (rename(cdr2.buf,cdr.buf))
  249. ohshite(_("unable to install `%.250s' as `%.250s'"),cdr2.buf,cdr.buf);
  250. break;
  251. default:
  252. internerr("unknown what");
  253. }
  254. conff->hash= nfstrsave(newdisthash);
  255. modstatdb_note(pkg);
  256. free(newdisthash);
  257. free(currenthash);
  258. } /* for (conff= ... */
  259. varbuffree(&cdr);
  260. varbuffree(&cdr2);
  261. pkg->status= stat_halfconfigured;
  262. }
  263. assert(pkg->status == stat_halfconfigured);
  264. modstatdb_note(pkg);
  265. if (maintainer_script_installed(pkg, POSTINSTFILE, "post-installation",
  266. "configure",
  267. informativeversion(&pkg->configversion)
  268. ? versiondescribe(&pkg->configversion,
  269. vdew_nonambig)
  270. : "",
  271. (char*)0))
  272. putchar('\n');
  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",(char*)0);
  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. }