static void action_open(const char *const *action) { const char *file_name = action[2]; char full_name[1024]; msg_file_t file = NULL; double clock = MSG_get_clock(); snprintf(full_name,1023, "%s:%s", MSG_process_get_name(MSG_process_self()), file_name); ACT_DEBUG("Entering Open: %s (filename: %s)", NAME, file_name); file = MSG_file_open(file_name, NULL); xbt_dict_set(opened_files, full_name, file, NULL); log_action(action, MSG_get_clock() - clock); }
int Command_commit(Command *cmd) { bstring what = option(cmd, "what", ""); bstring why = option(cmd, "why", NULL); bstring where = option(cmd, "where", NULL); bstring how = option(cmd, "how", "m2sh"); bstring db_file = option(cmd, "db", "config.sqlite"); check_file(db_file, "config database", R_OK | W_OK); return log_action(db_file, what, why, where, how); error: return -1; }
static void action_read(const char *const *action) { const char *file_name = action[2]; const char *size_str = action[3]; msg_file_t file = NULL; sg_size_t size = parse_size(size_str); double clock = MSG_get_clock(); file = get_file_descriptor(file_name); ACT_DEBUG("Entering Read: %s (size: %llu)", NAME, size); MSG_file_read(file, size); log_action(action, MSG_get_clock() - clock); }
static void action_bcast(const char *const *action) { int i; char *bcast_identifier; char mailbox[80]; double comm_size = parse_double(action[2]); msg_task_t task = NULL; const char *process_name; double clock = MSG_get_clock(); process_globals_t counters = (process_globals_t) MSG_process_get_data(MSG_process_self()); xbt_assert(communicator_size, "Size of Communicator is not defined, " "can't use collective operations"); process_name = MSG_process_get_name(MSG_process_self()); bcast_identifier = bprintf("bcast_%d", counters->bcast_counter++); if (!strcmp(process_name, "p0")) { XBT_DEBUG("%s: %s is the Root", bcast_identifier, process_name); msg_comm_t *comms = xbt_new0(msg_comm_t, communicator_size - 1); for (i = 1; i < communicator_size; i++) { sprintf(mailbox, "%s_p0_p%d", bcast_identifier, i); comms[i - 1] = MSG_task_isend(MSG_task_create(mailbox, 0, comm_size, NULL), mailbox); } MSG_comm_waitall(comms, communicator_size - 1, -1); for (i = 1; i < communicator_size; i++) MSG_comm_destroy(comms[i - 1]); xbt_free(comms); XBT_DEBUG("%s: all messages sent by %s have been received", bcast_identifier, process_name); } else { sprintf(mailbox, "%s_p0_%s", bcast_identifier, process_name); MSG_task_receive(&task, mailbox); MSG_task_destroy(task); XBT_DEBUG("%s: %s has received", bcast_identifier, process_name); } log_action(action, MSG_get_clock() - clock); xbt_free(bcast_identifier); }
static void simrelease(const char *const *action) { const char *processid = action[0]; const char *file_name = action[2]; const char *worktime = action[3]; double sleeptime; const char *index = action[4]; msg_file_t file; double clock = MSG_get_clock(); /* this "call" is free thanks to inlining */ sleeptime = atof(worktime); MSG_process_sleep(sleeptime); file = get_file_descriptor(file_name,index); ACT_DEBUG("Entering Close: %s (filename: %s)", NAME, file_name); MSG_file_close(file); log_action(action, MSG_get_clock() - clock); XBT_INFO("release worker %s%s is done",processid,index); }
void *save_calloc(const char *name,const char *file,int line, size_t nelem,size_t elsize) { void *p; p=NULL; if ((nelem==0)||(elsize==0)) p=NULL; else { #ifdef PRINT_ALLOC_KB int rank=0; if (nelem*elsize >= PRINT_ALLOC_KB*1024) { #ifdef GMX_MPI #include <mpi.h> MPI_Comm_rank(MPI_COMM_WORLD,&rank); #endif printf("Allocating %.1f MB for %s (called from file %s, line %d on %d)\n", nelem*elsize/1048576.0,name,file,line,rank); } #endif #ifdef GMX_BROKEN_CALLOC /* emulate calloc(3) with malloc/memset on machines with a broken calloc, e.g. in -lgmalloc on cray xt3. */ if ((p=malloc((size_t)nelem*(size_t)elsize))==NULL) gmx_fatal(errno,__FILE__,__LINE__, "Not enough memory. Failed to calloc %"gmx_large_int_fmt " elements of size %"gmx_large_int_fmt " for %s\n(called from file %s, line %d)", (gmx_large_int_t)nelem,(gmx_large_int_t)elsize, name,file,line); memset(p, 0,(size_t) (nelem * elsize)); #else if ((p=calloc((size_t)nelem,(size_t)elsize))==NULL) gmx_fatal(errno,__FILE__,__LINE__, "Not enough memory. Failed to calloc %"gmx_large_int_fmt " elements of size %"gmx_large_int_fmt " for %s\n(called from file %s, line %d)", (gmx_large_int_t)nelem,(gmx_large_int_t)elsize,name,file,line); #endif } #ifdef DEBUG log_action(1,name,file,line,nelem,elsize,p); #endif return p; }
static void simread(const char *const *action) { const char *processid = action[0]; const char *file_name = action[2]; const char *index = action[4]; const char *position_str =action[5]; const char *size_str = action[6]; msg_file_t file = NULL; sg_size_t size = parse_size(size_str); sg_offset_t position= parse_offset(position_str); double clock = MSG_get_clock(); /* this "call" is free thanks to inlining */ file = get_file_descriptor(file_name,index); ACT_DEBUG("Entering Read: %s (size: %llu)", NAME, size); MSG_file_seek(file,position,SEEK_SET); MSG_file_read(file, size); log_action(action, MSG_get_clock() - clock); XBT_INFO("read worker %s%s is done",processid,index); }
static void send_next_log(void* data) { int tmpLog = curLog; curLog = 0; char buffer[LOG_COLS]; if(tmpLog > 0){ strcpy(buffer, logqueue[0]); for(int i = 1; i < tmpLog; i++){ strcpy(logqueue[i - 1], logqueue[i]); curLog++; } log_action(buffer); } }
static void action_Isend(const char *const *action) { char to[250]; const char *size = action[3]; double clock = MSG_get_clock(); process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self()); sprintf(to, "%s_%s", MSG_process_get_name(MSG_process_self()), action[2]); msg_comm_t comm = MSG_task_isend(MSG_task_create(to, 0, parse_double(size), NULL), to); xbt_dynar_push(globals->isends, &comm); XBT_DEBUG("Isend on %s", MSG_process_get_name(MSG_process_self())); log_action(action, MSG_get_clock() - clock); asynchronous_cleanup(); }
static void simopen(const char *const *action) { const char *processid = action[0]; const char *file_name = action[2]; const char *worktime = action[3]; double sleeptime; const char *index = action[4]; char full_name[1024]; msg_file_t file = NULL; double clock = MSG_get_clock(); /* this "call" is free thanks to inlining */ sleeptime = atof(worktime); MSG_process_sleep(sleeptime); sprintf(full_name, "%s:%s:%s", file_name,MSG_process_get_name(MSG_process_self()),index); ACT_DEBUG("Entering Open: %s (filename: %s)", NAME, file_name); file = MSG_file_open(file_name, NULL); xbt_dict_set(opened_files, full_name, file, NULL); log_action(action, MSG_get_clock() - clock); XBT_INFO("open worker %s%s is done",processid,index); }
static void action_recv(const char *const *action) { char mailbox_name[250]; msg_task_t task = NULL; double clock = MSG_get_clock(); sprintf(mailbox_name, "%s_%s", action[2], MSG_process_get_name(MSG_process_self())); ACT_DEBUG("Receiving: %s", NAME); msg_error_t res = MSG_task_receive(&task, mailbox_name); log_action(action, MSG_get_clock() - clock); if (res == MSG_OK) { MSG_task_destroy(task); } asynchronous_cleanup(); }
void *save_malloc(char *name,char *file,int line,int size) { void *p; p=NULL; if (size==0) p=NULL; else { if ((p=malloc(size))==NULL) fatal_error(errno,"malloc for %s (%d bytes, file %s, line %d)", name,size,file,line); (void) memset(p,0,size); } #ifdef DEBUG log_action(1,name,file,line,1,size,p); #endif return p; }
void *save_calloc(char *name,char *file,int line, unsigned nelem,unsigned elsize) { void *p; p=NULL; if ((nelem==0)||(elsize==0)) p=NULL; else { if ((p=calloc((size_t)nelem,(size_t)elsize))==NULL) fatal_error(errno,"calloc for %s (nelem=%d, elsize=%d, file %s" ", line %d)",name,nelem,elsize,file,line); } #ifdef DEBUG log_action(1,name,file,line,nelem,elsize,p); #endif return p; }
static void simread(const char *const *action) { const char *processid = action[0]; const char *file_name = action[2]; const char *index = action[4]; const char *position_str =action[5]; const char *size_str = action[6]; msg_file_t file = NULL; sg_size_t size = parse_size(size_str); sg_offset_t position= parse_offset(position_str); double clock = MSG_get_clock(); /* this "call" is free thanks to inlining */ if(position<2880 && (position+size)<2880) { file = get_file_descriptor("fast",file_name,index); ACT_DEBUG("Entering Read: %s (size: %llu)", NAME, size); MSG_file_seek(file,position,SEEK_SET); MSG_file_read(file, size); } else if(position<2880 && (position+size)>2880) { //read the Head part file = get_file_descriptor("fast",file_name,index); ACT_DEBUG("Entering Read: %s (size: %llu)", NAME, size); MSG_file_seek(file,position,SEEK_SET); MSG_file_read(file, (2880-position)); //read the data part file = get_file_descriptor("slow",file_name,index); ACT_DEBUG("Entering Read: %s (size: %llu)", NAME, size); MSG_file_seek(file,2880,SEEK_SET); MSG_file_read(file, size-(2880-position)); } else { XBT_INFO("3 position is %llu ,size is %llu",position,size); file = get_file_descriptor("slow",file_name,index); ACT_DEBUG("Entering Read: %s (size: %llu)", NAME, size); MSG_file_seek(file,position,SEEK_SET); MSG_file_read(file, size); } log_action(action, MSG_get_clock() - clock); XBT_INFO("read worker %s%s is done",processid,index); }
/* My actions */ static void action_send(const char *const *action) { char to[250]; const char *size_str = action[3]; double size = parse_double(size_str); double clock = MSG_get_clock(); /* this "call" is free thanks to inlining */ sprintf(to, "%s_%s", MSG_process_get_name(MSG_process_self()), action[2]); ACT_DEBUG("Entering Send: %s (size: %g)", NAME, size); if (size < 65536) { action_Isend(action); } else { MSG_task_send(MSG_task_create(to, 0, size, NULL), to); } log_action(action, MSG_get_clock() - clock); asynchronous_cleanup(); }
void *save_realloc(const char *name,const char *file,int line,void *ptr, size_t nelem,size_t elsize) { void *p; size_t size = nelem*elsize; p=NULL; if (size==0) { save_free(name, file, line, ptr); } else { #ifdef PRINT_ALLOC_KB int rank=0; if (size >= PRINT_ALLOC_KB*1024) { #ifdef GMX_MPI #include <mpi.h> MPI_Comm_rank(MPI_COMM_WORLD,&rank); #endif printf("Reallocating %.1f MB for %s (called from file %s, line %d on %d)\n", size/1048576.0,name,file,line,rank); } #endif if (ptr==NULL) p=malloc((size_t)size); else p=realloc(ptr,(size_t)size); if (p == NULL) { char cbuf[22]; gmx_fatal(errno,__FILE__,__LINE__, "Not enough memory. Failed to realloc %s bytes for %s, %s=%x\n" "(called from file %s, line %d)", gmx_large_int_str((gmx_large_int_t)size,cbuf), name,name,ptr,file,line); } #ifdef DEBUG log_action(1,name,file,line,1,size,p); #endif } return p; }
int Command_load(Command *cmd) { bstring db_file = option(cmd, "db", "config.sqlite"); bstring conf_file = option(cmd, "config", "mongrel2.conf"); bstring what = NULL; bstring why = NULL; check_file(conf_file, "config file", R_OK); Config_load(bdata(conf_file), bdata(db_file)); what = bfromcstr("load"); why = bfromcstr("command"); log_action(db_file, what, why, NULL, conf_file); error: // fallthrough bdestroy(what); bdestroy(why); return 0; }
static void action_wait(const char *const *action) { msg_task_t task = NULL; msg_comm_t comm; double clock = MSG_get_clock(); process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self()); xbt_assert(xbt_dynar_length(globals->irecvs), "action wait not preceded by any irecv: %s", xbt_str_join_array(action, " ")); ACT_DEBUG("Entering %s", NAME); comm = xbt_dynar_pop_as(globals->irecvs, msg_comm_t); MSG_comm_wait(comm, -1); task = xbt_dynar_pop_as(globals->tasks, msg_task_t); MSG_comm_destroy(comm); MSG_task_destroy(task); log_action(action, MSG_get_clock() - clock); }
static void action_Irecv(const char *const *action) { char mailbox[250]; double clock = MSG_get_clock(); process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self()); XBT_DEBUG("Irecv on %s", MSG_process_get_name(MSG_process_self())); sprintf(mailbox, "%s_%s", action[2], MSG_process_get_name(MSG_process_self())); msg_task_t t = NULL; xbt_dynar_push(globals->tasks, &t); msg_comm_t c = MSG_task_irecv(xbt_dynar_get_ptr (globals->tasks, xbt_dynar_length(globals->tasks) - 1), mailbox); xbt_dynar_push(globals->irecvs, &c); log_action(action, MSG_get_clock() - clock); asynchronous_cleanup(); }
void *save_realloc(char *name,char *file,int line,void *ptr,unsigned size) { void *p; p=NULL; if (size==0) p=NULL; else { if (ptr==NULL) p=malloc((size_t)size); else p=realloc(ptr,(size_t)size); if (p==NULL) fatal_error(errno, "realloc for %s (%d bytes, file %s, line %d, %s=0x%8x)", name,size,file,line,name,ptr); } #ifdef DEBUG log_action(1,name,file,line,1,size,p); #endif return p; }
static void simrelease(const char *const *action) { const char *processid = action[0]; const char *file_name = action[2]; const char *worktime = action[3]; double sleeptime; const char *index = action[4]; msg_file_t file; double clock = MSG_get_clock(); /* this "call" is free thanks to inlining */ //Because the action release is too fast ,to catch up with the clock of the simulator, we let it to sleep for a while. sleeptime = atof(worktime); MSG_process_sleep(sleeptime); //close slow file file = get_file_descriptor("slow",file_name,index); ACT_DEBUG("Entering Close: %s (filename: %s)", NAME, file_name); MSG_file_close(file); //close fast file file = get_file_descriptor("fast",file_name,index); ACT_DEBUG("Entering Close: %s (filename: %s)", NAME, file_name); MSG_file_close(file); log_action(action, MSG_get_clock() - clock); XBT_INFO("release worker %s%s is done",processid,index); }
void *save_malloc(const char *name,const char *file,int line,size_t size) { void *p; p=NULL; if (size==0) p=NULL; else { if ((p=malloc(size))==NULL) { char cbuf[22]; gmx_fatal(errno,__FILE__,__LINE__, "Not enough memory. Failed to malloc %s bytes for %s\n" "(called from file %s, line %d)", gmx_large_int_str((gmx_large_int_t)size,cbuf), name,file,line); } (void) memset(p,0,size); } #ifdef DEBUG log_action(1,name,file,line,1,size,p); #endif return p; }
void process_archive(const char *filename) { static const struct TarFunctions tf = { tarfileread, tarobject, tarobject, tarobject, tarobject, tarobject }; /* These need to be static so that we can pass their addresses to * push_cleanup as arguments to the cu_xxx routines; if an error occurs * we unwind the stack before processing the cleanup list, and these * variables had better still exist ... */ static int p1[2]; static char cidirtmpnambuf[L_tmpnam+100]; static char *cidirbuf = NULL, *reasmbuf = NULL; static struct fileinlist *newconffiles, *newfileslist; static enum pkgstatus oldversionstatus; static struct varbuf infofnvb, fnvb, depprobwhy; static struct tarcontext tc; int c1, r, admindirlen, i, infodirlen, infodirbaseused, status; struct pkgiterator *it; struct pkginfo *pkg, *otherpkg, *divpkg; char *cidir, *cidirrest, *p; char *pfilenamebuf, conffilenamebuf[MAXCONFFILENAME]; char *psize; const char *pfilename, *newinfofilename; struct fileinlist *newconff, **newconffileslastp; struct fileinlist *cfile; struct reversefilelistiter rlistit; struct conffile *searchconff, **iconffileslastp, *newiconff; struct filepackages *packageslump; struct dependency *dsearch, *newdeplist, **newdeplistlastp; struct dependency *newdep, *dep, *providecheck; struct deppossi *psearch, **newpossilastp, *possi, *newpossi, *pdep; FILE *conff; DIR *dsd; struct filenamenode *namenode; struct dirent *de; struct stat stab, oldfs; struct pkg_deconf_list *deconpil, *deconpiltemp; cleanup_pkg_failed= cleanup_conflictor_failed= 0; admindirlen= strlen(admindir); for (pfilename= filename ; pfilename && strlen(pfilename) > 30 && strchr(pfilename,'/') != NULL ; pfilename++ ) pfilename= strchr(pfilename,'/'); if (pfilename && pfilename != filename) { pfilenamebuf= (char *)nfmalloc(strlen(pfilename)+5); strcpy(pfilenamebuf,".../"); strcat(pfilenamebuf,pfilename); pfilename= pfilenamebuf; } else { pfilename= filename; } if (stat(filename,&stab)) ohshite(_("cannot access archive")); if (!f_noact) { /* We can't `tentatively-reassemble' packages. */ if (!reasmbuf) { reasmbuf= m_malloc(admindirlen+sizeof(REASSEMBLETMP)+5); strcpy(reasmbuf,admindir); strcat(reasmbuf,"/" REASSEMBLETMP); } if (unlink(reasmbuf) && errno != ENOENT) ohshite(_("error ensuring `%.250s' doesn't exist"),reasmbuf); push_cleanup(cu_pathname, ~0, NULL, 0, 1, (void *)reasmbuf); c1= m_fork(); if (!c1) { execlp(SPLITTER, SPLITTER, "-Qao", reasmbuf, filename, NULL); ohshite(_("failed to exec dpkg-split to see if it's part of a multiparter")); } while ((r= waitpid(c1,&status,0)) == -1 && errno == EINTR); if (r != c1) { onerr_abort++; ohshite(_("wait for dpkg-split failed")); } switch (WIFEXITED(status) ? WEXITSTATUS(status) : -1) { case 0: /* It was a part - is it complete ? */ if (!stat(reasmbuf,&stab)) { /* Yes. */ filename= reasmbuf; pfilename= _("reassembled package file"); break; } else if (errno == ENOENT) { /* No. That's it, we skip it. */ return; } case 1: /* No, it wasn't a part. */ break; default: checksubprocerr(status,SPLITTER,0); } } /* Verify the package. */ if (!f_nodebsig && (stat(DEBSIGVERIFY, &stab)==0)) { printf(_("Authenticating %s ...\n"), filename); fflush(stdout); c1 = m_fork(); if (!c1) { execl(DEBSIGVERIFY, DEBSIGVERIFY, "-q", filename, NULL); ohshite(_("failed to execl debsig-verify")); } else { int status; waitpid(c1, &status, 0); if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) { if (! fc_badverify) { ohshit(_("Verification on package %s failed!"), filename); } else { fprintf(stderr, _("Verification on package %s failed,\nbut installing anyway as you requested.\n"), filename); } } else { printf(_("passed\n")); } } } if (f_noact) { cidir= cidirtmpnambuf; /* We use tmpnam here, not to get a unique filename, but to get a unique directory. */ if (!tmpnam(cidir)) ohshite(_("unable to get unique filename for control info")); strcat(cidir,"/"); } else { /* We want it to be on the same filesystem so that we can * use rename(2) to install the postinst &c. */ if (!cidirbuf) cidirbuf= m_malloc(admindirlen+sizeof(CONTROLDIRTMP)+MAXCONTROLFILENAME+10); cidir= cidirbuf; strcpy(cidir,admindir); strcat(cidir, "/" CONTROLDIRTMP); } cidirrest= cidir + strlen(cidir); assert(*cidir && cidirrest[-1] == '/'); cidirrest[-1] = '\0'; ensure_pathname_nonexisting(cidir); cidirrest[-1]= '/'; push_cleanup(cu_cidir, ~0, NULL, 0, 2, (void *)cidir, (void *)cidirrest); c1= m_fork(); if (!c1) { cidirrest[-1] = '\0'; execlp(BACKEND, BACKEND, "--control", filename, cidir, NULL); ohshite(_("failed to exec dpkg-deb to extract control information")); } waitsubproc(c1,BACKEND " --control",0); strcpy(cidirrest,CONTROLFILE); parsedb(cidir, pdb_recordavailable | pdb_rejectstatus | pdb_ignorefiles, &pkg,NULL,NULL); if (!pkg->files) { pkg->files= nfmalloc(sizeof(struct filedetails)); pkg->files->next = NULL; pkg->files->name = pkg->files->msdosname = pkg->files->md5sum = NULL; } /* Always nfmalloc. Otherwise, we may overwrite some other field(like md5sum). */ psize = nfmalloc(30); sprintf(psize, "%lu", (unsigned long)stab.st_size); pkg->files->size = psize; if (cipaction->arg == act_avail) { printf(_("Recorded info about %s from %s.\n"),pkg->name,pfilename); pop_cleanup(ehflag_normaltidy); return; } if (pkg->available.architecture && *pkg->available.architecture && strcmp(pkg->available.architecture,"all") && strcmp(pkg->available.architecture,architecture)) forcibleerr(fc_architecture, _("package architecture (%s) does not match system (%s)"), pkg->available.architecture,architecture); if (!pkg->installed.valid) blankpackageperfile(&pkg->installed); assert(pkg->available.valid); for (deconpil= deconfigure; deconpil; deconpil= deconpiltemp) { deconpiltemp= deconpil->next; free(deconpil); } deconfigure = NULL; clear_istobes(); if (!wanttoinstall(pkg,&pkg->available.version,1)) { pop_cleanup(ehflag_normaltidy); return; } /* Check if anything is installed that we conflict with, or not installed * that we need */ pkg->clientdata->istobe= itb_installnew; for (dsearch= pkg->available.depends; dsearch; dsearch= dsearch->next) { switch (dsearch->type) { case dep_conflicts: /* Look for things we conflict with. */ check_conflict(dsearch, pkg, pfilename); break; case dep_breaks: /* Look for things we break. */ check_breaks(dsearch, pkg, pfilename); break; case dep_provides: /* Look for things that conflict with what we provide. */ if (dsearch->list->ed->installed.valid) { for (psearch= dsearch->list->ed->installed.depended; psearch; psearch= psearch->nextrev) { if (psearch->up->type != dep_conflicts) continue; check_conflict(psearch->up, pkg, pfilename); } } break; case dep_suggests: case dep_recommends: case dep_depends: case dep_replaces: case dep_enhances: /* Ignore these here. */ break; case dep_predepends: if (!depisok(dsearch, &depprobwhy, NULL, 1)) { varbufaddc(&depprobwhy,0); fprintf(stderr, _("dpkg: regarding %s containing %s, pre-dependency problem:\n%s"), pfilename, pkg->name, depprobwhy.buf); if (!force_depends(dsearch->list)) ohshit(_("pre-dependency problem - not installing %.250s"),pkg->name); warning(_("ignoring pre-dependency problem!")); } } } /* Look for things that conflict with us. */ for (psearch= pkg->installed.depended; psearch; psearch= psearch->nextrev) { if (psearch->up->type != dep_conflicts) continue; check_conflict(psearch->up, pkg, pfilename); } ensure_allinstfiles_available(); filesdbinit(); trig_file_interests_ensure(); if (pkg->status != stat_notinstalled && pkg->status != stat_configfiles) { printf(_("Preparing to replace %s %s (using %s) ...\n"), pkg->name, versiondescribe(&pkg->installed.version,vdew_nonambig), pfilename); log_action("upgrade", pkg); } else { printf(_("Unpacking %s (from %s) ...\n"),pkg->name,pfilename); log_action("install", pkg); } if (f_noact) { pop_cleanup(ehflag_normaltidy); return; } /* * OK, we're going ahead. */ trig_activate_packageprocessing(pkg); strcpy(cidirrest, TRIGGERSCIFILE); trig_parse_ci(cidir, NULL, trig_cicb_statuschange_activate, pkg); /* Read the conffiles, and copy the hashes across. */ newconffiles = NULL; newconffileslastp = &newconffiles; push_cleanup(cu_fileslist, ~0, NULL, 0, 0); strcpy(cidirrest,CONFFILESFILE); conff= fopen(cidir,"r"); if (conff) { push_cleanup(cu_closefile, ehflag_bombout, NULL, 0, 1, (void *)conff); while (fgets(conffilenamebuf,MAXCONFFILENAME-2,conff)) { p= conffilenamebuf + strlen(conffilenamebuf); assert(p != conffilenamebuf); if (p[-1] != '\n') ohshit(_("name of conffile (starting `%.250s') is too long (>%d characters)"), conffilenamebuf, MAXCONFFILENAME); while (p > conffilenamebuf && isspace(p[-1])) --p; if (p == conffilenamebuf) continue; *p = '\0'; namenode= findnamenode(conffilenamebuf, 0); namenode->oldhash= NEWCONFFILEFLAG; newconff= newconff_append(&newconffileslastp, namenode); /* Let's see if any packages have this file. If they do we * check to see if they listed it as a conffile, and if they did * we copy the hash across. Since (for plain file conffiles, * which is the only kind we are supposed to have) there will * only be one package which `has' the file, this will usually * mean we only look in the package which we're installing now. * The `conffiles' data in the status file is ignored when a * package isn't also listed in the file ownership database as * having that file. If several packages are listed as owning * the file we pick one at random. */ searchconff = NULL; for (packageslump= newconff->namenode->packages; packageslump; packageslump= packageslump->more) { for (i=0; i < PERFILEPACKAGESLUMP && packageslump->pkgs[i]; i++) { otherpkg= packageslump->pkgs[i]; debug(dbg_conffdetail,"process_archive conffile `%s' in package %s - conff ?", newconff->namenode->name,otherpkg->name); for (searchconff= otherpkg->installed.conffiles; searchconff && strcmp(newconff->namenode->name,searchconff->name); searchconff= searchconff->next) debug(dbg_conffdetail, "process_archive conffile `%s' in package %s - conff ? not `%s'", newconff->namenode->name,otherpkg->name,searchconff->name); if (searchconff) { debug(dbg_conff,"process_archive conffile `%s' package=%s %s hash=%s", newconff->namenode->name,otherpkg->name, otherpkg == pkg ? "same" : "different!", searchconff->hash); if (otherpkg == pkg) goto xit_conff_hashcopy_srch; } } } xit_conff_hashcopy_srch: if (searchconff) { newconff->namenode->oldhash= searchconff->hash; /* we don't copy `obsolete'; it's not obsolete in the new package */ } else { debug(dbg_conff,"process_archive conffile `%s' no package, no hash", newconff->namenode->name); } newconff->namenode->flags |= fnnf_new_conff; } if (ferror(conff)) ohshite(_("read error in %.250s"),cidir); pop_cleanup(ehflag_normaltidy); /* conff= fopen() */ if (fclose(conff)) ohshite(_("error closing %.250s"),cidir); } else { if (errno != ENOENT) ohshite(_("error trying to open %.250s"),cidir); } /* All the old conffiles are marked with a flag, so that we don't delete * them if they seem to disappear completely. */ oldconffsetflags(pkg->installed.conffiles); for (i = 0 ; i < cflict_index ; i++) { oldconffsetflags(conflictor[i]->installed.conffiles); } oldversionstatus= pkg->status; assert(oldversionstatus <= stat_installed); debug(dbg_general,"process_archive oldversionstatus=%s", statusstrings[oldversionstatus]); if (oldversionstatus == stat_halfconfigured || oldversionstatus == stat_triggersawaited || oldversionstatus == stat_triggerspending || oldversionstatus == stat_installed) { pkg->eflag |= eflag_reinstreq; pkg->status= stat_halfconfigured; modstatdb_note(pkg); push_cleanup(cu_prermupgrade, ~ehflag_normaltidy, NULL, 0, 1, (void *)pkg); maintainer_script_alternative(pkg, PRERMFILE, "pre-removal", cidir, cidirrest, "upgrade", "failed-upgrade"); pkg->status= stat_unpacked; oldversionstatus= stat_unpacked; modstatdb_note(pkg); } for (deconpil= deconfigure; deconpil; deconpil= deconpil->next) { struct pkginfo *removing = deconpil->pkg_removal; if (removing) printf(_("De-configuring %s, to allow removal of %s ...\n"), deconpil->pkg->name, removing->name); else printf(_("De-configuring %s ...\n"), deconpil->pkg->name); trig_activate_packageprocessing(deconpil->pkg); deconpil->pkg->status= stat_halfconfigured; modstatdb_note(deconpil->pkg); /* This means that we *either* go and run postinst abort-deconfigure, * *or* queue the package for later configure processing, depending * on which error cleanup route gets taken. */ push_cleanup(cu_prermdeconfigure, ~ehflag_normaltidy, ok_prermdeconfigure, ehflag_normaltidy, 3, (void*)deconpil->pkg, (void*)removing, (void*)pkg); if (removing) { maintainer_script_installed(deconpil->pkg, PRERMFILE, "pre-removal", "deconfigure", "in-favour", pkg->name, versiondescribe(&pkg->available.version, vdew_nonambig), "removing", removing->name, versiondescribe(&removing->installed.version, vdew_nonambig), NULL); } else { maintainer_script_installed(deconpil->pkg, PRERMFILE, "pre-removal", "deconfigure", "in-favour", pkg->name, versiondescribe(&pkg->available.version, vdew_nonambig), NULL); } } for (i = 0 ; i < cflict_index; i++) { if (!(conflictor[i]->status == stat_halfconfigured || conflictor[i]->status == stat_triggersawaited || conflictor[i]->status == stat_triggerspending || conflictor[i]->status == stat_installed)) continue; trig_activate_packageprocessing(conflictor[i]); conflictor[i]->status= stat_halfconfigured; modstatdb_note(conflictor[i]); push_cleanup(cu_prerminfavour, ~ehflag_normaltidy, NULL, 0, 2,(void*)conflictor[i],(void*)pkg); maintainer_script_installed(conflictor[i], PRERMFILE, "pre-removal", "remove", "in-favour", pkg->name, versiondescribe(&pkg->available.version, vdew_nonambig), NULL); conflictor[i]->status= stat_halfinstalled; modstatdb_note(conflictor[i]); } pkg->eflag |= eflag_reinstreq; if (pkg->status == stat_notinstalled) pkg->installed.version= pkg->available.version; pkg->status= stat_halfinstalled; modstatdb_note(pkg); if (oldversionstatus == stat_notinstalled) { push_cleanup(cu_preinstverynew, ~ehflag_normaltidy, NULL, 0, 3,(void*)pkg,(void*)cidir,(void*)cidirrest); maintainer_script_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest, "install", NULL); } else if (oldversionstatus == stat_configfiles) { push_cleanup(cu_preinstnew, ~ehflag_normaltidy, NULL, 0, 3,(void*)pkg,(void*)cidir,(void*)cidirrest); maintainer_script_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest, "install", versiondescribe(&pkg->installed.version, vdew_nonambig), NULL); } else { push_cleanup(cu_preinstupgrade, ~ehflag_normaltidy, NULL, 0, 4,(void*)pkg,(void*)cidir,(void*)cidirrest,(void*)&oldversionstatus); maintainer_script_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest, "upgrade", versiondescribe(&pkg->installed.version, vdew_nonambig), NULL); printf(_("Unpacking replacement %.250s ...\n"),pkg->name); } /* * Now we unpack the archive, backing things up as we go. * For each file, we check to see if it already exists. * There are several possibilities: * + We are trying to install a non-directory ... * - It doesn't exist. In this case we simply extract it. * - It is a plain file, device, symlink, &c. We do an `atomic * overwrite' using link() and rename(), but leave a backup copy. * Later, when we delete the backup, we remove it from any other * packages' lists. * - It is a directory. In this case it depends on whether we're * trying to install a symlink or something else. * = If we're not trying to install a symlink we move the directory * aside and extract the node. Later, when we recursively remove * the backed-up directory, we remove it from any other packages' * lists. * = If we are trying to install a symlink we do nothing - ie, * dpkg will never replace a directory tree with a symlink. This * is to avoid embarrassing effects such as replacing a directory * tree with a link to a link to the original directory tree. * + We are trying to install a directory ... * - It doesn't exist. We create it with the appropriate modes. * - It exists as a directory or a symlink to one. We do nothing. * - It is a plain file or a symlink (other than to a directory). * We move it aside and create the directory. Later, when we * delete the backup, we remove it from any other packages' lists. * * Install non-dir Install symlink Install dir * Exists not X X X * File/node/symlink LXR LXR BXR * Directory BXR - - * * X: extract file/node/link/directory * LX: atomic overwrite leaving backup * B: ordinary backup * R: later remove from other packages' lists * -: do nothing * * After we've done this we go through the remaining things in the * lists of packages we're trying to remove (including the old * version of the current package). This happens in reverse order, * so that we process files before the directories (or symlinks-to- * directories) containing them. * + If the thing is a conffile then we leave it alone for the purge * operation. * + Otherwise, there are several possibilities too: * - The listed thing does not exist. We ignore it. * - The listed thing is a directory or a symlink to a directory. * We delete it only if it isn't listed in any other package. * - The listed thing is not a directory, but was part of the package * that was upgraded, we check to make sure the files aren't the * same ones from the old package by checking dev/inode * - The listed thing is not a directory or a symlink to one (ie, * it's a plain file, device, pipe, &c, or a symlink to one, or a * dangling symlink). We delete it. * The removed packages' list becomes empty (of course, the new * version of the package we're installing will have a new list, * which replaces the old version's list). * * If at any stage we remove a file from a package's list, and the * package isn't one we're already processing, and the package's * list becomes empty as a result, we `vanish' the package. This * means that we run its postrm with the `disappear' argument, and * put the package in the `not-installed' state. If it had any * conffiles, their hashes and ownership will have been transferred * already, so we just ignore those and forget about them from the * point of view of the disappearing package. * * NOTE THAT THE OLD POSTRM IS RUN AFTER THE NEW PREINST, since the * files get replaced `as we go'. */ m_pipe(p1); push_cleanup(cu_closepipe, ehflag_bombout, NULL, 0, 1, (void *)&p1[0]); c1= m_fork(); if (!c1) { m_dup2(p1[1],1); close(p1[0]); close(p1[1]); execlp(BACKEND, BACKEND, "--fsys-tarfile", filename, NULL); ohshite(_("unable to exec dpkg-deb to get filesystem archive")); } close(p1[1]); p1[1] = -1; newfileslist = NULL; tc.newfilesp = &newfileslist; push_cleanup(cu_fileslist, ~0, NULL, 0, 0); tc.pkg= pkg; tc.backendpipe= p1[0]; r= TarExtractor((void*)&tc, &tf); if (r) { if (errno) { ohshite(_("error reading dpkg-deb tar output")); } else { ohshit(_("corrupted filesystem tarfile - corrupted package archive")); } } fd_null_copy(p1[0], -1, _("dpkg-deb: zap possible trailing zeros")); close(p1[0]); p1[0] = -1; waitsubproc(c1,BACKEND " --fsys-tarfile",PROCPIPE); if (oldversionstatus == stat_halfinstalled || oldversionstatus == stat_unpacked) { /* Packages that were in `installed' and `postinstfailed' have been reduced * to `unpacked' by now, by the running of the prerm script. */ pkg->status= stat_halfinstalled; modstatdb_note(pkg); push_cleanup(cu_postrmupgrade, ~ehflag_normaltidy, NULL, 0, 1, (void *)pkg); maintainer_script_alternative(pkg, POSTRMFILE, "post-removal", cidir, cidirrest, "upgrade", "failed-upgrade"); } /* If anything goes wrong while tidying up it's a bit late to do * anything about it. However, we don't install the new status * info yet, so that a future dpkg installation will put everything * right (we hope). * * If something does go wrong later the `conflictor' package will be * left in the `removal_failed' state. Removing or installing it * will be impossible if it was required because of the conflict with * the package we're installing now and (presumably) the dependency * by other packages. This means that the files it contains in * common with this package will hang around until we successfully * get this package installed, after which point we can trust the * conflicting package's file list, which will have been updated to * remove any files in this package. */ push_checkpoint(~ehflag_bombout, ehflag_normaltidy); /* Now we delete all the files that were in the old version of * the package only, except (old or new) conffiles, which we leave * alone. */ reversefilelist_init(&rlistit,pkg->clientdata->files); while ((namenode= reversefilelist_next(&rlistit))) { struct filenamenode *usenode; if ((namenode->flags & fnnf_new_conff) || (namenode->flags & fnnf_new_inarchive)) continue; usenode = namenodetouse(namenode, pkg); trig_file_activate(usenode, pkg); fnamevb.used= fnameidlu; varbufaddstr(&fnamevb, usenode->name); varbufaddc(&fnamevb,0); if (!stat(namenode->name,&stab) && S_ISDIR(stab.st_mode)) { debug(dbg_eachfiledetail, "process_archive: %s is a directory", namenode->name); if (isdirectoryinuse(namenode,pkg)) continue; } if (lstat(fnamevb.buf, &oldfs)) { if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR)) warning(_("could not stat old file '%.250s' so not deleting it: %s"), fnamevb.buf, strerror(errno)); continue; } if (S_ISDIR(oldfs.st_mode)) { if (rmdir(fnamevb.buf)) { warning(_("unable to delete old directory '%.250s': %s"), namenode->name, strerror(errno)); } else if ((namenode->flags & fnnf_old_conff)) { warning(_("old conffile '%.250s' was an empty directory " "(and has now been deleted)"), namenode->name); } } else { /* Ok, it's an old file, but is it really not in the new package? * It might be known by a different name because of symlinks. * * We need to check to make sure, so we stat the file, then compare * it to the new list. If we find a dev/inode match, we assume they * are the same file, and leave it alone. NOTE: we don't check in * other packages for sanity reasons (we don't want to stat _all_ * the files on the system). * * We run down the list of _new_ files in this package. This keeps * the process a little leaner. We are only worried about new ones * since ones that stayed the same don't really apply here. */ struct fileinlist *sameas = NULL; static struct stat empty_stat; struct varbuf cfilename = VARBUF_INIT; /* If we can't stat the old or new file, or it's a directory, * we leave it up to the normal code */ debug(dbg_eachfile, "process_archive: checking %s for same files on " "upgrade/downgrade", fnamevb.buf); for (cfile= newfileslist; cfile; cfile= cfile->next) { if (!cfile->namenode->filestat) { struct stat tmp_stat; varbufreset(&cfilename); varbufaddstr(&cfilename, instdir); varbufaddc(&cfilename, '/'); varbufaddstr(&cfilename, cfile->namenode->name); varbufaddc(&cfilename, '\0'); if (lstat(cfilename.buf, &tmp_stat) == 0) { cfile->namenode->filestat = nfmalloc(sizeof(struct stat)); memcpy(cfile->namenode->filestat, &tmp_stat, sizeof(struct stat)); } else { if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR)) ohshite(_("unable to stat other new file `%.250s'"), cfile->namenode->name); cfile->namenode->filestat = &empty_stat; continue; } } if (cfile->namenode->filestat == &empty_stat) continue; if (oldfs.st_dev == cfile->namenode->filestat->st_dev && oldfs.st_ino == cfile->namenode->filestat->st_ino) { if (sameas) warning(_("old file '%.250s' is the same as several new files! " "(both '%.250s' and '%.250s')"), fnamevb.buf, sameas->namenode->name, cfile->namenode->name); sameas= cfile; debug(dbg_eachfile, "process_archive: not removing %s," " since it matches %s", fnamevb.buf, cfile->namenode->name); } } varbuffree(&cfilename); if ((namenode->flags & fnnf_old_conff)) { if (sameas) { if (sameas->namenode->flags & fnnf_new_conff) { if (!strcmp(sameas->namenode->oldhash, NEWCONFFILEFLAG)) { sameas->namenode->oldhash= namenode->oldhash; debug(dbg_eachfile, "process_archive: old conff %s" " is same as new conff %s, copying hash", namenode->name, sameas->namenode->name); } else { debug(dbg_eachfile, "process_archive: old conff %s" " is same as new conff %s but latter already has hash", namenode->name, sameas->namenode->name); } } } else { debug(dbg_eachfile, "process_archive: old conff %s" " is disappearing", namenode->name); namenode->flags |= fnnf_obs_conff; newconff_append(&newconffileslastp, namenode); addfiletolist(&tc, namenode); } continue; } if (sameas) continue; if (secure_unlink_statted(fnamevb.buf, &oldfs)) { warning(_("unable to securely remove old file '%.250s': %s"), namenode->name, strerror(errno)); } } /* !S_ISDIR */ } /* OK, now we can write the updated files-in-this package list, * since we've done away (hopefully) with all the old junk. */ write_filelist_except(pkg,newfileslist,0); /* Trigger interests may have changed. * Firstly we go through the old list of interests deleting them. * Then we go through the new list adding them. */ strcpy(cidirrest, TRIGGERSCIFILE); trig_parse_ci(pkgadminfile(pkg, TRIGGERSCIFILE), trig_cicb_interest_delete, NULL, pkg); trig_parse_ci(cidir, trig_cicb_interest_add, NULL, pkg); trig_file_interests_save(); /* We also install the new maintainer scripts, and any other * cruft that may have come along with the package. First * we go through the existing scripts replacing or removing * them as appropriate; then we go through the new scripts * (any that are left) and install them. */ debug(dbg_general, "process_archive updating info directory"); varbufreset(&infofnvb); varbufaddstr(&infofnvb,admindir); varbufaddstr(&infofnvb, "/" INFODIR); infodirlen= infofnvb.used; varbufaddc(&infofnvb,0); dsd= opendir(infofnvb.buf); if (!dsd) ohshite(_("cannot read info directory")); push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)dsd); while ((de = readdir(dsd)) != NULL) { debug(dbg_veryverbose, "process_archive info file `%s'", de->d_name); if (de->d_name[0] == '.') continue; /* ignore dotfiles, including `.' and `..' */ p= strrchr(de->d_name,'.'); if (!p) continue; /* ignore anything odd */ if (strlen(pkg->name) != (size_t)(p-de->d_name) || strncmp(de->d_name,pkg->name,p-de->d_name)) continue; debug(dbg_stupidlyverbose, "process_archive info this pkg"); /* Right do we have one ? */ p++; /* skip past the full stop */ if (!strcmp(p,LISTFILE)) continue; /* We do the list separately */ if (strlen(p) > MAXCONTROLFILENAME) ohshit(_("old version of package has overly-long info file name starting `%.250s'"), de->d_name); infofnvb.used= infodirlen; varbufaddstr(&infofnvb,de->d_name); varbufaddc(&infofnvb,0); strcpy(cidirrest,p); if (!rename(cidir,infofnvb.buf)) { debug(dbg_scripts, "process_archive info installed %s as %s", cidir, infofnvb.buf); } else if (errno == ENOENT) { /* Right, no new version. */ if (unlink(infofnvb.buf)) ohshite(_("unable to remove obsolete info file `%.250s'"),infofnvb.buf); debug(dbg_scripts, "process_archive info unlinked %s",infofnvb.buf); } else { ohshite(_("unable to install (supposed) new info file `%.250s'"),cidir); } } pop_cleanup(ehflag_normaltidy); /* closedir */ *cidirrest = '\0'; /* the directory itself */ dsd= opendir(cidir); if (!dsd) ohshite(_("unable to open temp control directory")); push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)dsd); while ((de= readdir(dsd))) { if (strchr(de->d_name,'.')) { debug(dbg_scripts,"process_archive tmp.ci script/file `%s' contains dot", de->d_name); continue; } if (strlen(de->d_name) > MAXCONTROLFILENAME) ohshit(_("package contains overly-long control info file name (starting `%.50s')"), de->d_name); strcpy(cidirrest,de->d_name); /* First we check it's not a directory. */ if (!rmdir(cidir)) ohshit(_("package control info contained directory `%.250s'"),cidir); else if (errno != ENOTDIR) ohshite(_("package control info rmdir of `%.250s' didn't say not a dir"),de->d_name); if (!strcmp(de->d_name,CONTROLFILE)) { debug(dbg_scripts,"process_archive tmp.ci script/file `%s' is control",cidir); continue; /* ignore the control file */ } if (!strcmp(de->d_name,LISTFILE)) { warning(_("package %s contained list as info file"), pkg->name); continue; } /* Right, install it */ newinfofilename= pkgadminfile(pkg,de->d_name); if (rename(cidir,newinfofilename)) ohshite(_("unable to install new info file `%.250s' as `%.250s'"), cidir,newinfofilename); debug(dbg_scripts,"process_archive tmp.ci script/file `%s' installed as `%s'", cidir, newinfofilename); } pop_cleanup(ehflag_normaltidy); /* closedir */ /* Update the status database. * This involves copying each field across from the `available' * to the `installed' half of the pkg structure. * For some of the fields we have to do a complicated construction * operation; for others we can just copy the value. * We tackle the fields in the order they appear, so that * we don't miss any out :-). * At least we don't have to copy any strings that are referred * to, because these are never modified and never freed. */ /* The dependencies are the most difficult. We have to build * a whole new forward dependency tree. At least the reverse * links (linking our deppossi's into the reverse chains) * can be done by copy_dependency_links. */ newdeplist = NULL; newdeplistlastp = &newdeplist; for (dep= pkg->available.depends; dep; dep= dep->next) { newdep= nfmalloc(sizeof(struct dependency)); newdep->up= pkg; newdep->next = NULL; newdep->list = NULL; newpossilastp = &newdep->list; for (possi= dep->list; possi; possi= possi->next) { newpossi= nfmalloc(sizeof(struct deppossi)); newpossi->up= newdep; newpossi->ed= possi->ed; newpossi->next = NULL; newpossi->nextrev = newpossi->backrev = NULL; newpossi->verrel= possi->verrel; if (possi->verrel != dvr_none) newpossi->version= possi->version; else blankversion(&newpossi->version); newpossi->cyclebreak= 0; *newpossilastp= newpossi; newpossilastp= &newpossi->next; } newdep->type= dep->type; *newdeplistlastp= newdep; newdeplistlastp= &newdep->next; } /* Right, now we've replicated the forward tree, we * get copy_dependency_links to remove all the old dependency * structures from the reverse links and add the new dependency * structures in instead. It also copies the new dependency * structure pointer for this package into the right field. */ copy_dependency_links(pkg,&pkg->installed.depends,newdeplist,0); /* The `depended' pointer in the structure doesn't represent anything * that is actually specified by this package - it's there so we * can find out what other packages refer to this one. So, * we don't copy it. We go straight on to copy the text fields. */ pkg->installed.essential= pkg->available.essential; pkg->installed.description= pkg->available.description; pkg->installed.maintainer= pkg->available.maintainer; pkg->installed.source= pkg->available.source; pkg->installed.architecture= pkg->available.architecture; pkg->installed.installedsize= pkg->available.installedsize; pkg->installed.version= pkg->available.version; pkg->installed.origin = pkg->available.origin; pkg->installed.bugs = pkg->available.bugs; /* We have to generate our own conffiles structure. */ pkg->installed.conffiles = NULL; iconffileslastp = &pkg->installed.conffiles; for (cfile= newconffiles; cfile; cfile= cfile->next) { newiconff= nfmalloc(sizeof(struct conffile)); newiconff->next = NULL; newiconff->name= nfstrsave(cfile->namenode->name); newiconff->hash= nfstrsave(cfile->namenode->oldhash); newiconff->obsolete= !!(cfile->namenode->flags & fnnf_obs_conff); *iconffileslastp= newiconff; iconffileslastp= &newiconff->next; } /* We can just copy the arbitrary fields list, because it is * never even rearranged. Phew! */ pkg->installed.arbs= pkg->available.arbs; /* Check for disappearing packages: * We go through all the packages on the system looking for ones * whose files are entirely part of the one we've just unpacked * (and which actually *have* some files!). * * Any that we find are removed - we run the postrm with `disappear' * as an argument, and remove their info/... files and status info. * Conffiles are ignored (the new package had better do something * with them !). */ it= iterpkgstart(); while ((otherpkg = iterpkgnext(it)) != NULL) { ensure_package_clientdata(otherpkg); if (otherpkg == pkg || otherpkg->status == stat_notinstalled || otherpkg->status == stat_configfiles || otherpkg->clientdata->istobe == itb_remove || !otherpkg->clientdata->files) continue; debug(dbg_veryverbose, "process_archive checking disappearance %s",otherpkg->name); assert(otherpkg->clientdata->istobe == itb_normal || otherpkg->clientdata->istobe == itb_deconfigure); for (cfile= otherpkg->clientdata->files; cfile && !strcmp(cfile->namenode->name,"/."); cfile= cfile->next); if (!cfile) { debug(dbg_stupidlyverbose, "process_archive no non-root, no disappear"); continue; } for (cfile= otherpkg->clientdata->files; cfile && !filesavespackage(cfile,otherpkg,pkg); cfile= cfile->next); if (cfile) continue; /* So dependency things will give right answers ... */ otherpkg->clientdata->istobe= itb_remove; debug(dbg_veryverbose, "process_archive disappear checking dependencies"); for (pdep= otherpkg->installed.depended; pdep; pdep= pdep->nextrev) { if (pdep->up->type != dep_depends && pdep->up->type != dep_predepends && pdep->up->type != dep_recommends) continue; if (depisok(pdep->up, &depprobwhy, NULL, 0)) continue; varbufaddc(&depprobwhy,0); debug(dbg_veryverbose,"process_archive cannot disappear: %s",depprobwhy.buf); break; } if (!pdep) { /* If we haven't found a reason not to yet, let's look some more. */ for (providecheck= otherpkg->installed.depends; providecheck; providecheck= providecheck->next) { if (providecheck->type != dep_provides) continue; for (pdep= providecheck->list->ed->installed.depended; pdep; pdep= pdep->nextrev) { if (pdep->up->type != dep_depends && pdep->up->type != dep_predepends && pdep->up->type != dep_recommends) continue; if (depisok(pdep->up, &depprobwhy, NULL, 0)) continue; varbufaddc(&depprobwhy,0); debug(dbg_veryverbose,"process_archive cannot disappear (provides %s): %s", providecheck->list->ed->name, depprobwhy.buf); goto break_from_both_loops_at_once; } } break_from_both_loops_at_once:; } otherpkg->clientdata->istobe= itb_normal; if (pdep) continue; printf(_("(Noting disappearance of %s, which has been completely replaced.)\n"), otherpkg->name); debug(dbg_general, "process_archive disappearing %s",otherpkg->name); /* No, we're disappearing it. This is the wrong time to go and * run maintainer scripts and things, as we can't back out. But * what can we do ? It has to be run this late. */ trig_activate_packageprocessing(otherpkg); maintainer_script_installed(otherpkg, POSTRMFILE, "post-removal script (for disappearance)", "disappear", pkg->name, versiondescribe(&pkg->available.version, vdew_nonambig), NULL); /* OK, now we delete all the stuff in the `info' directory .. */ varbufreset(&fnvb); varbufaddstr(&fnvb,admindir); varbufaddstr(&fnvb,"/" INFODIR); infodirbaseused= fnvb.used; varbufaddc(&fnvb,0); dsd= opendir(fnvb.buf); if (!dsd) ohshite(_("cannot read info directory")); push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)dsd); debug(dbg_general, "process_archive disappear cleaning info directory"); while ((de = readdir(dsd)) != NULL) { debug(dbg_veryverbose, "process_archive info file `%s'", de->d_name); if (de->d_name[0] == '.') continue; p= strrchr(de->d_name,'.'); if (!p) continue; if (strlen(otherpkg->name) != (size_t)(p-de->d_name) || strncmp(de->d_name,otherpkg->name,p-de->d_name)) continue; debug(dbg_stupidlyverbose, "process_archive info this pkg"); fnvb.used= infodirbaseused; varbufaddstr(&fnvb,de->d_name); varbufaddc(&fnvb,0); if (unlink(fnvb.buf)) ohshite(_("unable to delete disappearing control info file `%.250s'"),fnvb.buf); debug(dbg_scripts, "process_archive info unlinked %s",fnvb.buf); } pop_cleanup(ehflag_normaltidy); /* closedir */ otherpkg->status= stat_notinstalled; otherpkg->want = want_unknown; otherpkg->eflag = eflag_ok; blankversion(&otherpkg->configversion); blankpackageperfile(&otherpkg->installed); otherpkg->clientdata->fileslistvalid= 0; modstatdb_note(otherpkg); } /* while (otherpkg= ... */ iterpkgend(it); /* Delete files from any other packages' lists. * We have to do this before we claim this package is in any * sane kind of state, as otherwise we might delete by mistake * a file that we overwrote, when we remove the package which * had the version we overwrote. To prevent this we make * sure that we don't claim this package is OK until we * have claimed `ownership' of all its files. */ for (cfile= newfileslist; cfile; cfile= cfile->next) { if (!(cfile->namenode->flags & fnnf_elide_other_lists)) continue; if (cfile->namenode->divert && cfile->namenode->divert->useinstead) { divpkg= cfile->namenode->divert->pkg; if (divpkg == pkg) { debug(dbg_eachfile, "process_archive not overwriting any `%s' (overriding, `%s')", cfile->namenode->name, cfile->namenode->divert->useinstead->name); continue; } else { debug(dbg_eachfile, "process_archive looking for overwriting `%s' (overridden by %s)", cfile->namenode->name, divpkg ? divpkg->name : "<local>"); } } else { divpkg = NULL; debug(dbg_eachfile, "process_archive looking for overwriting `%s'", cfile->namenode->name); } for (packageslump= cfile->namenode->packages; packageslump; packageslump= packageslump->more) { for (i=0; i < PERFILEPACKAGESLUMP && packageslump->pkgs[i]; i++) { otherpkg= packageslump->pkgs[i]; debug(dbg_eachfiledetail, "process_archive ... found in %s\n",otherpkg->name); /* If !fileslistvalid then it's one of the disappeared packages above * and we don't bother with it here, clearly. */ if (otherpkg == pkg || !otherpkg->clientdata->fileslistvalid) continue; if (otherpkg == divpkg) { debug(dbg_eachfiledetail, "process_archive ... diverted, skipping\n"); continue; } /* Found one. We delete remove the list entry for this file, * (and any others in the same package) and then mark the package * as requiring a reread. */ write_filelist_except(otherpkg, otherpkg->clientdata->files, 1); ensure_package_clientdata(otherpkg); debug(dbg_veryverbose, "process_archive overwrote from %s",otherpkg->name); } } } /* Right, the package we've unpacked is now in a reasonable state. * The only thing that we have left to do with it is remove * backup files, and we can leave the user to fix that if and when * it happens (we leave the reinstall required flag, of course). */ pkg->status= stat_unpacked; modstatdb_note(pkg); /* Now we delete all the backup files that we made when * extracting the archive - except for files listed as conffiles * in the new package. * This time we count it as an error if something goes wrong. * * Note that we don't ever delete things that were in the old * package as a conffile and don't appear at all in the new. * They stay recorded as obsolete conffiles and will eventually * (if not taken over by another package) be forgotten. */ for (cfile= newfileslist; cfile; cfile= cfile->next) { if (cfile->namenode->flags & fnnf_new_conff) continue; fnametmpvb.used= fnameidlu; varbufaddstr(&fnametmpvb,namenodetouse(cfile->namenode,pkg)->name); varbufaddstr(&fnametmpvb,DPKGTEMPEXT); varbufaddc(&fnametmpvb,0); ensure_pathname_nonexisting(fnametmpvb.buf); } /* OK, we're now fully done with the main package. * This is quite a nice state, so we don't unwind past here. */ pkg->eflag = eflag_ok; modstatdb_note(pkg); push_checkpoint(~ehflag_bombout, ehflag_normaltidy); /* Only the removal of the conflictor left to do. * The files list for the conflictor is still a little inconsistent in-core, * as we have not yet updated the filename->packages mappings; however, * the package->filenames mapping is */ for (i = 0 ; i < cflict_index ; i++) { /* We need to have the most up-to-date info about which files are what ... */ ensure_allinstfiles_available(); removal_bulk(conflictor[i]); } if (cipaction->arg == act_install) add_to_queue(pkg); }
void strap_log_event(char* path) { if (!persist_read_bool(STRAP_OPT_OUT)) { log_action(path); } }
void CAgent::print(std::vector<float> subspace) { CLog log((char*)"q_map.txt", 3); u32 i; float y, x; std::vector<float> state; for (i = 0; i < agent.inputs_count; i++) state.push_back(0.0); for (i = 0; i < subspace.size(); i++) state[i] = subspace[i]; printf("\n q max \n"); for (y = -1.0; y < 1.0; y+= agent.state_density) { for (x = -1.0; x < 1.0; x+= agent.state_density) { state[subspace.size() + 1] = y; state[subspace.size() + 0] = x; float res = q_learning->get_max_q(state); printf("%2.3f ", res); //u32 state_idx = q_learning->get_state_idx(); //printf("%3u ", state_idx); log.add(0, x); log.add(1, y); log.add(2, res); } printf("\n"); } log.save(); printf("\n\n"); printf("\n q min \n"); for (y = -1.0; y < 1.0; y+= agent.state_density) { for (x = -1.0; x < 1.0; x+= agent.state_density) { state[subspace.size() + 1] = y; state[subspace.size() + 0] = x; float res = q_learning->get_min_q(state); printf("%2.3f ", res); } printf("\n"); } printf("\n\n"); printf("\n q id \n"); CLog log_action_id((char*)"q_action_id.txt", 3); for (y = -1.0; y < 1.0; y+= agent.state_density) { for (x = -1.0; x < 1.0; x+= agent.state_density) { state[subspace.size() + 1] = y; state[subspace.size() + 0] = x; u32 res = q_learning->get_max_q_id(state); printf("%3i ", res); log_action_id.add(0, x); log_action_id.add(1, y); log_action_id.add(2, res); } printf("\n"); } printf("\n\n"); log_action_id.save(); printf("\nbest action matrix \n"); CLog log_action((char*)"q_action.txt", 2 + actions->get_action_size()); for (y = -1.0; y < 1.0; y+= agent.state_density) { for (x = -1.0; x < 1.0; x+= agent.state_density) { state[subspace.size() + 1] = y; state[subspace.size() + 0] = x; u32 action_id = q_learning->get_max_q_id(state); struct sAction action = actions->get(0, action_id); vect_print(action.action); log_action.add(0, x); log_action.add(1, y); for (i = 0; i < action.action.size(); i++) log_action.add(2 + i, action.action[i]); } printf("\n"); } printf("\n\n"); log_action.save(); }
/* * Does cycle checking. Doesn't mind if pkg has no triggers pending - in * that case does nothing but fix up any stale awaiters. */ void trigproc(struct pkginfo *pkg, enum trigproc_type type) { static struct varbuf namesarg; struct varbuf depwhynot = VARBUF_INIT; struct trigpend *tp; struct pkginfo *gaveup; debug(dbg_triggers, "trigproc %s", pkg_name(pkg, pnaw_always)); if (pkg->clientdata->trigprocdeferred) pkg->clientdata->trigprocdeferred->pkg = NULL; pkg->clientdata->trigprocdeferred = NULL; if (pkg->trigpend_head) { enum dep_check ok; assert(pkg->status == PKG_STAT_TRIGGERSPENDING || pkg->status == PKG_STAT_TRIGGERSAWAITED); if (dependtry > 1) { gaveup = check_trigger_cycle(pkg); if (gaveup == pkg) return; if (findbreakcycle(pkg)) sincenothing = 0; } ok = dependencies_ok(pkg, NULL, &depwhynot); if (ok == DEP_CHECK_DEFER) { varbuf_destroy(&depwhynot); enqueue_package(pkg); return; } else if (ok == DEP_CHECK_HALT) { /* We cannot process this package on this dpkg run, * and we can get here repeatedly if this package is * required to make progress for other packages. So * reset the trigger cycles tracking to avoid bogus * cycle detections. */ trigproc_reset_cycle(); /* When doing opportunistic trigger processig, nothing * requires us to be able to make progress; skip the * package and silently ignore the error due to * unsatisfiable dependencies. */ if (type == TRIGPROC_TRY) { varbuf_destroy(&depwhynot); return; } sincenothing = 0; varbuf_end_str(&depwhynot); notice(_("dependency problems prevent processing " "triggers for %s:\n%s"), pkg_name(pkg, pnaw_nonambig), depwhynot.buf); varbuf_destroy(&depwhynot); ohshit(_("dependency problems - leaving triggers unprocessed")); } else if (depwhynot.used) { varbuf_end_str(&depwhynot); notice(_("%s: dependency problems, but processing " "triggers anyway as you requested:\n%s"), pkg_name(pkg, pnaw_nonambig), depwhynot.buf); varbuf_destroy(&depwhynot); } if (dependtry <= 1) { gaveup = check_trigger_cycle(pkg); if (gaveup == pkg) return; } printf(_("Processing triggers for %s (%s) ...\n"), pkg_name(pkg, pnaw_nonambig), versiondescribe(&pkg->installed.version, vdew_nonambig)); log_action("trigproc", pkg, &pkg->installed); varbuf_reset(&namesarg); for (tp = pkg->trigpend_head; tp; tp = tp->next) { varbuf_add_char(&namesarg, ' '); varbuf_add_str(&namesarg, tp->name); } varbuf_end_str(&namesarg); /* Setting the status to half-configured * causes modstatdb_note to clear pending triggers. */ pkg_set_status(pkg, PKG_STAT_HALFCONFIGURED); modstatdb_note(pkg); if (!f_noact) { sincenothing = 0; maintscript_postinst(pkg, "triggered", namesarg.buf + 1, NULL); } post_postinst_tasks(pkg, PKG_STAT_INSTALLED); } else { /* In other branch is done by modstatdb_note(), from inside * post_postinst_tasks(). */ trig_clear_awaiters(pkg); } }
void addFilespec(FILE *fd, int squash_uids, int squash_perms) { unsigned long rmode, mode, uid, gid, major, minor, i; unsigned long start, increment, count, octmode, decmode; char *c, *dir, *name, *dname = NULL, *path = NULL, *path2 = NULL, *line = NULL; char type; size_t len; int argv, i2, overWrite = 0, lineno = 0; __u16 inodeType; while ( getline(&line, &len, fd) >= 0 ) { rmode = mode = uid = gid = major = minor = start = count = overWrite = 0; increment = 1; lineno++; if (( c = strchr(line, '#'))) *c = 0; if ( path ) { free( path ); path = NULL; } if ( path2 ) { free( path2 ); path2 = NULL; } argv = sscanf(line, "%" SCANF_PREFIX "s %c %ld %lu %lu %lu %lu %lu %lu %lu", SCANF_STRING(path), &type, &rmode, &uid, &gid, &major, &minor, &start, &increment, &count); if ( argv < 3 ) { if ( argv > 0 ) log_warning("device table[%d]: bad format for entry '%s' [skip]", lineno, path); continue; } i2 = 0; octmode = rmode; decmode = 0; while ( octmode != 0 ) { decmode = decmode + (octmode % 10) * pow(8, i2++); octmode = octmode / 10; } if ( squash_uids ) uid = gid = 0; mode = decmode; path2 = strdup( path ); name = basename( path ); dir = dirname( path2 ); if (( !strcmp(name, ".")) || ( !strcmp(name, "..")) || ( !strcmp(name, "/"))) { log_warning("device table[%d]: [skip]", lineno); continue; } log_action(ACT_CHDIR, dir, NULL, 0, 0, 0, 0, 0, 0, 0); if ( !do_chdir(dir)) { log_warning("device table[%d]: target directory '%s' for entry '%s' does not exist [skip]", lineno, dir, name); log_action(ACT_CHDIR, "/", NULL, 0, 0, 0, 0, 0, 0, 0); if ( !do_chdir("/")) log_error("[Filesystem error] cannot chdir to root"); continue; } if (( type != 'd' ) && ( type != 'f' ) && ( type != 'p' ) && ( type != 'c' ) && ( type != 'b' ) && ( type != 's')) { log_warning("device table[%d]: bad type '%c' for entry '%s' [skip]", lineno, type, name); continue; } if (squash_perms) { mode &= ~( LINUX_S_IRWXG | LINUX_S_IRWXO ); rmode &= ~( LINUX_S_IRWXG | LINUX_S_IRWXO); } if ( count > 0 ) { if ( dname ) { free( dname ); dname = NULL; } unsigned len; len = strlen(name) + 10; dname = malloc(len + 1); for ( i = start; i < count; i++ ) { snprintf(dname, len, "%s%lu", name, i); if (( overWrite = name_to_inode(dname))) inodeType = inode_mode(dname); if (( type == 'd' ) && ( overWrite ) && ( !LINUX_S_ISDIR(inodeType))) log_error("[Remote fs mismatch] %s/%s exists but isn't a directory when it should be.", log_cwd(), dname); else if (( type != 'd' ) && ( overWrite )) { if ( LINUX_S_ISDIR(inodeType)) log_error("[Remote fs mismatch] %s/%s exists but is a directory when it shouldn't be.", log_cwd(), dname); if ((!LINUX_S_ISREG(inodeType)) && (!LINUX_S_ISLNK(inodeType)) && (!LINUX_S_ISBLK(inodeType)) && (!LINUX_S_ISCHR(inodeType)) && (!LINUX_S_ISFIFO(inodeType)) && (!LINUX_S_ISSOCK(inodeType))) log_error("[Remote fs mismatch] Existing file %s/%s has unknown/unsupported type [0x%x].", log_cwd(), dname, inodeType); } switch ( type ) { case 'd': mode |= LINUX_S_IFDIR; log_action(ACT_MKDIR, dname, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !overWrite ) if ( !do_mkdir(dname)) log_error("[Filesystem error] cannot mkdir %s/%s", log_cwd(), dname); break; case 'c': case 'b': if ( type == 'c' ) mode |= LINUX_S_IFCHR; else mode |= LINUX_S_IFBLK; if ( overWrite ) { log_action(ACT_RM, dname, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !do_rm(dname)) log_error("[Filesystem error] cannot rm %s/%s", log_cwd(), dname); } log_action(ACT_MKNOD, dname, NULL, 0, 0, 0, type, major, minor + ((i * increment) - start), overWrite); if ( !do_mknod(dname, type, major, minor + ((i * increment) - start))) log_error("[Filesystem error] cannot mknod %s/%s", log_cwd(), dname); break; case 's': case 'p': if ( type == 's' ) mode |= LINUX_S_IFSOCK; else mode |= LINUX_S_IFIFO; if ( overWrite ) { log_action(ACT_RM, dname, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !do_rm(dname)) log_error("[Filesystem error] cannot rm %s/%s", log_cwd(), dname); } log_action(ACT_MKNOD, dname, NULL, 0, 0, 0, type, 0, 0, overWrite); if ( !do_mknod(dname, type, 0, 0)) log_error("[Filesystem error] cannot mknod %s/%s", log_cwd(), dname); break; } log_action(ACT_CHMOD, dname, NULL, rmode, 0, 0, 0, 0, 0, 0); if ( !do_chmod(dname, rmode)) log_error("[Filesystem error] cannot chmod %s/%s", log_cwd(), dname); log_action(ACT_CHOWN, dname, NULL, 0, uid, gid, 0, 0, 0, 0); if ( !do_chown(dname, uid, gid)) log_error("[Filesystem error] cannot chown %s/%s", log_cwd(), dname); } log_action(ACT_CHDIR, "/", NULL, 0, 0, 0, 0, 0, 0, 0); if ( !do_chdir("/")) log_error("[Filesystem error] cannot chdir to root"); free(dname); dname = NULL; } else { if (( overWrite = name_to_inode(name))) inodeType = inode_mode(name); if (( type == 'd' ) && ( overWrite ) && ( !LINUX_S_ISDIR(inodeType))) log_error("[Remote fs mismatch] %s/%s exists but isn't a directory when it should be.", log_cwd(), dname); else if ( type != 'd' ) { if (( overWrite ) && ( LINUX_S_ISDIR(inodeType))) log_error("[Remote fs mismatch] %s/%s exists but is a directory when it shouldn't be.", log_cwd(), dname); if (( overWrite ) && (!LINUX_S_ISREG(inodeType)) && (!LINUX_S_ISLNK(inodeType)) && (!LINUX_S_ISBLK(inodeType)) && (!LINUX_S_ISCHR(inodeType)) && (!LINUX_S_ISFIFO(inodeType)) && (!LINUX_S_ISSOCK(inodeType))) log_error("[Remote fs mismatch] Existing file %s/%s has unknown/unsupported type [0x%x].", log_cwd(), dname, inodeType); } switch ( type ) { case 'd': mode |= LINUX_S_IFDIR; log_action(ACT_MKDIR, name, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !overWrite ) if ( !do_mkdir(name)) log_error("[Filesystem error] cannot mkdir %s/%s", log_cwd(), name); break; case 'c': case 'b': if ( type == 'c' ) mode |= LINUX_S_IFCHR; else mode |= LINUX_S_IFBLK; if ( overWrite ) { log_action(ACT_RM, name, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !do_rm(name)) log_error("[Filesystem error] cannot rm %s/%s", log_cwd(), name); } log_action(ACT_MKNOD, name, NULL, 0, 0, 0, type, major, minor, overWrite); if ( !do_mknod(name, type, major, minor)) log_error("[Filesystem error] cannot mknod %s/%s", log_cwd(), name); break; case 's': case 'p': if ( type == 's' ) mode |= LINUX_S_IFSOCK; else mode |= LINUX_S_IFIFO; if ( overWrite ) { log_action(ACT_RM, name, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !do_rm(name)) log_error("[Filesystem error] cannot rm %s/%s", log_cwd(), name); } log_action(ACT_MKNOD, name, NULL, 0, 0, 0, type, 0, 0, overWrite); if ( !do_mknod(name, type, 0, 0)) log_error("[Filesystem error] cannot mknod %s/%s", log_cwd(), name); break; } log_action(ACT_CHMOD, name, NULL, rmode, 0, 0, 0, 0, 0, 0); if ( !do_chmod(name, rmode)) log_error("[Filesystem error] cannot chmod %s/%s", log_cwd(), name); log_action(ACT_CHOWN, name, NULL, 0, uid, gid, 0, 0, 0, 0); if ( !do_chown(name, uid, gid)) log_error("[Filesystem error] cannot chown %s/%s", log_cwd(), name); log_action(ACT_CHDIR, "/", NULL, 0, 0, 0, 0, 0, 0, 0); if ( !do_chdir("/")) log_error("[Filesystem error] cannot chdir to root"); } } if ( line ) { free( line ); line = NULL; } if ( path ) { free( path ); path = NULL; } if ( path2 ) { free( path2 ); path2 = NULL; } }
void process_archive(const char *filename) { static const struct tar_operations tf = { .read = tarfileread, .extract_file = tarobject, .link = tarobject, .symlink = tarobject, .mkdir = tarobject, .mknod = tarobject, }; /* These need to be static so that we can pass their addresses to * push_cleanup as arguments to the cu_xxx routines; if an error occurs * we unwind the stack before processing the cleanup list, and these * variables had better still exist ... */ static int p1[2]; static char *cidir = NULL; static struct fileinlist *newconffiles, *newfileslist; static enum pkgstatus oldversionstatus; static struct varbuf depprobwhy; static struct tarcontext tc; int r, i; pid_t pid; struct pkgiterator *it; struct pkginfo *pkg, *otherpkg; char *cidirrest, *p; char conffilenamebuf[MAXCONFFILENAME]; char *psize; const char *pfilename; struct fileinlist *newconff, **newconffileslastp; struct fileinlist *cfile; struct reversefilelistiter rlistit; struct conffile *searchconff, **iconffileslastp, *newiconff; struct dependency *dsearch, *newdeplist, **newdeplistlastp; struct dependency *newdep, *dep, *providecheck; struct deppossi *psearch, **newpossilastp, *possi, *newpossi, *pdep; FILE *conff; struct filenamenode *namenode; struct stat stab, oldfs; struct pkg_deconf_list *deconpil, *deconpiltemp; struct pkginfo *fixbytrigaw; cleanup_pkg_failed= cleanup_conflictor_failed= 0; pfilename = summarize_filename(filename); if (stat(filename,&stab)) ohshite(_("cannot access archive")); /* We can't ‘tentatively-reassemble’ packages. */ if (!f_noact) { if (!deb_reassemble(&filename, &pfilename)) return; } /* Verify the package. */ if (!f_nodebsig) deb_verify(filename); /* Get the control information directory. */ cidir = get_control_dir(cidir); cidirrest = cidir + strlen(cidir); push_cleanup(cu_cidir, ~0, NULL, 0, 2, (void *)cidir, (void *)cidirrest); pid = subproc_fork(); if (pid == 0) { cidirrest[-1] = '\0'; execlp(BACKEND, BACKEND, "--control", filename, cidir, NULL); ohshite(_("unable to execute %s (%s)"), _("package control information extraction"), BACKEND); } subproc_wait_check(pid, BACKEND " --control", 0); /* We want to guarantee the extracted files are on the disk, so that the * subsequent renames to the info database do not end up with old or zero * length files in case of a system crash. As neither dpkg-deb nor tar do * explicit fsync()s, we have to do them here. * XXX: This could be avoided by switching to an internal tar extractor. */ dir_sync_contents(cidir); strcpy(cidirrest,CONTROLFILE); parsedb(cidir, pdb_parse_binary | pdb_ignorefiles | parsedb_force_flags(), &pkg); if (!pkg->files) { pkg->files= nfmalloc(sizeof(struct filedetails)); pkg->files->next = NULL; pkg->files->name = pkg->files->msdosname = pkg->files->md5sum = NULL; } /* Always nfmalloc. Otherwise, we may overwrite some other field (like * md5sum). */ psize = nfmalloc(30); sprintf(psize, "%jd", (intmax_t)stab.st_size); pkg->files->size = psize; if (cipaction->arg_int == act_avail) { printf(_("Recorded info about %s from %s.\n"), pkgbin_name(pkg, &pkg->available, pnaw_nonambig), pfilename); pop_cleanup(ehflag_normaltidy); return; } if (pkg->available.arch->type != arch_all && pkg->available.arch->type != arch_native) forcibleerr(fc_architecture, _("package architecture (%s) does not match system (%s)"), pkg->available.arch->name, dpkg_arch_get(arch_native)->name); for (deconpil= deconfigure; deconpil; deconpil= deconpiltemp) { deconpiltemp= deconpil->next; free(deconpil); } deconfigure = NULL; clear_istobes(); if (!wanttoinstall(pkg)) { pop_cleanup(ehflag_normaltidy); return; } /* Check if anything is installed that we conflict with, or not installed * that we need. */ pkg->clientdata->istobe= itb_installnew; for (dsearch= pkg->available.depends; dsearch; dsearch= dsearch->next) { switch (dsearch->type) { case dep_conflicts: /* Look for things we conflict with. */ check_conflict(dsearch, pkg, pfilename); break; case dep_breaks: /* Look for things we break. */ check_breaks(dsearch, pkg, pfilename); break; case dep_provides: /* Look for things that conflict with what we provide. */ for (psearch = dsearch->list->ed->depended.installed; psearch; psearch = psearch->rev_next) { if (psearch->up->type != dep_conflicts) continue; check_conflict(psearch->up, pkg, pfilename); } break; case dep_suggests: case dep_recommends: case dep_depends: case dep_replaces: case dep_enhances: /* Ignore these here. */ break; case dep_predepends: if (!depisok(dsearch, &depprobwhy, NULL, &fixbytrigaw, true)) { if (fixbytrigaw) { while (fixbytrigaw->trigaw.head) trigproc(fixbytrigaw->trigaw.head->pend); } else { varbuf_end_str(&depprobwhy); fprintf(stderr, _("dpkg: regarding %s containing %s, pre-dependency problem:\n%s"), pfilename, pkgbin_name(pkg, &pkg->available, pnaw_nonambig), depprobwhy.buf); if (!force_depends(dsearch->list)) ohshit(_("pre-dependency problem - not installing %.250s"), pkgbin_name(pkg, &pkg->available, pnaw_nonambig)); warning(_("ignoring pre-dependency problem!")); } } } } /* Look for things that conflict with us. */ for (psearch = pkg->set->depended.installed; psearch; psearch = psearch->rev_next) { if (psearch->up->type != dep_conflicts) continue; check_conflict(psearch->up, pkg, pfilename); } ensure_allinstfiles_available(); filesdbinit(); trig_file_interests_ensure(); if (pkg->status != stat_notinstalled && pkg->status != stat_configfiles) { printf(_("Preparing to replace %s %s (using %s) ...\n"), pkg_name(pkg, pnaw_nonambig), versiondescribe(&pkg->installed.version,vdew_nonambig), pfilename); log_action("upgrade", pkg, &pkg->installed); } else { printf(_("Unpacking %s (from %s) ...\n"), pkgbin_name(pkg, &pkg->available, pnaw_nonambig), pfilename); log_action("install", pkg, &pkg->available); } if (f_noact) { pop_cleanup(ehflag_normaltidy); return; } /* * OK, we're going ahead. */ trig_activate_packageprocessing(pkg); strcpy(cidirrest, TRIGGERSCIFILE); trig_parse_ci(cidir, NULL, trig_cicb_statuschange_activate, pkg, &pkg->available); /* Read the conffiles, and copy the hashes across. */ newconffiles = NULL; newconffileslastp = &newconffiles; push_cleanup(cu_fileslist, ~0, NULL, 0, 0); strcpy(cidirrest,CONFFILESFILE); conff= fopen(cidir,"r"); if (conff) { push_cleanup(cu_closestream, ehflag_bombout, NULL, 0, 1, (void *)conff); while (fgets(conffilenamebuf,MAXCONFFILENAME-2,conff)) { struct filepackages_iterator *iter; p= conffilenamebuf + strlen(conffilenamebuf); assert(p != conffilenamebuf); if (p[-1] != '\n') ohshit(_("name of conffile (starting `%.250s') is too long (>%d characters)"), conffilenamebuf, MAXCONFFILENAME); while (p > conffilenamebuf && isspace(p[-1])) --p; if (p == conffilenamebuf) continue; *p = '\0'; namenode= findnamenode(conffilenamebuf, 0); namenode->oldhash= NEWCONFFILEFLAG; newconff= newconff_append(&newconffileslastp, namenode); /* Let's see if any packages have this file. If they do we * check to see if they listed it as a conffile, and if they did * we copy the hash across. Since (for plain file conffiles, * which is the only kind we are supposed to have) there will * only be one package which ‘has’ the file, this will usually * mean we only look in the package which we're installing now. * The ‘conffiles’ data in the status file is ignored when a * package isn't also listed in the file ownership database as * having that file. If several packages are listed as owning * the file we pick one at random. */ searchconff = NULL; iter = filepackages_iter_new(newconff->namenode); while ((otherpkg = filepackages_iter_next(iter))) { debug(dbg_conffdetail, "process_archive conffile `%s' in package %s - conff ?", newconff->namenode->name, pkg_name(otherpkg, pnaw_nonambig)); for (searchconff = otherpkg->installed.conffiles; searchconff && strcmp(newconff->namenode->name, searchconff->name); searchconff = searchconff->next) debug(dbg_conffdetail, "process_archive conffile `%s' in package %s - conff ? not `%s'", newconff->namenode->name, pkg_name(otherpkg, pnaw_nonambig), searchconff->name); if (searchconff) { debug(dbg_conff, "process_archive conffile `%s' package=%s %s hash=%s", newconff->namenode->name, pkg_name(otherpkg, pnaw_nonambig), otherpkg == pkg ? "same" : "different!", searchconff->hash); if (otherpkg == pkg) break; } } filepackages_iter_free(iter); if (searchconff) { newconff->namenode->oldhash= searchconff->hash; /* We don't copy ‘obsolete’; it's not obsolete in the new package. */ } else { debug(dbg_conff,"process_archive conffile `%s' no package, no hash", newconff->namenode->name); } newconff->namenode->flags |= fnnf_new_conff; } if (ferror(conff)) ohshite(_("read error in %.250s"),cidir); pop_cleanup(ehflag_normaltidy); /* conff = fopen() */ if (fclose(conff)) ohshite(_("error closing %.250s"),cidir); } else { if (errno != ENOENT) ohshite(_("error trying to open %.250s"),cidir); } /* All the old conffiles are marked with a flag, so that we don't delete * them if they seem to disappear completely. */ oldconffsetflags(pkg->installed.conffiles); for (i = 0 ; i < cflict_index ; i++) { oldconffsetflags(conflictor[i]->installed.conffiles); } oldversionstatus= pkg->status; assert(oldversionstatus <= stat_installed); debug(dbg_general,"process_archive oldversionstatus=%s", statusstrings[oldversionstatus]); if (oldversionstatus == stat_halfconfigured || oldversionstatus == stat_triggersawaited || oldversionstatus == stat_triggerspending || oldversionstatus == stat_installed) { pkg_set_eflags(pkg, eflag_reinstreq); pkg_set_status(pkg, stat_halfconfigured); modstatdb_note(pkg); push_cleanup(cu_prermupgrade, ~ehflag_normaltidy, NULL, 0, 1, (void *)pkg); if (versioncompare(&pkg->available.version, &pkg->installed.version) >= 0) /* Upgrade or reinstall */ maintainer_script_alternative(pkg, PRERMFILE, "pre-removal", cidir, cidirrest, "upgrade", "failed-upgrade"); else /* Downgrade => no fallback */ maintainer_script_installed(pkg, PRERMFILE, "pre-removal", "upgrade", versiondescribe(&pkg->available.version, vdew_nonambig), NULL); pkg_set_status(pkg, stat_unpacked); oldversionstatus= stat_unpacked; modstatdb_note(pkg); } for (deconpil= deconfigure; deconpil; deconpil= deconpil->next) { struct pkginfo *removing = deconpil->pkg_removal; if (removing) printf(_("De-configuring %s, to allow removal of %s ...\n"), pkg_name(deconpil->pkg, pnaw_nonambig), pkg_name(removing, pnaw_nonambig)); else printf(_("De-configuring %s ...\n"), pkg_name(deconpil->pkg, pnaw_nonambig)); trig_activate_packageprocessing(deconpil->pkg); pkg_set_status(deconpil->pkg, stat_halfconfigured); modstatdb_note(deconpil->pkg); /* This means that we *either* go and run postinst abort-deconfigure, * *or* queue the package for later configure processing, depending * on which error cleanup route gets taken. */ push_cleanup(cu_prermdeconfigure, ~ehflag_normaltidy, ok_prermdeconfigure, ehflag_normaltidy, 3, (void*)deconpil->pkg, (void*)removing, (void*)pkg); if (removing) { maintainer_script_installed(deconpil->pkg, PRERMFILE, "pre-removal", "deconfigure", "in-favour", pkg->set->name, versiondescribe(&pkg->available.version, vdew_nonambig), "removing", removing->set->name, versiondescribe(&removing->installed.version, vdew_nonambig), NULL); } else { maintainer_script_installed(deconpil->pkg, PRERMFILE, "pre-removal", "deconfigure", "in-favour", pkg->set->name, versiondescribe(&pkg->available.version, vdew_nonambig), NULL); } } for (i = 0 ; i < cflict_index; i++) { if (!(conflictor[i]->status == stat_halfconfigured || conflictor[i]->status == stat_triggersawaited || conflictor[i]->status == stat_triggerspending || conflictor[i]->status == stat_installed)) continue; trig_activate_packageprocessing(conflictor[i]); pkg_set_status(conflictor[i], stat_halfconfigured); modstatdb_note(conflictor[i]); push_cleanup(cu_prerminfavour, ~ehflag_normaltidy, NULL, 0, 2,(void*)conflictor[i],(void*)pkg); maintainer_script_installed(conflictor[i], PRERMFILE, "pre-removal", "remove", "in-favour", pkg->set->name, versiondescribe(&pkg->available.version, vdew_nonambig), NULL); pkg_set_status(conflictor[i], stat_halfinstalled); modstatdb_note(conflictor[i]); } pkg_set_eflags(pkg, eflag_reinstreq); if (pkg->status == stat_notinstalled) pkg->installed.version= pkg->available.version; pkg_set_status(pkg, stat_halfinstalled); modstatdb_note(pkg); if (oldversionstatus == stat_notinstalled) { push_cleanup(cu_preinstverynew, ~ehflag_normaltidy, NULL, 0, 3,(void*)pkg,(void*)cidir,(void*)cidirrest); maintainer_script_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest, "install", NULL); } else if (oldversionstatus == stat_configfiles) { push_cleanup(cu_preinstnew, ~ehflag_normaltidy, NULL, 0, 3,(void*)pkg,(void*)cidir,(void*)cidirrest); maintainer_script_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest, "install", versiondescribe(&pkg->installed.version, vdew_nonambig), NULL); } else { push_cleanup(cu_preinstupgrade, ~ehflag_normaltidy, NULL, 0, 4,(void*)pkg,(void*)cidir,(void*)cidirrest,(void*)&oldversionstatus); maintainer_script_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest, "upgrade", versiondescribe(&pkg->installed.version, vdew_nonambig), NULL); printf(_("Unpacking replacement %.250s ...\n"), pkgbin_name(pkg, &pkg->available, pnaw_nonambig)); } /* * Now we unpack the archive, backing things up as we go. * For each file, we check to see if it already exists. * There are several possibilities: * * + We are trying to install a non-directory ... * - It doesn't exist. In this case we simply extract it. * - It is a plain file, device, symlink, &c. We do an ‘atomic * overwrite’ using link() and rename(), but leave a backup copy. * Later, when we delete the backup, we remove it from any other * packages' lists. * - It is a directory. In this case it depends on whether we're * trying to install a symlink or something else. * = If we're not trying to install a symlink we move the directory * aside and extract the node. Later, when we recursively remove * the backed-up directory, we remove it from any other packages' * lists. * = If we are trying to install a symlink we do nothing - ie, * dpkg will never replace a directory tree with a symlink. This * is to avoid embarrassing effects such as replacing a directory * tree with a link to a link to the original directory tree. * + We are trying to install a directory ... * - It doesn't exist. We create it with the appropriate modes. * - It exists as a directory or a symlink to one. We do nothing. * - It is a plain file or a symlink (other than to a directory). * We move it aside and create the directory. Later, when we * delete the backup, we remove it from any other packages' lists. * * Install non-dir Install symlink Install dir * Exists not X X X * File/node/symlink LXR LXR BXR * Directory BXR - - * * X: extract file/node/link/directory * LX: atomic overwrite leaving backup * B: ordinary backup * R: later remove from other packages' lists * -: do nothing * * After we've done this we go through the remaining things in the * lists of packages we're trying to remove (including the old * version of the current package). This happens in reverse order, * so that we process files before the directories (or symlinks-to- * directories) containing them. * * + If the thing is a conffile then we leave it alone for the purge * operation. * + Otherwise, there are several possibilities too: * - The listed thing does not exist. We ignore it. * - The listed thing is a directory or a symlink to a directory. * We delete it only if it isn't listed in any other package. * - The listed thing is not a directory, but was part of the package * that was upgraded, we check to make sure the files aren't the * same ones from the old package by checking dev/inode * - The listed thing is not a directory or a symlink to one (ie, * it's a plain file, device, pipe, &c, or a symlink to one, or a * dangling symlink). We delete it. * * The removed packages' list becomes empty (of course, the new * version of the package we're installing will have a new list, * which replaces the old version's list). * * If at any stage we remove a file from a package's list, and the * package isn't one we're already processing, and the package's * list becomes empty as a result, we ‘vanish’ the package. This * means that we run its postrm with the ‘disappear’ argument, and * put the package in the ‘not-installed’ state. If it had any * conffiles, their hashes and ownership will have been transferred * already, so we just ignore those and forget about them from the * point of view of the disappearing package. * * NOTE THAT THE OLD POSTRM IS RUN AFTER THE NEW PREINST, since the * files get replaced ‘as we go’. */ m_pipe(p1); push_cleanup(cu_closepipe, ehflag_bombout, NULL, 0, 1, (void *)&p1[0]); pid = subproc_fork(); if (pid == 0) { m_dup2(p1[1],1); close(p1[0]); close(p1[1]); execlp(BACKEND, BACKEND, "--fsys-tarfile", filename, NULL); ohshite(_("unable to execute %s (%s)"), _("package filesystem archive extraction"), BACKEND); } close(p1[1]); p1[1] = -1; newfileslist = NULL; tc.newfilesp = &newfileslist; push_cleanup(cu_fileslist, ~0, NULL, 0, 0); tc.pkg= pkg; tc.backendpipe= p1[0]; r = tar_extractor(&tc, &tf); if (r) { if (errno) { ohshite(_("error reading dpkg-deb tar output")); } else { ohshit(_("corrupted filesystem tarfile - corrupted package archive")); } } fd_skip(p1[0], -1, _("dpkg-deb: zap possible trailing zeros")); close(p1[0]); p1[0] = -1; subproc_wait_check(pid, BACKEND " --fsys-tarfile", PROCPIPE); tar_deferred_extract(newfileslist, pkg); if (oldversionstatus == stat_halfinstalled || oldversionstatus == stat_unpacked) { /* Packages that were in ‘installed’ and ‘postinstfailed’ have been * reduced to ‘unpacked’ by now, by the running of the prerm script. */ pkg_set_status(pkg, stat_halfinstalled); modstatdb_note(pkg); push_cleanup(cu_postrmupgrade, ~ehflag_normaltidy, NULL, 0, 1, (void *)pkg); maintainer_script_alternative(pkg, POSTRMFILE, "post-removal", cidir, cidirrest, "upgrade", "failed-upgrade"); } /* If anything goes wrong while tidying up it's a bit late to do * anything about it. However, we don't install the new status * info yet, so that a future dpkg installation will put everything * right (we hope). * * If something does go wrong later the ‘conflictor’ package will be * left in the ‘removal_failed’ state. Removing or installing it * will be impossible if it was required because of the conflict with * the package we're installing now and (presumably) the dependency * by other packages. This means that the files it contains in * common with this package will hang around until we successfully * get this package installed, after which point we can trust the * conflicting package's file list, which will have been updated to * remove any files in this package. */ push_checkpoint(~ehflag_bombout, ehflag_normaltidy); /* Now we delete all the files that were in the old version of * the package only, except (old or new) conffiles, which we leave * alone. */ reversefilelist_init(&rlistit,pkg->clientdata->files); while ((namenode= reversefilelist_next(&rlistit))) { struct filenamenode *usenode; if ((namenode->flags & fnnf_new_conff) || (namenode->flags & fnnf_new_inarchive)) continue; usenode = namenodetouse(namenode, pkg, &pkg->installed); trig_file_activate(usenode, pkg); varbuf_trunc(&fnamevb, fnameidlu); varbuf_add_str(&fnamevb, usenode->name); varbuf_end_str(&fnamevb); if (!stat(namenode->name,&stab) && S_ISDIR(stab.st_mode)) { debug(dbg_eachfiledetail, "process_archive: %s is a directory", namenode->name); if (dir_is_used_by_others(namenode, pkg)) continue; } if (lstat(fnamevb.buf, &oldfs)) { if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR)) warning(_("could not stat old file '%.250s' so not deleting it: %s"), fnamevb.buf, strerror(errno)); continue; } if (S_ISDIR(oldfs.st_mode)) { if (rmdir(fnamevb.buf)) { warning(_("unable to delete old directory '%.250s': %s"), namenode->name, strerror(errno)); } else if ((namenode->flags & fnnf_old_conff)) { warning(_("old conffile '%.250s' was an empty directory " "(and has now been deleted)"), namenode->name); } } else { struct fileinlist *sameas = NULL; static struct stat empty_stat; struct varbuf cfilename = VARBUF_INIT; /* * Ok, it's an old file, but is it really not in the new package? * It might be known by a different name because of symlinks. * * We need to check to make sure, so we stat the file, then compare * it to the new list. If we find a dev/inode match, we assume they * are the same file, and leave it alone. NOTE: we don't check in * other packages for sanity reasons (we don't want to stat _all_ * the files on the system). * * We run down the list of _new_ files in this package. This keeps * the process a little leaner. We are only worried about new ones * since ones that stayed the same don't really apply here. */ /* If we can't stat the old or new file, or it's a directory, * we leave it up to the normal code. */ debug(dbg_eachfile, "process_archive: checking %s for same files on " "upgrade/downgrade", fnamevb.buf); for (cfile= newfileslist; cfile; cfile= cfile->next) { /* If the file has been filtered then treat it as if it didn't exist * on the file system. */ if (cfile->namenode->flags & fnnf_filtered) continue; if (!cfile->namenode->filestat) { struct stat tmp_stat; varbuf_reset(&cfilename); varbuf_add_str(&cfilename, instdir); varbuf_add_char(&cfilename, '/'); varbuf_add_str(&cfilename, cfile->namenode->name); varbuf_end_str(&cfilename); if (lstat(cfilename.buf, &tmp_stat) == 0) { cfile->namenode->filestat = nfmalloc(sizeof(struct stat)); memcpy(cfile->namenode->filestat, &tmp_stat, sizeof(struct stat)); } else { if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR)) ohshite(_("unable to stat other new file `%.250s'"), cfile->namenode->name); cfile->namenode->filestat = &empty_stat; continue; } } if (cfile->namenode->filestat == &empty_stat) continue; if (oldfs.st_dev == cfile->namenode->filestat->st_dev && oldfs.st_ino == cfile->namenode->filestat->st_ino) { if (sameas) warning(_("old file '%.250s' is the same as several new files! " "(both '%.250s' and '%.250s')"), fnamevb.buf, sameas->namenode->name, cfile->namenode->name); sameas= cfile; debug(dbg_eachfile, "process_archive: not removing %s," " since it matches %s", fnamevb.buf, cfile->namenode->name); } } varbuf_destroy(&cfilename); if ((namenode->flags & fnnf_old_conff)) { if (sameas) { if (sameas->namenode->flags & fnnf_new_conff) { if (!strcmp(sameas->namenode->oldhash, NEWCONFFILEFLAG)) { sameas->namenode->oldhash= namenode->oldhash; debug(dbg_eachfile, "process_archive: old conff %s" " is same as new conff %s, copying hash", namenode->name, sameas->namenode->name); } else { debug(dbg_eachfile, "process_archive: old conff %s" " is same as new conff %s but latter already has hash", namenode->name, sameas->namenode->name); } } } else { debug(dbg_eachfile, "process_archive: old conff %s" " is disappearing", namenode->name); namenode->flags |= fnnf_obs_conff; newconff_append(&newconffileslastp, namenode); addfiletolist(&tc, namenode); } continue; } if (sameas) continue; if (secure_unlink_statted(fnamevb.buf, &oldfs)) { warning(_("unable to securely remove old file '%.250s': %s"), namenode->name, strerror(errno)); } } /* !S_ISDIR */ } /* OK, now we can write the updated files-in-this package list, * since we've done away (hopefully) with all the old junk. */ write_filelist_except(pkg, &pkg->available, newfileslist, 0); /* Trigger interests may have changed. * Firstly we go through the old list of interests deleting them. * Then we go through the new list adding them. */ strcpy(cidirrest, TRIGGERSCIFILE); trig_parse_ci(pkgadminfile(pkg, &pkg->installed, TRIGGERSCIFILE), trig_cicb_interest_delete, NULL, pkg, &pkg->installed); trig_parse_ci(cidir, trig_cicb_interest_add, NULL, pkg, &pkg->available); trig_file_interests_save(); /* We also install the new maintainer scripts, and any other * cruft that may have come along with the package. First * we go through the existing scripts replacing or removing * them as appropriate; then we go through the new scripts * (any that are left) and install them. */ debug(dbg_general, "process_archive updating info directory"); pkg_infodb_update(pkg, cidir, cidirrest); /* * Update the status database. * * This involves copying each field across from the ‘available’ * to the ‘installed’ half of the pkg structure. * For some of the fields we have to do a complicated construction * operation; for others we can just copy the value. * We tackle the fields in the order they appear, so that * we don't miss any out :-). * At least we don't have to copy any strings that are referred * to, because these are never modified and never freed. */ /* The dependencies are the most difficult. We have to build * a whole new forward dependency tree. At least the reverse * links (linking our deppossi's into the reverse chains) * can be done by copy_dependency_links. */ newdeplist = NULL; newdeplistlastp = &newdeplist; for (dep= pkg->available.depends; dep; dep= dep->next) { newdep= nfmalloc(sizeof(struct dependency)); newdep->up= pkg; newdep->next = NULL; newdep->list = NULL; newpossilastp = &newdep->list; for (possi= dep->list; possi; possi= possi->next) { newpossi= nfmalloc(sizeof(struct deppossi)); newpossi->up= newdep; newpossi->ed= possi->ed; newpossi->next = NULL; newpossi->rev_next = newpossi->rev_prev = NULL; newpossi->arch_is_implicit = possi->arch_is_implicit; newpossi->arch = possi->arch; newpossi->verrel= possi->verrel; if (possi->verrel != dvr_none) newpossi->version= possi->version; else blankversion(&newpossi->version); newpossi->cyclebreak = false; *newpossilastp= newpossi; newpossilastp= &newpossi->next; } newdep->type= dep->type; *newdeplistlastp= newdep; newdeplistlastp= &newdep->next; } /* Right, now we've replicated the forward tree, we * get copy_dependency_links to remove all the old dependency * structures from the reverse links and add the new dependency * structures in instead. It also copies the new dependency * structure pointer for this package into the right field. */ copy_dependency_links(pkg,&pkg->installed.depends,newdeplist,0); /* We copy the text fields. */ pkg->installed.essential= pkg->available.essential; pkg->installed.multiarch = pkg->available.multiarch; pkg->installed.description= pkg->available.description; pkg->installed.maintainer= pkg->available.maintainer; pkg->installed.source= pkg->available.source; pkg->installed.arch = pkg->available.arch; pkg->installed.installedsize= pkg->available.installedsize; pkg->installed.version= pkg->available.version; pkg->installed.origin = pkg->available.origin; pkg->installed.bugs = pkg->available.bugs; /* We have to generate our own conffiles structure. */ pkg->installed.conffiles = NULL; iconffileslastp = &pkg->installed.conffiles; for (cfile= newconffiles; cfile; cfile= cfile->next) { newiconff= nfmalloc(sizeof(struct conffile)); newiconff->next = NULL; newiconff->name= nfstrsave(cfile->namenode->name); newiconff->hash= nfstrsave(cfile->namenode->oldhash); newiconff->obsolete= !!(cfile->namenode->flags & fnnf_obs_conff); *iconffileslastp= newiconff; iconffileslastp= &newiconff->next; } /* We can just copy the arbitrary fields list, because it is * never even rearranged. Phew! */ pkg->installed.arbs= pkg->available.arbs; /* Check for disappearing packages: * We go through all the packages on the system looking for ones * whose files are entirely part of the one we've just unpacked * (and which actually *have* some files!). * * Any that we find are removed - we run the postrm with ‘disappear’ * as an argument, and remove their info/... files and status info. * Conffiles are ignored (the new package had better do something * with them!). */ it = pkg_db_iter_new(); while ((otherpkg = pkg_db_iter_next_pkg(it)) != NULL) { ensure_package_clientdata(otherpkg); if (otherpkg == pkg || otherpkg->status == stat_notinstalled || otherpkg->status == stat_configfiles || otherpkg->clientdata->istobe == itb_remove || !otherpkg->clientdata->files) continue; debug(dbg_veryverbose, "process_archive checking disappearance %s", pkg_name(otherpkg, pnaw_nonambig)); assert(otherpkg->clientdata->istobe == itb_normal || otherpkg->clientdata->istobe == itb_deconfigure); for (cfile= otherpkg->clientdata->files; cfile && !strcmp(cfile->namenode->name,"/."); cfile= cfile->next); if (!cfile) { debug(dbg_stupidlyverbose, "process_archive no non-root, no disappear"); continue; } for (cfile= otherpkg->clientdata->files; cfile && !filesavespackage(cfile,otherpkg,pkg); cfile= cfile->next); if (cfile) continue; /* So dependency things will give right answers ... */ otherpkg->clientdata->istobe= itb_remove; debug(dbg_veryverbose, "process_archive disappear checking dependencies"); for (pdep = otherpkg->set->depended.installed; pdep; pdep = pdep->rev_next) { if (pdep->up->type != dep_depends && pdep->up->type != dep_predepends && pdep->up->type != dep_recommends) continue; if (depisok(pdep->up, &depprobwhy, NULL, NULL, false)) continue; varbuf_end_str(&depprobwhy); debug(dbg_veryverbose,"process_archive cannot disappear: %s",depprobwhy.buf); break; } if (!pdep) { /* If we haven't found a reason not to yet, let's look some more. */ for (providecheck= otherpkg->installed.depends; providecheck; providecheck= providecheck->next) { if (providecheck->type != dep_provides) continue; for (pdep = providecheck->list->ed->depended.installed; pdep; pdep = pdep->rev_next) { if (pdep->up->type != dep_depends && pdep->up->type != dep_predepends && pdep->up->type != dep_recommends) continue; if (depisok(pdep->up, &depprobwhy, NULL, NULL, false)) continue; varbuf_end_str(&depprobwhy); debug(dbg_veryverbose,"process_archive cannot disappear (provides %s): %s", providecheck->list->ed->name, depprobwhy.buf); goto break_from_both_loops_at_once; } } break_from_both_loops_at_once:; } otherpkg->clientdata->istobe= itb_normal; if (pdep) continue; /* No, we're disappearing it. This is the wrong time to go and * run maintainer scripts and things, as we can't back out. But * what can we do ? It has to be run this late. */ pkg_disappear(otherpkg, pkg); } /* while (otherpkg= ... */ pkg_db_iter_free(it); /* Delete files from any other packages' lists. * We have to do this before we claim this package is in any * sane kind of state, as otherwise we might delete by mistake * a file that we overwrote, when we remove the package which * had the version we overwrote. To prevent this we make * sure that we don't claim this package is OK until we * have claimed ‘ownership’ of all its files. */ for (cfile= newfileslist; cfile; cfile= cfile->next) { struct filepackages_iterator *iter; struct pkgset *divpkgset; if (!(cfile->namenode->flags & fnnf_elide_other_lists)) continue; if (cfile->namenode->divert && cfile->namenode->divert->useinstead) { divpkgset = cfile->namenode->divert->pkgset; if (divpkgset == pkg->set) { debug(dbg_eachfile, "process_archive not overwriting any `%s' (overriding, `%s')", cfile->namenode->name, cfile->namenode->divert->useinstead->name); continue; } else { debug(dbg_eachfile, "process_archive looking for overwriting `%s' (overridden by %s)", cfile->namenode->name, divpkgset ? divpkgset->name : "<local>"); } } else { divpkgset = NULL; debug(dbg_eachfile, "process_archive looking for overwriting `%s'", cfile->namenode->name); } iter = filepackages_iter_new(cfile->namenode); while ((otherpkg = filepackages_iter_next(iter))) { debug(dbg_eachfiledetail, "process_archive ... found in %s", pkg_name(otherpkg, pnaw_nonambig)); /* If !fileslistvalid then it's one of the disappeared packages above * and we don't bother with it here, clearly. */ if (otherpkg == pkg || !otherpkg->clientdata->fileslistvalid) continue; if (otherpkg->set == divpkgset) { debug(dbg_eachfiledetail, "process_archive ... diverted, skipping"); continue; } /* Found one. We delete remove the list entry for this file, * (and any others in the same package) and then mark the package * as requiring a reread. */ write_filelist_except(otherpkg, &otherpkg->installed, otherpkg->clientdata->files, fnnf_elide_other_lists); ensure_package_clientdata(otherpkg); debug(dbg_veryverbose, "process_archive overwrote from %s", pkg_name(otherpkg, pnaw_nonambig)); } filepackages_iter_free(iter); } /* Right, the package we've unpacked is now in a reasonable state. * The only thing that we have left to do with it is remove * backup files, and we can leave the user to fix that if and when * it happens (we leave the reinstall required flag, of course). */ pkg_set_status(pkg, stat_unpacked); modstatdb_note(pkg); /* Now we delete all the backup files that we made when * extracting the archive - except for files listed as conffiles * in the new package. * This time we count it as an error if something goes wrong. * * Note that we don't ever delete things that were in the old * package as a conffile and don't appear at all in the new. * They stay recorded as obsolete conffiles and will eventually * (if not taken over by another package) be forgotten. */ for (cfile= newfileslist; cfile; cfile= cfile->next) { if (cfile->namenode->flags & fnnf_new_conff) continue; varbuf_trunc(&fnametmpvb, fnameidlu); varbuf_add_str(&fnametmpvb, namenodetouse(cfile->namenode, pkg, &pkg->installed)->name); varbuf_add_str(&fnametmpvb, DPKGTEMPEXT); varbuf_end_str(&fnametmpvb); ensure_pathname_nonexisting(fnametmpvb.buf); } /* OK, we're now fully done with the main package. * This is quite a nice state, so we don't unwind past here. */ pkg_reset_eflags(pkg); modstatdb_note(pkg); push_checkpoint(~ehflag_bombout, ehflag_normaltidy); /* Only the removal of the conflictor left to do. * The files list for the conflictor is still a little inconsistent in-core, * as we have not yet updated the filename->packages mappings; however, * the package->filenames mapping is. */ for (i = 0 ; i < cflict_index ; i++) { /* We need to have the most up-to-date info about which files are * what ... */ ensure_allinstfiles_available(); removal_bulk(conflictor[i]); } if (cipaction->arg_int == act_install) add_to_queue(pkg); }
void addPath(const char *path, int squash_uids, int squash_perms) { size_t len; char *full_name = NULL, *lnk = NULL; struct dirent *file = NULL; DIR *direc = NULL; struct stat st; int overWrite; __u16 inodeType; direc = opendir(path); if ( !direc ) log_error("[Local fs opendir] Cannot open directory %s", path); while (( file = readdir(direc)) != NULL ) { if (( !strcmp(file->d_name, "." )) || ( !strcmp(file->d_name, ".." ))) continue; len = strlen(path) + strlen( file->d_name ) + 3; if ( full_name ) { free( full_name ); full_name = NULL; } full_name = (char*)malloc(len + 2); if ( !full_name ) log_error("[Local fs stat] Memory allocation error ( full_name --> %s/%s )", path, file->d_name); memset(full_name, 0, len + 2); snprintf(full_name, len, "%s/%s", path, file->d_name); lstat(full_name, &st); mode_t fmt = st.st_mode & S_IFMT; if ( squash_uids ) st.st_uid = st.st_gid = 0; if ( squash_perms ) st.st_mode &= ~( LINUX_S_IRWXG | LINUX_S_IRWXO ); overWrite = name_to_inode( file->d_name ); if ( st.st_nlink > 1 ) { if (( lnk = linklist_add(st.st_dev, st.st_ino, full_name + modPath_path_len))) { if ( overWrite ) { log_action(ACT_RM, file->d_name, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !do_rm(file->d_name)) log_error("[Filesystem error] cannot rm %s/%s", log_cwd(), file->d_name); } log_action(ACT_HARDLINK, file->d_name, lnk, 0, 0, 0, 0, 0, 0, overWrite); if (!do_hardlink(&st, lnk, file->d_name)) log_error("[Filesystem error] cannot hardlink %s --> %s", file->d_name, lnk); continue; } } if ( overWrite ) inodeType = inode_mode( file->d_name ); if (( fmt == S_IFDIR ) && ( overWrite ) && ( !LINUX_S_ISDIR(inodeType))) log_error("[Remote fs mismatch] %s/%s exists but isn't a directory when it should be.", log_cwd(), file->d_name); else if (( fmt != S_IFDIR) && ( overWrite )) { if ( LINUX_S_ISDIR(inodeType)) log_error("[Remote fs mismatch] %s/%s exists but is a directory when it shouldn't be.", log_cwd(), file->d_name); if ((!LINUX_S_ISREG(inodeType)) && (!LINUX_S_ISLNK(inodeType)) && (!LINUX_S_ISBLK(inodeType)) && (!LINUX_S_ISCHR(inodeType)) && (!LINUX_S_ISFIFO(inodeType)) && (!LINUX_S_ISSOCK(inodeType))) log_error("[Remote fs mismatch] Existing file %s/%s has unknown/unsupported type [0x%x].", log_cwd(), file->d_name); } switch ( fmt ) { case S_IFDIR: // Directory log_action(ACT_MKDIR, file->d_name, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !overWrite ) if ( !do_mkdir( &st, file->d_name )) log_error("[Filesystem error] cannot mkdir %s/%s", log_cwd(), file->d_name); log_action(ACT_CHMODE, file->d_name, NULL, st.st_mode, 0, 0, 0, 0, 0, overWrite); if ( !do_chmode(file->d_name, st.st_mode)) log_error("[Filesystem error] Failed to chmode 0x%x for directory %s/%s", st.st_mode, log_cwd(), file->d_name); log_action(ACT_CHOWN, file->d_name, NULL, 0, st.st_uid, st.st_gid, 0, 0, 0, 0); if ( !do_chown(file->d_name, st.st_uid, st.st_gid)) log_error("[Filesystem error] Failed to chown %ld, %ld for directory %s/%s", st.st_uid, st.st_gid, log_cwd(), file->d_name); log_action(ACT_CHDIR, file->d_name, NULL, 0, 0, 0, 0, 0, 0, 0); if ( !do_chdir( file->d_name )) log_error("[Filesystem error] cannot chdir to newly created %s/%s", log_cwd(), file->d_name); addPath(full_name, squash_uids, squash_perms); log_action(ACT_CHDIR, "..", NULL, 0, 0, 0, 0, 0, 0, 0); if ( !do_chdir("..")) log_error("[Filesystem error] cannot chdir to parent directory"); break; case S_IFREG: // Regular file if ( overWrite ) { log_action(ACT_RM, file->d_name, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !do_rm(file->d_name)) log_error("[Filesystem error] cannot rm %s/%s", log_cwd(), file->d_name); } log_action(ACT_WRITE, file->d_name, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !do_write(full_name, file->d_name)) log_error("[Filesystem error] cannot write %s/%s", log_cwd(), file->d_name); break; case S_IFLNK: // Symbolic link lnk = (char*)malloc(MAX_PATHSIZE + 2); if ( !lnk ) log_error("[symlink] Memory allocation error (lnk)"); int len = readlink(full_name, lnk, MAX_PATHSIZE); if ( len == -1 ) { free(lnk); log_error("[Local filesystem error] Cannot read destination for link %s/%s", log_cwd(), file->d_name); } else lnk[len] = '\0'; if ( overWrite ) { log_action(ACT_RM, file->d_name, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !do_rm(file->d_name)) log_error("[Filesystem error] cannot rm %s/%s", log_cwd(), file->d_name); } log_action(ACT_SYMLINK, file->d_name, lnk, 0, 0, 0, 0, 0, 0, overWrite); if ( !do_symlink(&st, lnk, file->d_name)) log_error("[Filesystem error] cannot symlink %s/%s --> %s", log_cwd(), file->d_name, lnk); free(lnk); break; case S_IFBLK: // Block device node case S_IFCHR: // Character device node case S_IFSOCK: // socket case S_IFIFO: // fifo if ( overWrite ) { log_action(ACT_RM, file->d_name, NULL, 0, 0, 0, 0, 0, 0, overWrite); if ( !do_rm(file->d_name)) log_error("[Filesystem error] cannot rm %s/%s", log_cwd(), file->d_name); } char nodetype = ( fmt == S_IFBLK ? 'b' : ( fmt == S_IFCHR ? 'c' : ( fmt == S_IFSOCK ? 's' : 'p' ))); unsigned long major = 0, minor = 0; if (( nodetype == 'b' ) || ( nodetype == 'c' )) { major = (long)major(st.st_rdev); minor = (long)minor(st.st_rdev); } log_action(ACT_MKNOD, file->d_name, NULL, 0, 0, 0, nodetype, major, minor, overWrite); if ( !do_mknod(file->d_name, nodetype, major, minor)) log_error("[Filesystem error] cannot mknod %c %ld,%ld %s/%s", log_cwd(), nodetype, major, minor, log_cwd(), file->d_name); break; } if ( fmt != S_IFDIR ) { // Not dir ? log_action(ACT_CHMODE, file->d_name, NULL, st.st_mode, 0, 0, 0, 0, 0, overWrite); if ( !do_chmode(file->d_name, st.st_mode)) log_error("[Filesystem error] Failed to chmode 0x%x for file %s/%s", st.st_mode, log_cwd(), file->d_name); log_action(ACT_CHOWN, file->d_name, NULL, 0, st.st_uid, st.st_gid, 0, 0, 0, 0); if ( !do_chown(file->d_name, st.st_uid, st.st_gid)) log_error("[Filesystem error] Failed to chown %ld, %ld for file %s/%s", st.st_uid, st.st_gid, log_cwd(), file->d_name); } if ( full_name ) { free( full_name ); full_name = NULL; } } closedir(direc); }
xmlNode * do_calculations(pe_working_set_t * data_set, xmlNode * xml_input, crm_time_t * now) { GListPtr gIter = NULL; int rsc_log_level = LOG_INFO; /* pe_debug_on(); */ CRM_ASSERT(xml_input || is_set(data_set->flags, pe_flag_have_status)); if (is_set(data_set->flags, pe_flag_have_status) == FALSE) { set_working_set_defaults(data_set); data_set->input = xml_input; data_set->now = now; } else { crm_trace("Already have status - reusing"); } if (data_set->now == NULL) { data_set->now = crm_time_new(NULL); } crm_trace("Calculate cluster status"); stage0(data_set); if(is_not_set(data_set->flags, pe_flag_quick_location)) { gIter = data_set->resources; for (; gIter != NULL; gIter = gIter->next) { resource_t *rsc = (resource_t *) gIter->data; if (is_set(rsc->flags, pe_rsc_orphan) && rsc->role == RSC_ROLE_STOPPED) { continue; } rsc->fns->print(rsc, NULL, pe_print_log, &rsc_log_level); } } crm_trace("Applying placement constraints"); stage2(data_set); if(is_set(data_set->flags, pe_flag_quick_location)){ return NULL; } crm_trace("Create internal constraints"); stage3(data_set); crm_trace("Check actions"); stage4(data_set); crm_trace("Allocate resources"); stage5(data_set); crm_trace("Processing fencing and shutdown cases"); stage6(data_set); crm_trace("Applying ordering constraints"); stage7(data_set); crm_trace("Create transition graph"); stage8(data_set); crm_trace("=#=#=#=#= Summary =#=#=#=#="); crm_trace("\t========= Set %d (Un-runnable) =========", -1); if (get_crm_log_level() >= LOG_TRACE) { gIter = data_set->actions; for (; gIter != NULL; gIter = gIter->next) { action_t *action = (action_t *) gIter->data; if (is_set(action->flags, pe_action_optional) == FALSE && is_set(action->flags, pe_action_runnable) == FALSE && is_set(action->flags, pe_action_pseudo) == FALSE) { log_action(LOG_TRACE, "\t", action, TRUE); } } } return data_set->graph; }