static void cleanup(void) { (void) chdir("/"); if (tmpdir) { (void) rrmdir(tmpdir); free(tmpdir); tmpdir = NULL; } if (tmppath) { /* remove any previous tmppath stuff */ (void) rrmdir(tmppath); free(tmppath); tmppath = NULL; } if (tmpsymdir) { /* remove temp symbolic links made for signed pkg */ (void) rrmdir(tmpsymdir); free(tmpsymdir); tmpsymdir = NULL; } if (srcdev.mount && !ids_name) (void) pkgumount(&srcdev); if (dstdev.mount && !ods_name) (void) pkgumount(&dstdev); (void) ds_close(1); }
void quit(int retcode) { (void) signal(SIGINT, SIG_IGN); (void) signal(SIGHUP, SIG_IGN); if (retcode == 3) (void) fprintf(stderr, gettext(MSG_TERM)); else if (retcode) (void) fprintf(stderr, gettext(MSG_ERROR)); else (void) fprintf(stderr, gettext(MSG_COMPLETE)); if (retcode && started) (void) rrmdir(pkgloc); /* clean up output directory */ if (pkgdev.mount) (void) pkgumount(&pkgdev); if (t_pkgmap) (void) unlink(t_pkgmap); if (t_pkginfo) (void) unlink(t_pkginfo); exit(retcode); }
int bbdocument_deletecoll(char collection[]) { int LotNr; int i; char FilePath[512]; char IndexPath[512]; char DictionaryPath[512]; FILE *fh; debug("Deleting collection: \"%s\"\n",collection); LotNr = 1; while((fh =lotOpenFileNoCasheByLotNr(LotNr,"reposetory","r",'s',collection)) != NULL) { GetFilPathForLot(FilePath,LotNr,collection); fclose(fh); rrmdir(FilePath); ++LotNr; } for (i=0; i < 64; i++) { GetFilePathForIindex(FilePath,IndexPath,i,"Main","aa",collection); #ifdef DEBUG printf("FilePath: %s\nIndexPath: %s\n",FilePath,IndexPath); #endif if ((unlink(IndexPath) != 1) && (errno != ENOENT)) { //ENOENT=No such file or directory. Viser ikke feil hvis filen ikke fantes. Det er helt normalt perror("remove IndexPath"); } GetFilePathForIDictionary(FilePath,DictionaryPath,i,"Main","aa",collection); #ifdef DEBUG printf("FilePath: %s\nDictionaryPath: %s\n",FilePath,DictionaryPath); #endif if ((unlink(DictionaryPath) != 0) && (errno != ENOENT)) {//ENOENT=No such file or directory. Viser ikke feil hvis filen ikke fantes. Det er helt normalt perror("remove DictionaryPath"); } } //sletter i userToSubname.db struct userToSubnameDbFormat userToSubnameDb; if (!userToSubname_open(&userToSubnameDb,'w')) { printf("can't open users.db\n"); } else { userToSubname_deletecol(&userToSubnameDb,collection); userToSubname_close(&userToSubnameDb); } return 1; }
static int ckoverwrite(char *dir, char *inst, int options) { char path[PATH_MAX]; (void) snprintf(path, sizeof (path), "%s/%s", dir, inst); if (access(path, 0) == 0) { if (options & PT_OVERWRITE) return (rrmdir(path)); progerr(pkg_gt(ERR_TRANSFER)); logerr(pkg_gt(MSG_EXISTS), path); return (1); } return (0); }
/* * Name: fmkdir * Description: force the creation of a directory, even if the current * node exists and is not a directory * Arguments: a_path - pointer to string representing the path to the * directory to create * a_mode - mode(2) bits to set the path to if created * returns: 0 - directory created * 1 - could not remove existing non-directory node * 2 - could not create specified new directory */ int fmkdir(char *a_path, int a_mode) { if (access(a_path, F_OK) == 0) { if (rrmdir(a_path) != 0) { return (1); } } if (mkdir(a_path, a_mode) != 0) { return (2); } return (0); }
int main(int argc, char **argv) { char word[MAXWORD+1]; int cmd; int wrdlen; if(argc >= 2) { handle = clnt_create(argv[1], DIRPROG, DIRVERS, "tcp"); } else{ handle = clnt_create(RMACHINE, DIRPROG, DIRVERS, "tcp"); } if (handle == NULL) { printf("cound not contact remote program.\n"); exit(1); } while (1) { scanf("%d",&cmd); if(cmd == 10) exit(0); scanf("%s",word); switch(cmd) { case 1: rmkdir(word); printf("mkdir dir %s\n",word); break; case 2: rrmdir(word); printf("rmdir dir %s\n",word); break; case 10: printf("program quits.\n"); exit(0); default: printf("command %d invalid.\n", cmd); break; } } return 0; }
void quit(int retcode) { /* disable interrupts */ (void) signal(SIGINT, SIG_IGN); (void) signal(SIGHUP, SIG_IGN); /* process return code if not quit(99) */ if (retcode != 99) { if (ckreturnFunc != (ckreturnFunc_t *)NULL) { (ckreturnFunc)(retcode); } if (failflag) { retcode = 1; } else if (warnflag) { retcode = 2; } else if (intrflag) { retcode = 3; } else if (admnflag) { retcode = 4; } else if (nullflag) { retcode = 5; } else { retcode = 0; } if (ireboot) { retcode += 20; } if (doreboot) { retcode += 10; } } if (doreboot || ireboot) { ptext(stderr, gettext(MSG_REBOOT)); } if (pkgdev.mount) { (void) chdir("/"); (void) pkgumount(&pkgdev); } /* if set remove zone temporary directory */ if (zoneTempDir != (char *)NULL) { echoDebug(DBG_REMOVING_ZONE_TMPDIR, zoneTempDir); (void) rrmdir(zoneTempDir); zoneTempDir = (char *)NULL; } /* * issue final exit message depending on number of packages left * to process */ if (npkgs == 1) { echo(MSG_1_PKG_NOT_PROCESSED); } else if (npkgs) { echo(MSG_N_PKGS_NOT_PROCESSED, npkgs); } /* call intf_reloc function if registered */ if (intfRelocFunc != (intfRelocFunc_t *)NULL) { (intfRelocFunc)(); } /* if a zone list exists, unlock all zones */ if (zoneList != (zoneList_t)NULL) { (void) z_unlock_zones(zoneList, ZLOCKS_ALL); } else { (void) z_unlock_this_zone(ZLOCKS_ALL); } /* final exit debugging message */ echoDebug(DBG_EXIT_WITH_CODE, retcode); exit(retcode); /* NOTREACHED */ }
/* --- entry point --- */ int mathtex ( char *expression, char *filename ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ /* --- latex wrapper document template --- */ char latexwrapper[MAXEXPRSZ+16384] = "\\documentclass[10pt]{article}\n" "\\usepackage[latin1]{inputenc}\n" "\\usepackage{amsmath}\n" "\\usepackage{amsfonts}\n" "\\usepackage{amssymb}\n" /*"\\usepackage{bm}\n"*/ /* bold math */ #if defined(USEPACKAGE) /* cc -DUSEPACKAGE=\"filename\" */ #include USEPACKAGE /* filename with \usepackage{}'s */ #endif /* or anything for the preamble */ "%%usepackage%%\n" #if 0 "\\def\\stackboxes#1{\\vbox{\\def\\\\{\\egroup\\hbox\\bgroup}" "\\hbox\\bgroup#1\\egroup}}\n" "\\def\\fparbox#1{\\fbox{\\stackboxes{#1}}}\n" #endif "%%%\\pagestyle{empty}\n" "%%pagestyle%%\n" "%%previewenviron%%\n" "\\begin{document}\n" "%%%\\renewcommand{\\input}[1]" /* don't let users \input{} */ "{\\mbox{[[$\\backslash$input\\{#1\\} illegal]]}}\n" #if defined(NEWCOMMAND) /* cc -DNEWCOMMAND=\"filename\" */ #include NEWCOMMAND /* filename with \newcommand{}'s */ #endif /* or anything for the document */ "%%fontsize%%\n" "%%beginmath%% " "%%expression%% \n" /* \n in case expression contains %*/ " %%endmath%%\n" "\\end{document}\n"; char errormsg[1024] = /* latex runs but can't make .dvi */ "\\fbox{\\footnotesize $\\mbox{Latex failed, probably due to} " "\\atop \\mbox{an error in your expression.}$}"; char usepackage[1024] = "\000"; /* additional \usepackage{}'s */ char convertargs[1024] = /* args/switches for convert */ " -density %%dpi%% -gamma %%gamma%%" /*" -border 0% -fuzz 2%"*/ " -trim -transparent \"#FFFFFF\" "; char dvipngargs[1024] = /* args/switches for dvipng */ " --%%imagetype%% -D %%dpi%% --gamma %%gamma%%" " -bg Transparent -T tight -v" /* -q for quiet, -v for verbose */ " -o %%giffile%% "; /* output filename supplied as -o */ /* --- other variables --- */ static int iserror = 0; /* true if procesing error message */ //int setpaths(); /* set paths for latex,dvipng,etc */ char *makepath(); char latexfile[256],giffile[256]="\000"; /*path/filename.ext*/ FILE *latexfp = NULL; /* latex wrapper file for expression*/ char command[2048], subcommand[1024]; /* system(command) runs latex, etc */ char *beginmath[] = { "\\[", "$", " " }, /* start math mode */ *endmath[] = { "\\]", "$", " " }; /* end math mode */ int perm_all = (S_IRWXU|S_IRWXG|S_IRWXO); /* 777 permissions */ int dir_stat = 0; /* 1=mkdir okay, 2=chdir okay */ int sys_stat = 0; /* system() return status */ int isdexists(), isfexists(), /* check if dir, .dvi file created */ isnotfound(); /* check .err file for "not found" */ int strreplace(); /* replace template directives */ int ipackage = 0; /* packages[] index 0...npackages-1*/ int rrmdir(); /* rm -r */ int gifpathlen = 0; /* ../ or ../../ prefix of giffile */ int status = 0; /* imagetype or 0=error */ //int timelimit(); /* and using built-in timelimit() */ /* ------------------------------------------------------------------------- Make temporary work directory and change to it -------------------------------------------------------------------------- */ msgnumber = 0; /* no error to report yet */ if ( !isdexists(tempdir/*filename*/) ) /* if temp directory doesn't exist */ if ( mkdir(tempdir/*filename*/,perm_all) /* make temp dirextory */ != 0 ) { /* mkdir failed */ msgnumber = MKDIRFAILED; /* set corresponding message number*/ goto end_of_job; } /* and quit */ dir_stat++; /* signal mkdir successful */ if ( chdir(tempdir/*filename*/) /* cd to temp directory */ != 0 ) { /* cd failed */ msgnumber = CHDIRFAILED; /* set corresponding message number*/ goto end_of_job; } /* and quit */ dir_stat++; /* signal chdir successful */ /* ------------------------------------------------------------------------- set up latex directives for user-specified additional \usepackage{}'s -------------------------------------------------------------------------- */ if ( !iserror ) /* don't \usepackage for error */ if ( npackages > 0 ) /* have additional packages */ for ( ipackage=0; ipackage<npackages; ipackage++ ) { /*make \usepackage{}*/ strcat(usepackage,"\\usepackage"); /* start with a directive */ if ( !isempty(packargs[ipackage]) ) { /* have an optional arg */ strcat(usepackage,"["); /* begin optional argument */ strcat(usepackage,packargs[ipackage]); /* add optional arg */ strcat(usepackage,"]"); } /* finish optional arg */ strcat(usepackage,"{"); /* begin package name argument */ strcat(usepackage,packages[ipackage]); /* add package name */ strcat(usepackage,"}\n"); } /* finish constructing directive */ /* ------------------------------------------------------------------------- Replace "keywords" in latex template with expression and other directives -------------------------------------------------------------------------- */ /* --- replace %%pagestyle%% with \pagestyle{empty} if not a picture --- */ if ( !ispicture ) /* not \begin{picture} environment */ strreplace(latexwrapper,"%%pagestyle%%","\\pagestyle{empty}",1,0); /* --- replace %%previewenviron%% if a picture --- */ if ( ispicture ) /* have \begin{picture} environment */ strreplace(latexwrapper,"%%previewenviron%%", "\\PreviewEnvironment{picture}",1,0); /* --- replace %%beginmath%%...%%endmath%% with \[...\] or with $...$ --- */ if ( mathmode<0 || mathmode>2 ) mathmode=0; /* mathmode validity check */ strreplace(latexwrapper,"%%beginmath%%",beginmath[mathmode],1,0); strreplace(latexwrapper,"%%endmath%%",endmath[mathmode],1,0); /* --- replace %%fontsize%% in template with \tiny...\Huge --- */ strreplace(latexwrapper,"%%fontsize%%",sizedirectives[fontsize],1,0); /* --- replace %%usepackage%% in template with extra \usepackage{}'s --- */ strreplace(latexwrapper,"%%usepackage%%",usepackage,1,0); /* --- replace %%expression%% in template with expression --- */ strreplace(latexwrapper,"%%expression%%",expression,1,0); /* ------------------------------------------------------------------------- Create latex document wrapper file containing expression -------------------------------------------------------------------------- */ strcpy(latexfile,makepath("","latex",".tex")); /* latex filename latex.tex */ latexfp = fopen(latexfile,"w"); /* open latex file for write */ if ( latexfp == NULL ) { /* couldn't open latex file */ msgnumber = FOPENFAILED; /* set corresponding message number*/ goto end_of_job; } /* and quit */ fprintf(latexfp,"%s",latexwrapper); /* write file */ fclose(latexfp); /* close file after writing it */ /* ------------------------------------------------------------------------- Set paths to programs we'll need to run -------------------------------------------------------------------------- */ setpaths(10*latexmethod+imagemethod); /* ------------------------------------------------------------------------- Execute the latex file -------------------------------------------------------------------------- */ /* --- initialize system(command); to execute the latex file --- */ *command = '\000'; /* init command as empty string */ /* --- run latex under timelimit if explicitly given -DTIMELIMIT switch --- */ if ( istimelimitpath /* given explict -DTIMELIMIT path */ && warntime > 0 /* and positive warntime, and... */ && !iscompiletimelimit ) { /* not using built-in timelimit() */ if ( killtime < 1 ) killtime=1; /* don't make trouble for timelimit*/ strcat(command,makepath("",timelimitpath,NULL)); /* timelimit program */ if ( isempty(command) ) /* no path to timelimit */ warntime = (-1); /*reset flag to signal no timelimit*/ else { /* have path to timelimit program */ sprintf(command+strlen(command), /* add timelimit args after path */ " -t%d -T%d ",warntime,killtime); } } /* --- end-of-if(warntime>0) --- */ /* --- path to latex executable image followed by args --- */ if ( latexmethod != 2 ) /* not explicitly using pdflatex */ strcpy(subcommand,makepath("",latexpath,NULL)); /* running latex program */ else /* explicitly using pdflatex */ strcpy(subcommand,makepath("",pdflatexpath,NULL)); /* running pdflatex */ if ( isempty(subcommand) ) { /* no program path to latex */ msgnumber = SYLTXFAILED; /* set corresponding error message */ goto end_of_job; } /* signal failure and emit error */ strcat(command,subcommand); /* add latex path (after timelimit)*/ strcat(command," "); /* add a blank before latex args */ strcat(command,latexfile); /* run on latexfile we just wrote */ if ( isquiet > 0 ) { /* to continue after latex error */ if ( isquiet > 99 ) /* explicit q requested */ system("echo \"q\" > reply.txt"); /* reply q to latex error prompt */ else { /* reply <Enter>'s followed by x */ int nquiet = isquiet; /* this many <Enter>'s before x */ FILE *freply =fopen("reply.txt","w"); /* open reply.txt for write */ if ( freply != NULL ) { /* opened successfully */ while ( --nquiet >= 0 ) /* nquiet times... */ fputs("\n",freply); /* ...write <Enter> to reply.txt */ fputs("x",freply); /* finally followed by an x */ fclose(freply); } } /* close reply.txt */ strcat(command," < reply.txt"); } /*by redirecting stdin to reply.txt*/ else strcat(command," < /dev/null"); /* or redirect stdin to /dev/null */ strcat(command," >latex.out 2>latex.err"); /* redirect stdout and stderr */ showmsg(5,"latex command executed",command); /* show latex command executed*/ /* --- execute the latex file --- */ sys_stat = timelimit(command,killtime); /* throttle the latex command */ if ( msgfp!=NULL && msglevel>=3 ) /* and show command's return status*/ fprintf(msgfp,"\nmathTeX> system() return status: %d\n", sys_stat); if ( latexmethod != 2 ) /* ran latex */ if ( !isfexists(makepath("","latex",".dvi")) ) /* but no latex dvi */ sys_stat = (-1); /* signal that latex failed */ if ( latexmethod == 2 ) /* ran pdflatex */ if ( !isfexists(makepath("","latex",".pdf")) ) /* but no pdflatex pdf */ sys_stat = (-1); /* signal that pdflatex failed */ if ( sys_stat == (-1) ) { /* system() or pdf/latex failed */ if ( !iserror ) { /* don't recurse if errormsg fails */ iserror = 1; /* set error flag */ status = mathtex(errormsg,filename); /* recurse just once for error msg*/ goto end_of_job; } /* ignore original expression */ else { /* ignore 2nd try to recurse */ msgnumber = /* set corresponding message number*/ (sys_stat==(-1)?SYLTXFAILED: /* system() failed */ (isnotfound("latex")?SYLTXFAILED: /* latex program not found */ LATEXFAILED)); /* latex ran but failed */ goto end_of_job; } /* and quit */ } /* --- end-of-if(system()==-1||!isfexists()) --- */ /* ------------------------------------------------------------------------- Construct the output path/filename.[gif,png] for the image file -------------------------------------------------------------------------- */ if ( isempty(outfile) /* using default cache directory */ || !isthischar(*outfile,"/\\") ) { /* or just given a relative path */ strcpy(giffile,"../"); /* output file will be in cache */ if ( iserror ) strcat(giffile,"../"); /* we're in error subdirectory */ gifpathlen = strlen(giffile); } /* #chars in ../ or ../../ prefix */ if ( isempty(outfile) ) /* using default output filename */ strcat(giffile,makepath(NULL,filename,extensions[imagetype])); else /* have an explicit output file */ strcat(giffile,makepath("",outfile,extensions[imagetype])); showmsg(3,"output image file",giffile+gifpathlen); /* show output filename */ /* ------------------------------------------------------------------------- Run dvipng for .dvi-to-gif/png -------------------------------------------------------------------------- */ if ( imagemethod == 1 ) { /*dvipng method requested (default)*/ /* --- * First replace "keywords" in dvipngargs template with actual values *------------------------------------------------------------------- */ /* --- replace %%imagetype%% in dvipng arg template with gif or png --- */ strreplace(dvipngargs,"%%imagetype%%",extensions[imagetype],1,0); /* --- replace %%dpi%% in dvipng arg template with actual dpi --- */ strreplace(dvipngargs,"%%dpi%%",density,1,0); /* --- replace %%gamma%% in dvipng arg template with actual gamma --- */ strreplace(dvipngargs,"%%gamma%%",gamma,1,0); /* --- replace %%giffile%% in dvipng arg template with actual giffile --- */ strreplace(dvipngargs,"%%giffile%%",giffile,1,0); /* --- * And run dvipng to convert .dvi file directly to .gif/.png *---------------------------------------------------------- */ strcpy(command,makepath("",dvipngpath,NULL)); /* running dvipng program */ if ( isempty(command) ) { /* no program path to dvipng */ msgnumber = SYPNGFAILED; /* set corresponding error message */ goto end_of_job; } /* signal failure and emit error */ strcat(command,dvipngargs); /* add dvipng switches */ strcat(command,makepath("","latex",".dvi")); /* run dvipng on latex.dvi */ strcat(command," >dvipng.out 2>dvipng.err"); /* redirect stdout, stderr */ showmsg(5,"dvipng command executed",command); /* dvipng command executed */ sys_stat = system(command); /* execute the dvipng command */ if ( sys_stat == (-1) /* system(dvipng) failed */ || !isfexists(giffile) ) { /*or dvipng failed to create giffile*/ msgnumber = /* set corresponding message number*/ (sys_stat==(-1)?SYPNGFAILED: /* system() failed */ (isnotfound("dvipng")?SYPNGFAILED: /* dvipng program not found */ DVIPNGFAILED)); /* dvipng ran but failed */ goto end_of_job; } /* and quit */ } /* --- end-of-if(imagemethod==1) --- */ /* ------------------------------------------------------------------------- Run dvips for .dvi-to-postscript and convert for postscript-to-gif/png -------------------------------------------------------------------------- */ if ( imagemethod == 2 ) { /* dvips/convert method requested */ /* --- * First run dvips to convert .dvi file to .ps postscript *------------------------------------------------------- */ if ( latexmethod != 2 ) { /* only if not using pdflatex */ strcpy(command,makepath("",dvipspath,NULL)); /* running dvips program */ if ( isempty(command) ) { /* no program path to dvips */ msgnumber = SYPSFAILED; /* set corresponding error message */ goto end_of_job; } /* signal failure and emit error */ strcat(command," -E "); /* add -E switch and a blank */ strcat(command,makepath("","latex",".dvi")); /* run dvips on latex.dvi */ strcat(command," -o "); /* to produce output in */ strcat(command,makepath("","dvips",".ps")); /*dvips.ps postscript file*/ strcat(command," >dvips.out 2>dvips.err"); /* redirect stdout, stderr */ showmsg(5,"dvips command executed",command); /* dvips command executed */ sys_stat = system(command); /* execute system(dvips) */ if ( sys_stat == (-1) /* system(dvips) failed */ || !isfexists(makepath("","dvips",".ps")) ) { /*dvips didn't create .ps*/ msgnumber = /* set corresponding message number*/ (sys_stat==(-1)?SYPSFAILED: /* system() failed */ (isnotfound("dvips")?SYPSFAILED: /* dvips program not found */ DVIPSFAILED)); /* dvips ran but failed */ goto end_of_job; } /* and quit */ } /* --- end-of-if(latexmethod!=2) --- */ /* --- * Then replace "keywords" in convertargs template with actual values *------------------------------------------------------------------- */ /* --- replace %%dpi%% in convert arg template with actual density --- */ strreplace(convertargs,"%%dpi%%",density,1,0); /* --- replace %%gamma%% in convert arg template with actual gamma --- */ strreplace(convertargs,"%%gamma%%",gamma,1,0); /* --- * And run convert to convert .ps file to .gif/.png *-------------------------------------------------- */ strcpy(command,makepath("",convertpath,NULL)); /*running convert program*/ if ( isempty(command) ) { /* no program path to convert */ msgnumber = SYCVTFAILED; /* set corresponding error message */ goto end_of_job; } /* signal failure and emit error */ strcat(command,convertargs); /* add convert switches */ if ( latexmethod != 2 ) /* we ran latex and dvips */ strcat(command,makepath("","dvips",".ps")); /* convert from postscript */ if ( latexmethod == 2 ) /* we ran pdflatex */ strcat(command,makepath("","latex",".pdf")); /* convert from pdf */ strcat(command," "); /* field separator */ strcat(command,giffile); /* followed by ../cache/filename */ strcat(command," >convert.out 2>convert.err"); /*redirect stdout, stderr*/ showmsg(5,"convert command executed",command); /*convert command executed*/ sys_stat = system(command); /* execute system(convert) command */ if ( sys_stat == (-1) /* system(convert) failed */ || !isfexists(giffile) ) { /* or convert didn't create giffile*/ msgnumber = /* set corresponding message number*/ (sys_stat==(-1)?SYCVTFAILED: /* system() failed */ (isnotfound("convert")?SYCVTFAILED: /* convert program not found */ CONVERTFAILED)); /* convert ran but failed */ goto end_of_job; } /* and quit */ } /* --- end-of-if(imagemethod==2) --- */ status = imagetype; /* signal success */ /* ------------------------------------------------------------------------- Back to caller -------------------------------------------------------------------------- */ end_of_job: if ( dir_stat >= 2 ) chdir(".."); /* return up to original dir */ if ( dir_stat >= 1 ) rrmdir(tempdir/*filename*/); /*rm -r temp working dir*/ iserror = 0; /* always reset error flag */ return ( status ); } /* --- end-of-function mathtex() --- */
void quit(int retcode) { /* disable interrupts */ (void) signal(SIGINT, SIG_IGN); (void) signal(SIGHUP, SIG_IGN); /* process return code if not quit(99) */ if (retcode != 99) { if ((retcode % 10) == 0) { if (failflag) { retcode += 1; } else if (warnflag) { retcode += 2; } } if (ireboot) { retcode = (retcode % 10) + 20; } if (dreboot) { retcode = (retcode % 10) + 10; } } /* if set remove dstream temporary directory */ if (dstreamTempDir != (char *)NULL) { echoDebug(DBG_REMOVING_DSTREAM_TMPDIR, dstreamTempDir); (void) rrmdir(dstreamTempDir); dstreamTempDir = (char *)NULL; } /* If we're in dryrun mode, write out the dryrun file(s). */ if (in_dryrun_mode()) { char exit_msg[200]; set_dr_info(EXITCODE, retcode); if (failflag || warnflag) { set_dr_exitmsg(msgtext); } else { /* LINTED variable format specified */ (void) snprintf(exit_msg, sizeof (exit_msg), qreason(1, retcode, installStarted, includeZonename), (pkginst ? pkginst : "unknown"), zoneName); set_dr_exitmsg(exit_msg); } write_dryrun_file(extlist); ptext(stderr, MSG_DRYRUN_DONE); ptext(stderr, MSG_NOCHANGE); if (tmpdir[0] != NULL) (void) rrmdir(tmpdir); } else { /* fix bug #1082589 that deletes root file */ if (tmpdir[0] != NULL) { (void) rrmdir(tmpdir); } /* send mail to appropriate user list */ mailmsg(retcode); /* display message about this installation */ quitmsg(retcode); } /* * In the event that this quit() was called prior to completion of * the task, do an unlockinst() just in case. */ unlockinst(); /* Unmount anything that's our responsibility. */ (void) unmount_client(); /* * No need to umount device since calling process * was responsible for original mount */ if (!updatingExistingPackage) { if (!installStarted && pkgloc[0]) { /* * install not yet started; if package install * location is defined, remove the package. */ echoDebug(DBG_QUIT_REMOVING_PKGDIR, pkgloc); (void) chdir("/"); if (pkgloc[0]) { (void) rrmdir(pkgloc); } } } else { if (!installStarted) { /* * If we haven't started, but have already done * the <PKGINST>/install directory rename, then * remove the new <PKGINST>/install directory * and rename <PKGINST>/install.save back to * <PKGINST>/install. */ if (pkgloc_sav[0] && !access(pkgloc_sav, F_OK)) { if (pkgloc[0] && !access(pkgloc, F_OK)) (void) rrmdir(pkgloc); if (rename(pkgloc_sav, pkgloc) == -1) { progerr(ERR_PACKAGEBINREN, pkgloc_sav, pkgloc); } } } else { if (pkgloc_sav[0] && !access(pkgloc_sav, F_OK)) { echoDebug(DBG_QUIT_REMOVING_PKGSAV, pkgloc_sav); (void) rrmdir(pkgloc_sav); } } } /* * pkginst can be null if an administration setting doesn't all * the package to be installed. Make sure pkginst exeists before * updating the DB */ if (dparts > 0) ds_skiptoend(pkgdev.cdevice); (void) ds_close(1); /* Free the filesystem table. */ fs_tab_free(); /* Free the package information lists. */ pinfo_free(); /* Free all stragglers. */ bl_free(BL_ALL); (void) pathdup(NULL); /* Free regfiles. */ regfiles_free(); /* final exit debugging message */ echoDebug(DBG_EXIT_WITH_CODE, retcode); exit(retcode); /*NOTREACHED*/ }
int main(int argc, char *argv[]) { FILE *fp; char *abi_comp_ptr; char *abi_sym_ptr; char *p; char *prog_full_name = NULL; char *pt; char *value; char *vfstab_file = NULL; char *zoneName = (char *)NULL; char cmdbin[PATH_MAX]; char param[MAX_PKG_PARAM_LENGTH]; char path[PATH_MAX]; char script[PATH_MAX]; int c; int err; int fd; int i; int map_client = 1; int n; int nodelete = 0; /* do not delete file or run scripts */ int pkgrmremote = 0; /* dont remove remote objects */ struct sigaction nact; struct sigaction oact; PKGserver pkgserver = NULL; VFP_T *tmpfp; /* reset contents of all default paths */ (void) memset(cmdbin, '\0', sizeof (cmdbin)); /* initialize locale environment */ (void) setlocale(LC_ALL, ""); (void) textdomain(TEXT_DOMAIN); /* initialize program name */ prog_full_name = argv[0]; (void) set_prog_name(argv[0]); /* tell spmi zones interface how to access package output functions */ z_set_output_functions(echo, echoDebug, progerr); /* exit if not root */ if (getuid()) { progerr(ERR_NOT_ROOT, get_prog_name()); exit(1); /* NOTREACHED */ } /* Read PKG_INSTALL_ROOT from the environment, if it's there. */ if (!set_inst_root(getenv("PKG_INSTALL_ROOT"))) { progerr(ERR_ROOT_SET); exit(1); } pkgserversetmode(DEFAULTMODE); /* parse command line options */ while ((c = getopt(argc, argv, "?Aa:b:FMN:nO:oR:V:vy")) != EOF) { switch (c) { /* * Same as pkgrm: Allow admin to remove package objects from * a shared area from a reference client. */ case 'A': pkgrmremote++; break; /* * Same as pkgrm: Use the installation * administration file, admin, in place of the * default admin file. pkgrm first looks in the * current working directory for the administration * file. If the specified administration file is not * in the current working directory, pkgrm looks in * the /var/sadm/install/admin directory for the * administration file. */ case 'a': admnfile = flex_device(optarg, 0); break; /* * Same as pkgrm: location where package executables * can be found - default is /usr/sadm/install/bin. */ case 'b': if (!path_valid(optarg)) { progerr(ERR_PATH, optarg); exit(1); } if (isdir(optarg) != 0) { char *p = strerror(errno); progerr(ERR_CANNOT_USE_DIR, optarg, p); exit(1); } (void) strlcpy(cmdbin, optarg, sizeof (cmdbin)); break; /* * Same as pkgrm: suppresses the removal of any * files and any class action scripts, and suppresses * the running of any class action scripts. The * package files remain but the package looks like it * is not installed. This is mainly for use by the * upgrade process. */ case 'F': nodelete++; break; /* * Same as pkgrm: Instruct pkgrm not to use the * $root_path/etc/vfstab file for determining the * client's mount points. This option assumes the * mount points are correct on the server and it * behaves consistently with Solaris 2.5 and earlier * releases. */ case 'M': map_client = 0; break; /* * Different from pkgrm: specify program name to use * for messages. */ case 'N': (void) set_prog_name(optarg); break; /* * Same as pkgrm: package removal occurs in * non-interactive mode. Suppress output of the list of * removed files. The default mode is interactive. */ case 'n': nointeract++; (void) echoSetFlag(B_FALSE); break; /* * Almost same as pkgrm: the -O option allows the behavior * of the package tools to be modified. Recognized options: * -> debug * ---> enable debugging output * -> preremovecheck * ---> perform a "pre removal" check of the specified * ---> package - suppress all regular output and cause a * ---> series of one or more "name=value" pair format lines * ---> to be output that describes the "removability" of * ---> the specified package * -> enable-hollow-package-support * --> Enable hollow package support. When specified, for any * --> package that has SUNW_PKG_HOLLOW=true: * --> Do not calculate and verify package size against target * --> Do not run any package procedure or class action scripts * --> Do not create or remove any target directories * --> Do not perform any script locking * --> Do not install or uninstall any components of any package * --> Do not output any status or database update messages */ case 'O': for (p = strtok(optarg, ","); p != (char *)NULL; p = strtok(NULL, ",")) { /* process debug option */ if (strcmp(p, "debug") == 0) { /* set debug flag/enable debug output */ debugFlag = B_TRUE; (void) echoDebugSetFlag(debugFlag); /* debug info on arguments to pkgadd */ for (n = 0; n < argc && argv[n]; n++) { echoDebug(DBG_ARG, n, argv[n]); } continue; } /* process enable-hollow-package-support opt */ if (strcmp(p, "enable-hollow-package-support") == 0) { set_depend_pkginfo_DB(B_TRUE); continue; } /* process preremovecheck option */ if (strcmp(p, "preremovecheck") == 0) { preremoveCheck = B_TRUE; nointeract++; /* -n */ nodelete++; /* -F */ quitSetSilentExit(B_TRUE); continue; } /* process addzonename option */ if (strcmp(p, "addzonename") == 0) { zoneName = z_get_zonename(); quitSetZoneName(zoneName); continue; } /* process parent-zone-name option */ if (strncmp(p, PARENTZONENAME, PARENTZONENAME_LEN) == 0) { parentZoneName = p+PARENTZONENAME_LEN; continue; } /* process parent-zone-type option */ if (strncmp(p, PARENTZONETYPE, PARENTZONETYPE_LEN) == 0) { parentZoneType = p+PARENTZONETYPE_LEN; continue; } if (strncmp(p, PKGSERV_MODE, PKGSERV_MODE_LEN) == 0) { pkgserversetmode(pkgparsemode(p + PKGSERV_MODE_LEN)); continue; } /* option not recognized - issue warning */ progerr(ERR_INVALID_O_OPTION, p); continue; } break; /* * Different from pkgrm: This is an old non-ABI package */ case 'o': script_in = PROC_XSTDIN; break; /* * Same as pkgrm: defines the full path name of a * directory to use as the root_path. All files, * including package system information files, are * relocated to a directory tree starting in the * specified root_path. */ case 'R': if (!set_inst_root(optarg)) { progerr(ERR_ROOT_CMD); exit(1); } break; /* * Same as pkgrm: allow admin to establish the client * filesystem using a vfstab-like file of stable format. */ case 'V': vfstab_file = flex_device(optarg, 2); map_client = 1; break; /* * Same as pkgrm: trace all of the scripts that * get executed by pkgrm, located in the * pkginst/install directory. This option is used for * debugging the procedural and non-procedural * scripts. */ case 'v': pkgverbose++; break; /* * Different from pkgrm: process this package using * old non-ABI symlinks */ case 'y': set_nonABI_symlinks(); break; default: usage(); /*NOTREACHED*/ /* * Although usage() calls a noreturn function, * needed to add return (1); so that main() would * pass compilation checks. The statement below * should never be executed. */ return (1); } } /* * ******************************************************************** * validate command line options * ******************************************************************** */ (void) echoDebugSetFlag(debugFlag); (void) log_set_verbose(debugFlag); if (z_running_in_global_zone()) { echoDebug(DBG_ENTRY_IN_GZ, prog_full_name); } else { echoDebug(DBG_ENTRY_IN_LZ, prog_full_name, getzoneid(), z_get_zonename()); } /* establish cmdbin path */ if (cmdbin[0] == '\0') { (void) strlcpy(cmdbin, PKGBIN, sizeof (cmdbin)); } /* Read the mount table */ if (get_mntinfo(map_client, vfstab_file)) { quit(99); } /* * This function defines the standard /var/... directories used later * to construct the paths to the various databases. */ set_PKGpaths(get_inst_root()); /* * If this is being removed from a client whose /var filesystem is * mounted in some odd way, remap the administrative paths to the * real filesystem. This could be avoided by simply mounting up the * client now; but we aren't yet to the point in the process where * modification of the filesystem is permitted. */ if (is_an_inst_root()) { int fsys_value; fsys_value = fsys(get_PKGLOC()); if (use_srvr_map_n(fsys_value)) set_PKGLOC(server_map(get_PKGLOC(), fsys_value)); fsys_value = fsys(get_PKGADM()); if (use_srvr_map_n(fsys_value)) set_PKGADM(server_map(get_PKGADM(), fsys_value)); } else { pkgrmremote = 0; /* Makes no sense on local host. */ } /* * hook SIGINT and SIGHUP interrupts into quit.c's trap handler */ /* hold SIGINT/SIGHUP interrupts */ (void) sighold(SIGHUP); (void) sighold(SIGINT); /* connect quit.c:trap() to SIGINT */ nact.sa_handler = quitGetTrapHandler(); nact.sa_flags = SA_RESTART; (void) sigemptyset(&nact.sa_mask); (void) sigaction(SIGINT, &nact, &oact); /* connect quit.c:trap() to SIGHUP */ nact.sa_handler = quitGetTrapHandler(); nact.sa_flags = SA_RESTART; (void) sigemptyset(&nact.sa_mask); (void) sigaction(SIGHUP, &nact, &oact); /* release hold on signals */ (void) sigrelse(SIGHUP); (void) sigrelse(SIGINT); pkginst = argv[optind++]; if (optind != argc) { usage(); } /* validate package software database (contents) file */ if (vcfile() == 0) { quit(99); } /* * Acquire the package lock - currently at "remove initialization" */ if (!lockinst(get_prog_name(), pkginst, "remove-initial")) { quit(99); } /* establish temporary directory to use */ tmpdir = getenv("TMPDIR"); if (tmpdir == NULL) { tmpdir = P_tmpdir; } echoDebug(DBG_PKGREMOVE_TMPDIR, tmpdir); /* * Initialize installation admin parameters by reading * the adminfile. */ echoDebug(DBG_PKGREMOVE_ADMINFILE, admnfile ? admnfile : ""); setadminFile(admnfile); /* * about to perform first operation that could be modified by the * preremove check option - if preremove check is selected (that is, * only gathering dependencies), then output a debug message to * indicate that the check is beginning. Also turn echo() output * off and set various other flags. */ if (preremoveCheck == B_TRUE) { (void) echoSetFlag(B_FALSE); echoDebug(DBG_PKGREMOVE_PRERMCHK, pkginst ? pkginst : "", zoneName ? zoneName : "global"); rcksetPreremoveCheck(B_TRUE); rcksetZoneName(zoneName); } (void) snprintf(pkgloc, sizeof (pkgloc), "%s/%s", get_PKGLOC(), pkginst); (void) snprintf(pkgbin, sizeof (pkgbin), "%s/install", pkgloc); (void) snprintf(rlockfile, sizeof (rlockfile), "%s/!R-Lock!", pkgloc); if (chdir(pkgbin)) { progerr(ERR_CHDIR, pkgbin); quit(99); } echo(MSG_PREREMOVE_REMINST, pkginst); /* * if a lock file is present, then a previous attempt to remove this * package may have been unsuccessful. */ if (access(rlockfile, F_OK) == 0) { echo(ERR_UNSUCC); echoDebug(DBG_PKGINSTALL_HAS_LOCKFILE, pkginst, rlockfile, zoneName ? zoneName : "global"); } /* * Process all parameters from the pkginfo file * and place them in the execution environment */ /* Add DB retreival of the pkginfo parameters here */ (void) snprintf(path, sizeof (path), "%s/pkginfo", pkgloc); if ((fp = fopen(path, "r")) == NULL) { progerr(ERR_PKGINFO, path); quit(99); } /* Mount up the client if necessary. */ if (map_client && !mount_client()) { logerr(MSG_MANMOUNT); } /* Get mount point of client */ client_mntdir = getenv("CLIENT_MNTDIR"); getuserlocale(); /* * current environment has been read; clear environment out * so putparam() can be used to populate the new environment * to be passed to any executables/scripts. */ environ = NULL; if (nonABI_symlinks()) { putparam("PKG_NONABI_SYMLINKS", "TRUE"); } /* * read the pkginfo file and fix any PKGSAV path - the correct * install_root will be prepended to the existing path. */ param[0] = '\0'; while (value = fpkgparam(fp, param)) { int validx = 0; char *newvalue; /* strip out any setting of PATH */ if (strcmp(param, "PATH") == 0) { free(value); param[0] = '\0'; continue; } /* if not PKGSAV then write out unchanged */ if (strcmp(param, "PKGSAV") != 0) { putparam(param, value); free(value); param[0] = '\0'; continue; } /* * PKGSAV parameter found - interpret the directory: * If in host:path format or marked with the leading "//", * then there is no client-relative translation - take it * literally later rather than use fixpath(). */ if (strstr(value, ":/")) { /* no modification needed */ validx = 0; } else if (strstr(value, "//") == value) { validx = 1; } else if (is_an_inst_root()) { /* This PKGSAV needs to be made client-relative. */ newvalue = fixpath(value); free(value); value = newvalue; } putparam(param, value+validx); free(value); param[0] = '\0'; } (void) fclose(fp); /* write parent condition information to environment */ putConditionInfo(parentZoneName, parentZoneType); putuserlocale(); /* * Now do all the various setups based on ABI compliance */ /* Read the environment provided by the pkginfo file */ abi_comp_ptr = getenv("NONABI_SCRIPTS"); /* if not ABI compliant set global flag */ abi_sym_ptr = getenv("PKG_NONABI_SYMLINKS"); if (abi_sym_ptr && strncasecmp(abi_sym_ptr, "TRUE", 4) == 0) { set_nonABI_symlinks(); } /* * If pkginfo says it's not compliant then set non_abi_scripts. */ if (abi_comp_ptr && strncmp(abi_comp_ptr, "TRUE", 4) == 0) { script_in = PROC_XSTDIN; } /* * Since this is a removal, we can tell whether it's absolute or * not from the resident pkginfo file read above. */ if ((err = set_basedirs((getenv("BASEDIR") != NULL), adm.basedir, pkginst, nointeract)) != 0) { quit(err); } /* * See if were are removing a package that only wants to update * the database or only remove files associated with CAS's. We * only check the PKG_HOLLOW_VARIABLE variable if told to do so by * the caller. */ if (is_depend_pkginfo_DB()) { pt = getenv(PKG_HOLLOW_VARIABLE); if ((pt != NULL) && (strncasecmp(pt, "true", 4) == 0)) { echoDebug(DBG_PKGREMOVE_HOLLOW_ENABLED); /* * this is a hollow package and hollow package support * is enabled -- override admin settings to suppress * checks that do not make sense since no scripts will * be executed and no files will be removed. */ setadminSetting("conflict", "nocheck"); setadminSetting("setuid", "nocheck"); setadminSetting("action", "nocheck"); setadminSetting("partial", "nocheck"); setadminSetting("space", "nocheck"); setadminSetting("authentication", "nocheck"); } else { echoDebug(DBG_PKGREMOVE_HOLLOW_DISABLED); set_depend_pkginfo_DB(B_FALSE); } } put_path_params(); /* If client mount point, add it to pkgremove environment */ if (client_mntdir != NULL) { putparam("CLIENT_MNTDIR", client_mntdir); } /* Establish the class list and the class attributes. */ if ((value = getenv("CLASSES")) != NULL) { cl_sets(qstrdup(value)); } else { progerr(ERR_CLASSES, path); quit(99); } /* establish path and tmpdir */ if (cmdbin[0] == '\0') { (void) strlcpy(cmdbin, PKGBIN, sizeof (cmdbin)); } (void) snprintf(path, sizeof (path), "%s:%s", DEFPATH, cmdbin); putparam("PATH", path); putparam("TMPDIR", tmpdir); /* * Check ulimit requirement (provided in pkginfo). The purpose of * this limit is to terminate pathological file growth resulting from * file edits in scripts. It does not apply to files in the pkgmap * and it does not apply to any database files manipulated by the * installation service. */ if (value = getenv("ULIMIT")) { if (assign_ulimit(value) == -1) { progerr(ERR_BADULIMIT, value); warnflag++; } putparam("PKG_ULIMIT", "TRUE"); } /* * If only gathering dependencies, check and output status of all * remaining dependencies and exit. */ if (preremoveCheck == B_TRUE) { /* * make sure current runlevel is appropriate */ (void) fprintf(stdout, "rckrunlevel=%d\n", rckrunlevel()); /* * determine if any packaging scripts provided with * this package will execute as a priviledged user */ (void) fprintf(stdout, "rckpriv=%d\n", rckpriv()); /* * verify package dependencies */ (void) fprintf(stdout, "rckdepend=%d\n", rckdepend()); /* * ****** preremove check done - exit ****** */ echoDebug(DBG_PKGREMOVE_PRERMCHK_OK); quit(0); /*NOTREACHED*/ } /* * Not gathering dependencies only, proceed to check dependencies * and continue with the package removal operation. */ /* * make sure current runlevel is appropriate */ n = rckrunlevel(); if (n != 0) { quit(n); /* NOTREACHED */ } /* * determine if any packaging scripts provided with * this package will execute as a priviledged user */ n = rckpriv(); if (n != 0) { quit(n); /* NOTREACHED */ } /* * verify package dependencies */ n = rckdepend(); if (n != 0) { quit(n); /* NOTREACHED */ } /* * ********************************************************************* * the actual removal of the package begins here * ********************************************************************* */ /* * create lockfile to indicate start of removal */ started++; if ((fd = open(rlockfile, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) { progerr(ERR_LOCKFILE, rlockfile); quit(99); } else { (void) close(fd); } if (zoneName == (char *)NULL) { echo(MSG_PKGREMOVE_PROCPKG_GZ); echoDebug(DBG_PKGREMOVE_PROCPKG_GZ, pkginst, rlockfile); } else { echo(MSG_PKGREMOVE_PROCPKG_LZ, zoneName); echoDebug(DBG_PKGREMOVE_PROCPKG_LZ, pkginst, rlockfile, zoneName); } if (delmap(0, pkginst, &pkgserver, &tmpfp) != 0) { progerr(ERR_DB_QUERY, pkginst); quit(99); } /* * Run a preremove script if one is provided by the package. * Don't execute preremove script if only updating the DB. * Don't execute preremove script if files are not being deleted. */ /* update the lock - at the preremove script */ lockupd("preremove"); /* execute preremove script if one is provided */ (void) snprintf(script, sizeof (script), "%s/preremove", pkgbin); if (access(script, F_OK) != 0) { /* no script present */ echoDebug(DBG_PKGREMOVE_POC_NONE, pkginst, zoneName ? zoneName : "global"); } else if (nodelete) { /* not deleting files: skip preremove script */ echoDebug(DBG_PKGREMOVE_POC_NODEL, pkginst, script, zoneName ? zoneName : "global"); } else if (is_depend_pkginfo_DB()) { /* updating db only: skip preremove script */ echoDebug(DBG_PKGREMOVE_POC_DBUPD, pkginst, script, zoneName ? zoneName : "global"); } else { /* script present and ok to run: run the script */ set_ulimit("preremove", ERR_PREREMOVE); if (zoneName == (char *)NULL) { echo(MSG_PKGREMOVE_EXEPOC_GZ); echoDebug(DBG_PKGREMOVE_EXEPOC_GZ, pkginst, script); } else { echo(MSG_PKGREMOVE_EXEPOC_LZ, zoneName); echoDebug(DBG_PKGREMOVE_EXEPOC_LZ, pkginst, script, zoneName); } putparam("PKG_PROC_SCRIPT", "preremove"); if (pkgverbose) { ckreturn(pkgexecl(script_in, PROC_STDOUT, PROC_USER, PROC_GRP, SHELL, "-x", script, NULL), ERR_PREREMOVE); } else { ckreturn(pkgexecl(script_in, PROC_STDOUT, PROC_USER, PROC_GRP, SHELL, script, NULL), ERR_PREREMOVE); } clr_ulimit(); } /* update the lock - doing removal */ lockupd("remove"); /* * Remove all components belonging to this package. * Don't remove components if only updating the DB. * Don't remove components if files are not being deleted. */ if (nodelete) { echoDebug(DBG_PKGREMOVE_REM_NODEL, pkginst, zoneName ? zoneName : "global"); } else if (is_depend_pkginfo_DB()) { echoDebug(DBG_PKGREMOVE_REM_DBUPD, pkginst, zoneName ? zoneName : "global"); } else { echoDebug(DBG_PKGREMOVE_REM, pkginst, zoneName ? zoneName : "global"); /* * remove package one class at a time */ /* reverse order of classes */ for (i = cl_getn() - 1; i >= 0; i--) { rmclass(cl_nam(i), pkgrmremote, zoneName); } rmclass(NULL, pkgrmremote, zoneName); } z_destroyMountTable(); /* * Execute postremove script, if any * Don't execute postremove script if only updating the DB. * Don't execute postremove script if files are not being deleted. */ /* update the lock - at the postremove script */ lockupd("postremove"); /* execute postremove script if one is provided */ (void) snprintf(script, sizeof (script), "%s/postremove", pkgbin); if (access(script, F_OK) != 0) { /* no script present */ echoDebug(DBG_PKGREMOVE_PIC_NONE, pkginst, zoneName ? zoneName : "global"); } else if (nodelete) { /* not deleting files: skip postremove script */ echoDebug(DBG_PKGREMOVE_PIC_NODEL, pkginst, script, zoneName ? zoneName : "global"); } else if (is_depend_pkginfo_DB()) { /* updating db only: skip postremove script */ echoDebug(DBG_PKGREMOVE_PIC_DBUPD, pkginst, script, zoneName ? zoneName : "global"); } else { /* script present and ok to run: run the script */ set_ulimit("postremove", ERR_POSTREMOVE); if (zoneName == (char *)NULL) { echo(MSG_PKGREMOVE_EXEPIC_GZ); echoDebug(DBG_PKGREMOVE_EXEPIC_GZ, pkginst, script); } else { echo(MSG_PKGREMOVE_EXEPIC_LZ, zoneName); echoDebug(DBG_PKGREMOVE_EXEPIC_LZ, pkginst, script, zoneName); } putparam("PKG_PROC_SCRIPT", "postremove"); putparam("TMPDIR", tmpdir); if (pkgverbose) { ckreturn(pkgexecl(script_in, PROC_STDOUT, PROC_USER, PROC_GRP, SHELL, "-x", script, NULL), ERR_POSTREMOVE); } else { ckreturn(pkgexecl(script_in, PROC_STDOUT, PROC_USER, PROC_GRP, SHELL, script, NULL), ERR_POSTREMOVE); } clr_ulimit(); } if (zoneName == (char *)NULL) { echo(MSG_PKGREMOVE_UPDINF_GZ); } else { echo(MSG_PKGREMOVE_UPDINF_LZ, zoneName); } if (delmap(1, pkginst, &pkgserver, &tmpfp) != 0) { progerr(ERR_DB_QUERY, pkginst); quit(99); } if (!warnflag && !failflag) { (void) chdir("/"); if (rrmdir(pkgloc)) warnflag++; } if ((z_running_in_global_zone() == B_TRUE) && (pkgIsPkgInGzOnly(get_inst_root(), pkginst) == B_TRUE)) { boolean_t b; b = pkgRemovePackageFromGzonlyList(get_inst_root(), pkginst); if (b == B_FALSE) { progerr(ERR_PKGREMOVE_GZONLY_REMOVE, pkginst); ckreturn(1, NULL); } } /* release the generic package lock */ (void) unlockinst(); pkgcloseserver(pkgserver); quit(0); /* LINTED: no return */ }
int main(int argc, char *argv[]) { struct utsname utsbuf; struct statvfs64 svfsb; struct cfent **eptlist; FILE *fp; VFP_T *vfp; int i, c, n, eptnum, found, part, nparts, npkgs, objects; char buf[MAX_PKG_PARAM_LENGTH]; char temp[MAX_PKG_PARAM_LENGTH]; char param[MAX_PKG_PARAM_LENGTH]; char *pt, *value, *pkginst, *tmpdir, *abi_sym_ptr, **cmdparam; char *pkgname; char *pkgvers; char *pkgarch; char *pkgcat; void (*func)(); time_t clock; fsblkcnt_t bsize = 0; fsblkcnt_t frsize = 0; struct cl_attr **allclass = NULL; struct cl_attr **order; /* initialize locale environment */ (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); /* initialize program name */ (void) set_prog_name(argv[0]); /* tell spmi zones interface how to access package output functions */ z_set_output_functions(echo, echoDebug, progerr); func = sigset(SIGINT, trap); if (func != SIG_DFL) func = sigset(SIGINT, func); func = sigset(SIGHUP, trap); setmapmode(MAPBUILD); /* variable binding */ if (func != SIG_DFL) func = sigset(SIGHUP, func); environ = NULL; while ((c = getopt(argc, argv, "osnp:l:r:b:d:f:a:v:?")) != EOF) { switch (c) { case 'n': nflag++; break; case 's': sflag++; break; case 'o': overwrite++; break; case 'p': putparam("PSTAMP", optarg); break; case 'l': llimit = atol(optarg); break; case 'r': pt = strtok(optarg, " \t\n, "); n = 0; do { rootlist[n++] = flex_device(pt, 0); if (n >= NROOT) { progerr(gettext(ERR_NROOT), NROOT); quit(1); } } while (pt = strtok(NULL, " \t\n, ")); rootlist[n] = NULL; break; case 'b': basedir = optarg; break; case 'f': protofile = optarg; break; case 'd': device = flex_device(optarg, 1); break; case 'a': putparam("ARCH", optarg); break; case 'v': putparam("VERSION", optarg); break; default: usage(); } } /* * Store command line variable assignments for later * incorporation into the environment. */ cmdparam = &argv[optind]; /* Skip past equates. */ while (argv[optind] && strchr(argv[optind], '=')) optind++; /* Confirm that the instance name is valid */ if ((pkginst = argv[optind]) != NULL) { if (pkgnmchk(pkginst, "all", 0)) { progerr(gettext(ERR_PKGINST), pkginst); quit(1); } argv[optind++] = NULL; } if (optind != argc) usage(); tmpdir = getenv("TMPDIR"); if (tmpdir == NULL) tmpdir = P_tmpdir; /* bug id 4244631, not ABI compliant */ abi_sym_ptr = getenv("PKG_NONABI_SYMLINKS"); if (abi_sym_ptr && (strncasecmp(abi_sym_ptr, "TRUE", 4) == 0)) { set_nonABI_symlinks(); } if (device == NULL) { device = devattr(SPOOLDEV, "pathname"); if (device == NULL) { progerr(gettext(ERR_DEVICE), SPOOLDEV); exit(99); } } if (protofile == NULL) { if (access("prototype", 0) == 0) protofile = "prototype"; else if (access("Prototype", 0) == 0) protofile = "Prototype"; else { progerr(gettext(ERR_PROTOTYPE)); quit(1); } } if (devtype(device, &pkgdev)) { progerr(gettext(ERR_BADDEV), device); quit(1); } if (pkgdev.norewind) { /* initialize datastream */ progerr(gettext(ERR_DSTREAM), device); quit(1); } if (pkgdev.mount) { if (n = pkgmount(&pkgdev, NULL, 0, 0, 1)) quit(n); } /* * convert prototype file to a pkgmap, while locating * package objects in the current environment */ t_pkgmap = tempnam(tmpdir, "tmpmap"); if (t_pkgmap == NULL) { progerr(gettext(ERR_TEMP), errno); exit(99); } (void) fprintf(stderr, gettext(MSG_PROTOTYPE)); if (n = mkpkgmap(t_pkgmap, protofile, cmdparam)) { progerr(gettext(ERR_BUILD)); quit(1); } setmapmode(MAPNONE); /* All appropriate variables are now bound */ if (vfpOpen(&vfp, t_pkgmap, "r", VFP_NEEDNOW) != 0) { progerr(gettext(ERR_TEMP), errno); quit(99); } eptlist = procmap(vfp, 0, NULL); if (eptlist == NULL) { quit(1); } (void) vfpClose(&vfp); /* Validate the zone attributes in pkginfo, before creation */ if (!valid_zone_attr(eptlist)) { progerr(ERR_PKGINFO_INVALID_OPTION_COMB); quit(1); } (void) fprintf(stderr, gettext(MSG_PKGINFO)); pt = NULL; for (i = 0; eptlist[i]; i++) { ckmissing(eptlist[i]->path, eptlist[i]->ftype); if (eptlist[i]->ftype != 'i') continue; if (strcmp(eptlist[i]->path, "pkginfo") == 0) svept = eptlist[i]; } if (svept == NULL) { progerr(gettext(ERR_NOPKGINFO)); quit(99); } eptnum = i; /* * process all parameters from the pkginfo file * and place them in the execution environment */ if ((fp = fopen(svept->ainfo.local, "r")) == NULL) { progerr(gettext(ERR_RDPKGINFO), svept->ainfo.local); quit(99); } param[0] = '\0'; while (value = fpkgparam(fp, param)) { if (getenv(param) == NULL) putparam(param, value); free((void *)value); param[0] = '\0'; } (void) fclose(fp); /* add command line variables */ while (*cmdparam && (value = strchr(*cmdparam, '=')) != NULL) { *value = NULL; /* terminate the parameter */ value++; /* value is now the value (not '=') */ putparam(*cmdparam++, value); /* store it in environ */ } /* make sure parameters are valid */ (void) time(&clock); if (pt = getenv("PKG")) { if (pkgnmchk(pt, NULL, 0) || strchr(pt, '.')) { progerr(gettext(ERR_PKGABRV), pt); quit(1); } if (pkginst == NULL) pkginst = pt; } else { progerr(gettext(ERR_NOPARAM), "PKG", svept->path); quit(1); } /* * verify consistency between PKG parameter and pkginst */ (void) snprintf(param, sizeof (param), "%s.*", pt); if (pkgnmchk(pkginst, param, 0)) { progerr(gettext(ERR_PKGMTCH), pt, pkginst); quit(1); } /* * ********************************************************************* * this feature is removed starting with Solaris 10 - there is no built * in list of packages that should be run "the old way" * ********************************************************************* */ #ifdef ALLOW_EXCEPTION_PKG_LIST /* Until 2.9, set it from the execption list */ if (exception_pkg(pkginst, LINK)) set_nonABI_symlinks(); #endif if ((pkgname = getenv("NAME")) == NULL) { progerr(gettext(ERR_NOPARAM), "NAME", svept->path); quit(1); } if (ckparam("NAME", pkgname)) quit(1); if ((pkgvers = getenv("VERSION")) == NULL) { /* XXX - I18n */ /* LINTED do not use cftime(); use strftime instead */ (void) cftime(buf, "\045m/\045d/\045Y", &clock); (void) snprintf(temp, sizeof (temp), gettext("Dev Release %s"), buf); putparam("VERSION", temp); pkgvers = getenv("VERSION"); logerr(gettext(WRN_SETPARAM), "VERSION", temp); } if (ckparam("VERSION", pkgvers)) quit(1); if ((pkgarch = getenv("ARCH")) == NULL) { (void) uname(&utsbuf); putparam("ARCH", utsbuf.machine); pkgarch = getenv("ARCH"); logerr(gettext(WRN_SETPARAM), "ARCH", utsbuf.machine); } if (ckparam("ARCH", pkgarch)) quit(1); if (getenv("PSTAMP") == NULL) { /* use octal value of '%' to fight sccs expansion */ /* XXX - I18n */ /* LINTED do not use cftime(); use strftime instead */ (void) cftime(buf, "\045Y\045m\045d\045H\045M\045S", &clock); (void) uname(&utsbuf); (void) snprintf(temp, sizeof (temp), "%s%s", utsbuf.nodename, buf); putparam("PSTAMP", temp); logerr(gettext(WRN_SETPARAM), "PSTAMP", temp); } if ((pkgcat = getenv("CATEGORY")) == NULL) { progerr(gettext(ERR_NOPARAM), "CATEGORY", svept->path); quit(1); } if (ckparam("CATEGORY", pkgcat)) quit(1); /* * warn user of classes listed in package which do * not appear in CLASSES variable in pkginfo file */ objects = 0; for (i = 0; eptlist[i]; i++) { if (eptlist[i]->ftype != 'i') { objects++; addlist(&allclass, eptlist[i]->pkg_class); } } if ((pt = getenv("CLASSES")) == NULL) { if (allclass && *allclass) { cl_setl(allclass); cl_putl("CLASSES", allclass); logerr(gettext(WRN_SETPARAM), "CLASSES", getenv("CLASSES")); } } else { cl_sets(qstrdup(pt)); if (allclass && *allclass) { for (i = 0; allclass[i]; i++) { found = 0; if (cl_idx(allclass[i]->name) != -1) { found++; break; } if (!found) { logerr(gettext(WRN_CLASSES), (char *)allclass[i]); } } } } (void) fprintf(stderr, gettext(MSG_VOLUMIZE), objects); order = (struct cl_attr **)0; if (pt = getenv("ORDER")) { pt = qstrdup(pt); (void) setlist(&order, pt); cl_putl("ORDER", order); } /* stat the intended output filesystem to get blocking information */ if (pkgdev.dirname == NULL) { progerr(gettext(ERR_WHATVFS), device); quit(99); } if (statvfs64(pkgdev.dirname, &svfsb)) { progerr(gettext(ERR_STATVFS), pkgdev.dirname); quit(99); } if (bsize == 0) { bsize = svfsb.f_bsize; } if (frsize == 0) { frsize = svfsb.f_frsize; } if (limit == 0) /* * bavail is in terms of fragment size blocks - change * to 512 byte blocks */ limit = (((long)frsize > 0) ? howmany(frsize, DEV_BSIZE) : howmany(bsize, DEV_BSIZE)) * svfsb.f_bavail; if (ilimit == 0) { ilimit = (svfsb.f_favail > 0) ? svfsb.f_favail : svfsb.f_ffree; } nparts = splpkgmap(eptlist, eptnum, (char **)order, bsize, frsize, &limit, &ilimit, &llimit); if (nparts <= 0) { progerr(gettext(ERR_SPLIT)); quit(1); } if (nflag) { for (i = 0; eptlist[i]; i++) (void) ppkgmap(eptlist[i], stdout); exit(0); /*NOTREACHED*/ } (void) snprintf(pkgloc, sizeof (pkgloc), "%s/%s", pkgdev.dirname, pkginst); if (!isdir(pkgloc) && !overwrite) { progerr(gettext(ERR_OVERWRITE), pkgloc); quit(1); } /* output all environment install parameters */ t_pkginfo = tempnam(tmpdir, "pkginfo"); if ((fp = fopen(t_pkginfo, "w")) == NULL) { progerr(gettext(ERR_TEMP), errno); exit(99); } for (i = 0; environ[i]; i++) { if (isupper(*environ[i])) { (void) fputs(environ[i], fp); (void) fputc('\n', fp); } } (void) fclose(fp); started++; (void) rrmdir(pkgloc); if (mkdir(pkgloc, 0755)) { progerr(gettext(ERR_MKDIR), pkgloc); quit(1); } /* determine how many packages already reside on the medium */ pkgdir = pkgdev.dirname; npkgs = 0; while (pt = fpkginst("all", NULL, NULL)) npkgs++; (void) fpkginst(NULL); /* free resource usage */ if (nparts > 1) { if (pkgdev.mount && npkgs) { progerr(gettext(ERR_ONEVOL)); quit(1); } } /* * update pkgmap entry for pkginfo file, since it may * have changed due to command line or failure to * specify all neccessary parameters */ for (i = 0; eptlist[i]; i++) { if (eptlist[i]->ftype != 'i') continue; if (strcmp(eptlist[i]->path, "pkginfo") == 0) { svept = eptlist[i]; svept->ftype = '?'; svept->ainfo.local = t_pkginfo; (void) cverify(0, &svept->ftype, t_pkginfo, &svept->cinfo, 1); svept->ftype = 'i'; break; } } if (nparts > 1) (void) fprintf(stderr, gettext(MSG_PACKAGEM), nparts); else (void) fprintf(stderr, gettext(MSG_PACKAGE1)); for (part = 1; part <= nparts; part++) { if ((part > 1) && pkgdev.mount) { if (pkgumount(&pkgdev)) { progerr(gettext(ERR_UMOUNT), pkgdev.mount); quit(99); } if (n = pkgmount(&pkgdev, NULL, part, nparts, 1)) quit(n); (void) rrmdir(pkgloc); if (mkdir(pkgloc, 0555)) { progerr(gettext(ERR_MKDIR), pkgloc); quit(99); } } outvol(eptlist, eptnum, part, nparts); /* Validate (as much as possible) the control scripts. */ if (part == 1) { char inst_path[PATH_MAX]; (void) fprintf(stderr, gettext(MSG_VALSCRIPTS)); (void) snprintf(inst_path, sizeof (inst_path), "%s/install", pkgloc); checkscripts(inst_path, 0); } } quit(0); /*NOTREACHED*/ }