Example #1
0
void archivefiles(const char *const *argv) {
  const char *volatile thisarg;
  const char *const *volatile argp;
  jmp_buf ejbuf;
  int pi[2], fc, nfiles, c, i, r;
  FILE *pf;
  static struct varbuf findoutput;
  const char **arglist;
  char *p;

  trigproc_install_hooks();

  modstatdb_init(admindir,
                 f_noact ?                     msdbrw_readonly
               : cipaction->arg == act_avail ? msdbrw_write
               : fc_nonroot ?                  msdbrw_write
               :                               msdbrw_needsuperuser);

  checkpath();
  log_message("startup archives %s", cipaction->olong);

  if (f_recursive) {
    if (!*argv)
      badusage(_("--%s --recursive needs at least one path argument"),cipaction->olong);

    m_pipe(pi);
    fc = subproc_fork();
    if (!fc) {
      struct command cmd;
      const char *const *ap;

      m_dup2(pi[1],1); close(pi[0]); close(pi[1]);

      command_init(&cmd, FIND, _("find for dpkg --recursive"));
      command_add_args(&cmd, FIND, "-L", NULL);

      for (ap = argv; *ap; ap++) {
        if (strchr(FIND_EXPRSTARTCHARS,(*ap)[0])) {
          char *a;
          a= m_malloc(strlen(*ap)+10);
          strcpy(a,"./");
          strcat(a,*ap);
          command_add_arg(&cmd, a);
        } else {
          command_add_arg(&cmd, (const char *)*ap);
        }
      }

      command_add_args(&cmd, "-name", "*.deb", "-type", "f", "-print0", NULL);

      command_exec(&cmd);
    }
    close(pi[1]);

    nfiles= 0;
    pf= fdopen(pi[0],"r");  if (!pf) ohshite(_("failed to fdopen find's pipe"));
    varbufreset(&findoutput);
    while ((c= fgetc(pf)) != EOF) {
      varbufaddc(&findoutput,c);
      if (!c) nfiles++;
    }
    if (ferror(pf)) ohshite(_("error reading find's pipe"));
    if (fclose(pf)) ohshite(_("error closing find's pipe"));
    r = subproc_wait_check(fc, "find", PROCNOERR);
    if (r != 0)
      ohshit(_("find for --recursive returned unhandled error %i"),r);

    if (!nfiles)
      ohshit(_("searched, but found no packages (files matching *.deb)"));

    varbufaddc(&findoutput,0);
    varbufaddc(&findoutput,0);

    arglist= m_malloc(sizeof(char*)*(nfiles+1));
    p= findoutput.buf; i=0;
    while (*p) {
      arglist[i++]= p;
      while (*p++ != '\0') ;
    }
    arglist[i] = NULL;
    argp= arglist;
  } else {
    if (!*argv) badusage(_("--%s needs at least one package archive file argument"),
                         cipaction->olong);
    argp= argv;
  }

  currenttime = time(NULL);

  /* Initialize fname variables contents. */

  varbufreset(&fnamevb);
  varbufreset(&fnametmpvb);
  varbufreset(&fnamenewvb);

  varbufaddstr(&fnamevb,instdir); varbufaddc(&fnamevb,'/');
  varbufaddstr(&fnametmpvb,instdir); varbufaddc(&fnametmpvb,'/');
  varbufaddstr(&fnamenewvb,instdir); varbufaddc(&fnamenewvb,'/');
  fnameidlu= fnamevb.used;

  ensure_diversions();
  ensure_statoverrides();

  while ((thisarg = *argp++) != NULL) {
    if (setjmp(ejbuf)) {
      pop_error_context(ehflag_bombout);
      if (abort_processing)
        break;
      continue;
    }
    push_error_context_jump(&ejbuf, print_error_perpackage, thisarg);

    process_archive(thisarg);
    onerr_abort++;
    m_output(stdout, _("<standard output>"));
    m_output(stderr, _("<standard error>"));
    onerr_abort--;

    pop_error_context(ehflag_normaltidy);
  }

  switch (cipaction->arg) {
  case act_install:
  case act_configure:
  case act_triggers:
  case act_remove:
  case act_purge:
    process_queue();
  case act_unpack:
  case act_avail:
    break;
  default:
    internerr("unknown action '%d'", cipaction->arg);
  }

  trigproc_run_deferred();
  modstatdb_shutdown();
}
Example #2
0
int main(int argc, char *argv[])
{
 int cur_arg;
 #if SFX_LEVEL>=ARJSFXV
  int cmd;
  int is_add_cmd;
  unsigned long start_time, proc_time;
  FILE_COUNT i;
  FILE *stream;
  char *tmp_ptr, *tptr;
  int got_str;
  char *name;
  int flist_type;
  FILE_COUNT numfiles;
  int expand_wildcards;
  int entry;
  int sort_f;
  FILE_COUNT count;
  FILE_COUNT cur_file;
  int tmp_reg;
 #else
  char *tmp_ptr;
 #endif

#ifdef COLOR_OUTPUT
 no_colors=redirected=!is_tty(stdout);
#endif
 #if SFX_LEVEL>=ARJSFXV
  errorlevel=0;
  ignore_errors=0;
  new_stdout=stdout;
  lfn_supported=LFN_NOT_SUPPORTED;
  ticks=get_ticks();
  detect_lfns();
  detect_eas();
  #ifndef NO_FATAL_ERROR_HDL
   install_smart_handler();
  #endif
  build_crc32_table();
 #else
  build_crc32_table();
  detect_lfns();
  file_packing=1;
 #endif
 #ifdef TZ_VAR
  tzset();
 #endif
 #ifdef STDOUT_SETBUF_FIX               /* ASR fix for IBM C Set / GLIBC */
  setbuf(stdout, NULL);
  setbuf(stderr, NULL);
 #endif
 #if SFX_LEVEL>=ARJSFXV
  start_time=get_ticks();
  flist_init(&flist_main, FCLIM_ARCHIVE, FL_STANDARD);
  ctrlc_processing=0;
  header=(char *)malloc_msg(HEADERSIZE_MAX);
  archive_name=(char *)malloc_msg(FILENAME_MAX);
  /* Original ARJSFX reserves 200 bytes for misc_buf but, taking into account
     that LFNs can be large enough, more space is to be reserved. */
  misc_buf=(char *)malloc_msg(FILENAME_MAX+INPUT_LENGTH);
  tmp_tmp_filename=(char *)malloc_msg(FILENAME_MAX);
  limit=20;
  init();
  if(signal(SIGINT, ctrlc_handler)==SIG_ERR)
   error(M_SIGNAL_FAILED);
  #ifndef NO_TERM_HDL
   if(signal(SIGTERM, term_handler)==SIG_ERR)
    error(M_SIGNAL_FAILED);
  #endif
  atexit(final_cleanup);
 #else
  tmp_tmp_filename[0]='\0';
  target_dir=nullstr;
  garble_password=nullstr;
  extr_cmd_text=nullstr;
 #endif
 #ifndef SKIP_GET_EXE_NAME
  get_exe_name(archive_name);
 #else
  strcpy(archive_name, argv[0]);
 #endif
 exe_name=archive_name;
 #if SFX_LEVEL<=ARJSFX
  for(tmp_ptr=exe_name; *tmp_ptr!='\0'; tmp_ptr++)
   if(*tmp_ptr==PATHSEP_DEFAULT)
    exe_name=tmp_ptr+1;
  atexit(final_cleanup);
  signal(SIGINT, ctrlc_handler);
  #ifndef NO_TERM_HDL
   signal(SIGTERM, term_handler);
  #endif
 #endif
 check_fmsg(CHKMSG_SKIP);
 #if SFX_LEVEL>=ARJSFXV
  skip_switch_processing=0;
 #else
  switch_char=0;
 #endif
 for(cur_arg=1; cur_arg<argc; cur_arg++)
  parse_cmdline(argv[cur_arg]);
 #if SFX_LEVEL>=ARJSFXV
  if(install_errhdl)
   ignore_errors=1;
  if(quiet_mode)
   freopen(dev_null, m_w, stdout);
 #endif
 if(argc>1)
  skip_preset_options=1;
 arj_exec_validation();
 if(help_issued)
 {
  #if SFX_LEVEL>=ARJSFXV
   show_sfx_logo();
  #else
   msg_cprintf(0, M_ARJSFX_BANNER, exe_name);
  #endif
  check_fmsg(CHKMSG_SFX_HELP);
  #if SFX_LEVEL>=ARJSFXV
   exit(ARJ_ERL_SUCCESS);
  #else
   exit(ARJSFX_ERL_SUCCESS);
  #endif
 }
 #if SFX_LEVEL>=ARJSFXV
  if(limit!=0)
   wait_error(M_CRC_ERROR);
  limit=20;
  arj_exec_validation();
  proc_time=get_ticks();
  check_fmsg(CHKMSG_SKIP);
  perform_cmd();
 #else
  process_archive();
 #endif
 /* Cleanup for ARJSFXV */
 #if SFX_LEVEL>=ARJSFXV
  file_arg_cleanup();
 #endif
 if(errors>0)
  error(M_FOUND_N_ERRORS, errors);
 #if SFX_LEVEL>=ARJSFXV
  if(errorlevel!=ARJ_ERL_SUCCESS)
   exit(errorlevel);
 #endif
#if SFX_LEVEL>=ARJSFXV
 if(extr_cmd_text[0]!='\0')
#else
 if(execute_extr_cmd&&extr_cmd_text[0]!='\0')
#endif
 {
  if(licensed_sfx)
  {
   msg_cprintf(0, M_EXECUTING_CMD, extr_cmd_text);
   arj_delay(2);
   exec_command(extr_cmd_text);
  }
  else
  {
   #if SFX_LEVEL>=ARJSFXV
    msg_sprintf(misc_buf, M_EXTR_CMD_QUERY, extr_cmd_text);
    if(query_action(REPLY_YES, QUERY_CRITICAL, (FMSG *)misc_buf))
     exec_command(extr_cmd_text);
   #else
    msg_cprintf(0, M_EXTR_CMD_QUERY, extr_cmd_text);
    if(query_action())
     exec_command(extr_cmd_text);
   #endif
  }
 }
 #if SFX_LEVEL>=ARJSFXV
  return(ARJ_ERL_SUCCESS);
 #else
  return(ARJSFX_ERL_SUCCESS);
 #endif
}