/* * dselect - Debian GNU/Linux package maintenance user interface * method.cc - access method handling * * Copyright (C) 1995 Ian Jackson * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with dpkg; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include extern "C" { #include "config.h" #include "dpkg.h" #include "dpkg-db.h" } #include "dselect.h" #include "method.h" static const char *const methoddirectories[]= { LIBDIR "/" METHODSDIR, LOCALLIBDIR "/" METHODSDIR, 0 }; static char *methodlockfile= 0; static int methlockfd= -1; static void cu_unlockmethod(int, void**) { assert(methodlockfile); assert(methlockfd); if (flock(methlockfd,LOCK_UN)) ohshite("unable to unlock access method area"); } static enum urqresult ensureoptions(void) { const char *const *ccpp; option *newoptions; int nread; if (!options) { newoptions= 0; nread= 0; for (ccpp= methoddirectories; *ccpp; ccpp++) readmethods(*ccpp, &newoptions, &nread); if (!newoptions) { curseson(); addstr("No access methods are available.\n\n" "Press RETURN to continue."); refresh(); getch(); return urqr_fail; } options= newoptions; noptions= nread; } return urqr_normal; } static void lockmethod(void) { if (!methodlockfile) { int l; l= strlen(admindir); methodlockfile= new char[l+sizeof(METHLOCKFILE)+2]; strcpy(methodlockfile,admindir); strcpy(methodlockfile+l, "/" METHLOCKFILE); } if (methlockfd == -1) { methlockfd= open(methodlockfile, O_RDWR|O_CREAT|O_TRUNC, 0660); if (methlockfd == -1) { if (errno == EPERM) ohshit("you do not have permission to change the access method"); ohshite("unable to open/create access method lockfile"); } } if (flock(methlockfd,LOCK_EX|LOCK_NB)) { if (errno == EWOULDBLOCK || errno == EAGAIN) ohshit("the access method area is already locked"); ohshite("unable to lock access method area"); } push_cleanup(cu_unlockmethod,~0, 0,0, 0); } static int catchsignals[]= { SIGQUIT, SIGINT, 0 }; #define NCATCHSIGNALS ((signed)(sizeof(catchsignals)/sizeof(int))-1) static struct sigaction uncatchsignal[NCATCHSIGNALS]; void cu_restoresignals(int, void**) { int i; for (i=0; imeth->pathinmeth,exepath); const char *fallibleargs[] = { exepath, admindir, coption->meth->name, coption->name, 0 }; ur= falliblesubprocess(coption->meth->path,name,fallibleargs); } else { curseson(); addstr("No access method is selected/configured.\n\n" "Press RETURN to continue."); refresh(); getch(); ur= urqr_fail; } pop_cleanup(ehflag_normaltidy); return ur; } urqresult urq_update(void) { return runscript(METHODUPDATESCRIPT,"update available list script"); } urqresult urq_install(void) { return runscript(METHODINSTALLSCRIPT,"installation script"); } static urqresult rundpkgauto(const char *name, const char *dpkgmode) { const char *fallibleargs[] = { DPKG, "--pending", dpkgmode, 0 }; cursesoff(); printf("running dpkg --pending %s ...\n",dpkgmode); fflush(stdout); return falliblesubprocess(DPKG,name,fallibleargs); } urqresult urq_remove(void) { return rundpkgauto("dpkg --remove","--remove"); } urqresult urq_config(void) { return rundpkgauto("dpkg --configure","--configure"); } urqresult urq_setup(void) { quitaction qa; urqresult ur; ur= ensureoptions(); if (ur != urqr_normal) return ur; lockmethod(); getcurrentopt(); curseson(); methodlist *l= new methodlist(); qa= l->display(); delete l; if (qa == qa_quitchecksave) { strcpy(coption->meth->pathinmeth,METHODSETUPSCRIPT); const char *fallibleargs[] = { METHODSETUPSCRIPT, admindir, coption->meth->name, coption->name, 0 }; ur= falliblesubprocess(coption->meth->path,"query/setup script",fallibleargs); if (ur == urqr_normal) writecurrentopt(); } else { ur= urqr_fail; } pop_cleanup(ehflag_normaltidy); return ur; }