예제 #1
0
int
clockmatch(device_t parent, cfdata_t cf, void *aux)
{
	if (matchname("clock", aux))
		return(1);
	return(0);
}
예제 #2
0
파일: afsc.c 프로젝트: lacombar/netbsd-alc
/*
 * if we are a Commodore Amiga A4091 or possibly an A4000T
 */
int
afscmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
{
	struct zbus_args *zap;
	siop_regmap_p rp;
	u_long temp, scratch;

	zap = auxp;
	if (zap->manid == 514 && zap->prodid == 84)
		return(1);		/* It's an A4091 SCSI card */
	if (!is_a4000() || !matchname("afsc", auxp))
		return(0);		/* Not on an A4000 or not A4000T SCSI */
	rp = ztwomap(0xdd0040);
	if (badaddr((void *)__UNVOLATILE(&rp->siop_scratch)) || 
	    badaddr((void *)__UNVOLATILE(&rp->siop_temp))) {
		return(0);
	}
	scratch = rp->siop_scratch;
	temp = rp->siop_temp;
	rp->siop_scratch = 0xdeadbeef;
	rp->siop_temp = 0xaaaa5555;
	if (rp->siop_scratch != 0xdeadbeef || rp->siop_temp != 0xaaaa5555)
		return(0);
	rp->siop_scratch = scratch;
	rp->siop_temp = temp;
	if (rp->siop_scratch != scratch || rp->siop_temp != temp)
		return(0);
	return(1);
}
예제 #3
0
static short *doreplace(short *buf, int *max, int *len, short *find, short
    *replace, int slen, int flen, int nolt)
{
    short *s = buf;
    int sslen = slen;
    while (s = matchname(s, find, &sslen, nolt))
    {
        if (*max <=  *len + flen - sslen)
        {
            short *buf2 = xalloc(*max + 1000 * sizeof(short));
            *max += 1000;
            memcpy(buf2, buf, (*len + 1) *sizeof(short));
            s = s + (int)(buf2 - buf);
            buf = buf2;
        }
        if (flen > sslen)
            memmove(s + flen - sslen, s, (*len - (s - buf) + 1) *sizeof(short));
        else
            memcpy(s, s + sslen - flen, (*len - (s + sslen - flen - buf) + 1)
                *sizeof(short));
        *len += flen - sslen;
        memcpy(s, replace, flen *sizeof(short));
        s += flen;
        sslen = slen;
    }
    return buf;
}
예제 #4
0
파일: clock.c 프로젝트: lacombar/netbsd-alc
int
clockmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
{
	if (matchname("clock", auxp))
		return(1);
	return(0);
}
예제 #5
0
/*
 * we make sure to only init things once.  this is somewhat
 * tricky regarding the console.
 */
int
grfccmatch(device_t parent, cfdata_t cf, void *aux)
{
	static int ccconunit = -1;
	char *mainbus_name = aux;
	extern const struct cdevsw view_cdevsw;

	/*
	 * allow only one cc console
	 */
	if (amiga_realconfig == 0 && ccconunit != -1)
		return(0);
	if (matchname("grfcc", mainbus_name) == 0)
		return(0);
	if (amiga_realconfig == 0 || ccconunit != cf->cf_unit) {
		if (grfcc_probe() == 0)
			return(0);
		viewprobe();
		/*
		 * XXX nasty hack. opens view[0] and never closes.
		 */
		if ((*view_cdevsw.d_open)(0, 0, 0, NULL))
			return(0);
		if (amiga_realconfig == 0) {
			ccconunit = cf->cf_unit;
			cfdata = cf;
		}
	}
	return(1);
}
예제 #6
0
파일: extfcts.c 프로젝트: sarachour/topaz
extern "C" int scanbind(char **bvec, char *name) {
  int i;

  for (i = 0; bvec[i] != NULL; i++)
    if (matchname(bvec[i], name))
      return i;
  return -1;
}
int
wdc_amiga_probe(device_t parent, cfdata_t cfp, void *aux)
{
	if ((!is_a4000() && !is_a1200() && !is_a600()) ||
	    !matchname(aux, "wdc"))
		return(0);
	return 1;
}
예제 #8
0
long scanbind(string bvec[], string name)
{
    long i;

    for (i = 0; bvec[i] != NULL; i++)
        if (matchname(bvec[i], name))
            return (i);
    return (-1);
}
예제 #9
0
char *get_peer_name(int fd, BOOL force_lookup)
{
	static pstring name_buf;
	pstring tmp_name;
	static fstring addr_buf;
	struct hostent *hp;
	struct in_addr addr;
	char *p;

	/* reverse lookups can be *very* expensive, and in many
	   situations won't work because many networks don't link dhcp
	   with dns. To avoid the delay we avoid the lookup if
	   possible */
	if (!lp_hostname_lookups() && (force_lookup == False)) {
		return get_peer_addr(fd);
	}
	
	p = get_peer_addr(fd);

	/* it might be the same as the last one - save some DNS work */
	if (strcmp(p, addr_buf) == 0) 
		return name_buf;

	pstrcpy(name_buf,"UNKNOWN");
	if (fd == -1) 
		return name_buf;

	fstrcpy(addr_buf, p);

	addr = *interpret_addr2(p);
	
	/* Look up the remote host name. */
	if ((hp = gethostbyaddr((char *)&addr.s_addr, sizeof(addr.s_addr), AF_INET)) == 0) {
		DEBUG(1,("Gethostbyaddr failed for %s\n",p));
		pstrcpy(name_buf, p);
	} else {
		pstrcpy(name_buf,(char *)hp->h_name);
		if (!matchname(name_buf, addr)) {
			DEBUG(0,("Matchname failed on %s %s\n",name_buf,p));
			pstrcpy(name_buf,"UNKNOWN");
		}
	}

	/* can't pass the same source and dest strings in when you 
	   use --enable-developer or the clobber_region() call will 
	   get you */
	
	pstrcpy( tmp_name, name_buf );
	alpha_strcpy(name_buf, tmp_name, "_-.", sizeof(name_buf));
	if (strstr(name_buf,"..")) {
		pstrcpy(name_buf, "UNKNOWN");
	}

	return name_buf;
}
예제 #10
0
/*ARGSUSED*/
int
parmatch(device_t parent, cfdata_t cf, void *aux)
{
	static int par_found = 0;

	if (!matchname((char *)aux, "par") || par_found)
		return(0);

	par_found = 1;
	return(1);
}
예제 #11
0
파일: ms.c 프로젝트: lacombar/netbsd-alc
int
msmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
{
	static int ms_matched = 0;

	/* Allow only one instance. */
	if (!matchname((char *)auxp, "ms") || ms_matched)
		return 0;

	ms_matched = 1;
	return 1;
}
예제 #12
0
/*
 * One of us is on every DraCo motherboard,
 */
int
drscmatch(device_t parent, cfdata_t cf, void *aux)
{
	static int drsc_matched = 0;

	/* Allow only one instance. */
	if (!is_draco() || !matchname(aux, "drsc") || drsc_matched)
		return (0);

	drsc_matched = 1;
	return(1);
}
예제 #13
0
int
drsupiomatch(device_t parent, cfdata_t cf, void *aux)
{
	static int drsupio_matched = 0;

	/* Exactly one of us lives on the DraCo */
	if (!is_draco() || !matchname(aux, "drsupio") || drsupio_matched)
		return 0;

	drsupio_matched = 1;
	return 1;
}
예제 #14
0
파일: drsc.c 프로젝트: lacombar/netbsd-alc
/*
 * One of us is on every DraCo motherboard,
 */
int
drscmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
{
	static int drsc_matched = 0;

	/* Allow only one instance. */
	if (!is_draco() || !matchname(auxp, "drsc") || drsc_matched)
		return (0);

	drsc_matched = 1;
	return(1);
}
예제 #15
0
파일: amidisplaycc.c 프로젝트: MarginC/kame
static int
amidisplaycc_match(struct device *pdp, struct cfdata *cfp, void *auxp)
{
	char *name = auxp;

	if (matchname("amidisplaycc", name) == 0)
		return (0);

	/* Allow only one of us now. Not sure about that. */
	if (cfp->cf_unit != 0)
		return (0);

	return 1;
}
예제 #16
0
int
auccmatch(device_t parent, cfdata_t cf, void *aux)
{
	static int aucc_matched = 0;

	if (!matchname((char *)aux, "aucc") ||
#ifdef DRACO
	    is_draco() ||
#endif
	    aucc_matched)
		return 0;

	aucc_matched = 1;
	return 1;
}
예제 #17
0
파일: util_sock.c 프로젝트: CTU-OSP/mc
/*******************************************************************
 return the DNS name of the client 
 ******************************************************************/
char *
client_name (int fd)
{
    struct sockaddr sa;
    struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
    unsigned int length = sizeof (sa);
    static pstring name_buf;
    struct hostent *hp;
    static int last_fd = -1;

    if (global_client_name_done && last_fd == fd)
        return name_buf;

    last_fd = fd;
    global_client_name_done = False;

    pstrcpy (name_buf, "UNKNOWN");

    if (fd == -1)
    {
        return name_buf;
    }

    if (getpeername (fd, &sa, &length) < 0)
    {
        DEBUG (0, ("getpeername failed. Error was %s\n", unix_error_string (errno)));
        return name_buf;
    }

    /* Look up the remote host name. */
    if ((hp = gethostbyaddr ((char *) &sockin->sin_addr, sizeof (sockin->sin_addr), AF_INET)) == 0)
    {
        DEBUG (1, ("Gethostbyaddr failed for %s\n", client_addr (fd)));
        StrnCpy (name_buf, client_addr (fd), sizeof (name_buf) - 1);
    }
    else
    {
        StrnCpy (name_buf, (char *) hp->h_name, sizeof (name_buf) - 1);
        if (!matchname (name_buf, sockin->sin_addr))
        {
            DEBUG (0, ("Matchname failed on %s %s\n", name_buf, client_addr (fd)));
            pstrcpy (name_buf, "UNKNOWN");
        }
    }
    global_client_name_done = True;
    return name_buf;
}
예제 #18
0
파일: untar.c 프로젝트: mwiebe/nsis-untgz
/* Tar file extraction
 * gzFile in, handle of input tarball opened with gzopen
 * int cm, compressionMethod
 * int junkPaths, nonzero indicates to ignore stored path (don't create directories)
 * enum KeepMode keep, indicates to perform if file exists
 * int iCnt, char *iList[], argv style list of files to extract, {0,NULL} for all
 * int xCnt, char *xList[], argv style list of files NOT to extract, {0,NULL} for none
 * int failOnHardLinks, if nonzero then will treat failure to create a hard link same as
 *   failure to create a regular file, 0 prints a warning if fails - note that hardlinks
 *   will always fail on Windows prior to NT 5 (Win 2000) or later and non NTFS file systems.
 *
 * returns 0 (or positive value) on success
 * returns negative value on error, where
 *   -1 means error reading from tarball
 *   -2 means error extracting file from tarball
 *   -3 means error creating hard link
 */
int tgz_extract(gzFile in, int cm, int junkPaths, enum KeepMode keep, int iCnt, TCHAR *iList[], int xCnt, TCHAR *xList[], int failOnHardLinks)
{
  int           getheader = 1;    /* assume initial input has a tar header */
  HANDLE        outfile = INVALID_HANDLE_VALUE;

  union         tar_buffer buffer;
  unsigned long remaining;
  TCHAR          fname[BLOCKSIZE]; /* must be >= BLOCKSIZE bytes */
  time_t        tartime;

  /* do any prep work for extracting from compressed TAR file */
  if (cm_init(in, cm))
  {
    PrintMessage(_T("tgz_extract: unable to initialize decompression method."));
    cm_cleanup(cm);
    return -1;
  }
  
  while (1)
  {
    if (readBlock(cm, &buffer) < 0) return -1;
      
    /*
     * If we have to get a tar header
     */
    if (getheader >= 1)
    {
      /*
       * if we met the end of the tar
       * or the end-of-tar block,
       * we are done
       */
      if (/* (len == 0)  || */ (buffer.header.name[0]== 0)) break;

      /* compute and check header checksum, support signed or unsigned */
      if (!valid_checksum(&(buffer.header)))
      {
        PrintMessage(_T("tgz_extract: bad header checksum"));
        cm_cleanup(cm);
        return -1;
      }

      /* store time, so we can set the timestamp on files */
      tartime = (time_t)getoct(buffer.header.mtime,12);

      /* copy over filename chunk from header, avoiding overruns */
      if (getheader == 1) /* use normal (short or posix long) filename from header */
      {
        /* NOTE: prepends any prefix, including separator, and ensures terminated */
        memset(fname, 0, sizeof(fname));
		getFullName(&buffer, fname);
      }
      else /* use (GNU) long filename that preceeded this header */
      {
#if 0
        /* if (strncmp(fname,buffer.header.name,SHORTNAMESIZE-1) != 0) */
        char fs[SHORTNAMESIZE];   /* force strings to same max len, then compare */
        lstrcpyn(fs, fname, SHORTNAMESIZE);
        fs[SHORTNAMESIZE-1] = '\0';
        buffer.header.name[SHORTNAMESIZE-1] = '\0';
        if (lstrcmp(fs, buffer.header.name) != 0)
        {
          PrintMessage(_T("tgz_extract: mismatched long filename"));
          cm_cleanup(cm);
          return -1;
        }
#else
		PrintMessage(_T("tgz_extract: using GNU long filename [%s]"), fname);
#endif
      }
      /* LogMessage("buffer.header.name is:");  LogMessage(fname); */


      switch (buffer.header.typeflag)
      {
        case DIRTYPE:
		  dirEntry:
          if (!junkPaths)
          {
            safetyStrip(fname);
            makedir(fname);
          }
	      break;
		case LNKTYPE:   /* hard link */ 
		case CONTTYPE:  /* contiguous file, for compatibility treat as normal */
        case REGTYPE:
        case AREGTYPE:
	      /* Note: a file ending with a / may actually be a BSD tar directory entry */
	      if (fname[strlen(fname)-1] == '/')
	        goto dirEntry;

	      remaining = getoct(buffer.header.size,12);
	      if ( /* add (remaining > 0) && to ignore 0 zero byte files */
               ( (iList == NULL) || (matchname(fname, iCnt, iList, junkPaths)) ) &&
               (!matchname(fname, xCnt, xList, junkPaths))
             )
	      {
			  if (!junkPaths) /* if we want to use paths as stored */
			  {
	              /* try creating directory */
	              TCHAR *p = tstrrchr(fname, '/');
	              if (p != NULL) 
	              {
	                *p = '\0';
	                makedir(fname);
	                *p = '/';
	              }
			  }
			  else
			  {
	              /* try ignoring directory */
	              TCHAR *p = tstrrchr(fname, '/');
	              if (p != NULL) 
	              {
	                /* be sure terminating '\0' is copied and */
	                /* use ansi memcpy equivalent that handles overlapping regions */
	                MoveMemory(fname, p+1, (strlen(p+1) + 1) * sizeof(TCHAR) );
	              }
	          }
	          if (*fname) /* if after stripping path a fname still exists */
	          {
	            /* Attempt to open the output file and report action taken to user */
	            const TCHAR szERRMsg[] = _T("Error: Could not create file "),
	                        szSUCMsg[] = _T("Writing "),
	                        szSKPMsg[] = _T("Skipping ");
	            const TCHAR * szMsg = szSUCMsg;

	            safetyStrip(fname);

				if (buffer.header.typeflag == LNKTYPE)
				{
					outfile = INVALID_HANDLE_VALUE;
					/* create a hardlink if possible, else produce just a warning unless failOnHardLinks is true */
					if (!MakeHardLink(fname, buffer.header.linkname))
					{
						PrintMessage(_T("Warning: unable to create hard link %s [%d]"), fname, GetLastError());
						if (failOnHardLinks) 
						{
							cm_cleanup(cm);
							return -3;
						}
					}
					else
					{
						outfile = CreateFile(fname,GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
						goto setTimeAndCloseFile;
					}
				} else 
				{
	            /* Open the file for writing mode, creating if doesn't exist and truncating if exists and overwrite mode */
	            outfile = CreateFile(fname,GENERIC_WRITE,FILE_SHARE_READ,NULL,(keep==OVERWRITE)?CREATE_ALWAYS:CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL);

	            /* failed to open file, either valid error (like open) or it already exists and in a keep mode */
	            if (outfile == INVALID_HANDLE_VALUE)
	            {
	              /* if skip existing or only update existing and failed to open becauses exists */
	              if ((keep!=OVERWRITE) && (GetLastError()==ERROR_FILE_EXISTS))
	              {
	                /* assume skipping initially (mode==SKIP or ==UPDATE with existing file newer) */
	                szMsg = szSKPMsg; /* and update output message accordingly */

					/* if in update mode, check filetimes and reopen in overwrite mode */
	                if (keep == UPDATE)
	                {
	                  FILETIME ftm_a;
                      HANDLE h;
                      WIN32_FIND_DATA ffData;
 
	                  cnv_tar2win_time(tartime, &ftm_a); /* archive file time */
	                  h = FindFirstFile(fname, &ffData); /* existing file time */

                      if (h!=INVALID_HANDLE_VALUE)
                        FindClose(h);  /* cleanup search handle */
                      else
                        goto ERR_OPENING;

                      /* compare date+times, is one in tarball newer? */
                      if (*((LONGLONG *)&ftm_a) > *((LONGLONG *)&(ffData.ftLastWriteTime)))
                      {
                        outfile = CreateFile(fname,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
                        if (outfile == INVALID_HANDLE_VALUE) goto ERR_OPENING;
                        szMsg = szSUCMsg;
                      }
	                }
	              }
	              else /* in overwrite mode or failed for some other error than exists */
	              {
                    ERR_OPENING:
	                PrintMessage(_T("%s%s [%d]"), szERRMsg, fname, GetLastError());
	                cm_cleanup(cm);
	                return -2;
	              }
	            }

 	            /* Inform user of current extraction action (writing, skipping file XYZ) */
	            PrintMessage(_T("%s%s"), szMsg, fname);
				}
	          }
	      }
	      else
	          outfile = INVALID_HANDLE_VALUE;

	      /*
	       * could have no contents, in which case we close the file and set the times
	       */
	      if (remaining > 0)
	          getheader = 0;
		  else
	      {
	          setTimeAndCloseFile:
	          getheader = 1;
	          if (outfile != INVALID_HANDLE_VALUE)
	          {
	              FILETIME ftm;
 
	              cnv_tar2win_time(tartime, &ftm);
	              SetFileTime(outfile,&ftm,NULL,&ftm);
	              CloseHandle(outfile);
	              outfile = INVALID_HANDLE_VALUE;
	          }
		  }

	      break;
		case GNUTYPE_LONGLINK:
		case GNUTYPE_LONGNAME:
		{
	      remaining = getoct(buffer.header.size,12);
	      if (readBlock(cm, fname) < 0) return -1;
	      fname[BLOCKSIZE-1] = '\0';
	      if ((remaining >= BLOCKSIZE) || ((unsigned)strlen(fname) > remaining))
	      {
	          PrintMessage(_T("tgz_extract: invalid long name"));
	          cm_cleanup(cm);
	          return -1;
	      }
	      getheader = 2;
	      break;
		}
        default:
/*
	      if (action == TGZ_LIST)
	          printf(" %s     <---> %s\n",strtime(&tartime),fname);
*/
	      break;
      }
    }
    else  /* (getheader == 0) */
    {
      unsigned int bytes = (remaining > BLOCKSIZE) ? BLOCKSIZE : remaining;
	  unsigned long bwritten;

      if (outfile != INVALID_HANDLE_VALUE)
      {
          WriteFile(outfile,buffer.buffer,bytes,&bwritten,NULL);
		  if (bwritten != bytes)
          {
			  PrintMessage(_T("Error: write failed for %s"), fname);
              CloseHandle(outfile);
              DeleteFile(fname);

              cm_cleanup(cm);
              return -2;
          }
      }
      remaining -= bytes;
      if (remaining == 0) goto setTimeAndCloseFile;
    }
  } /* while(1) */
  
  cm_cleanup(cm);

  return 0;
}
예제 #19
0
int funTar (DataSource *src, int action, int arg, int argc,
            char **argv, TarCallbackFun cb, void *data)
{
  union  tar_buffer buffer;
  int    len;
  int    err;
  int    getheader = 1;
  int    remaining = 0;
  FILE   *outfile = NULL;
  char   fname[BLOCKSIZE];
  int    tarmode;
  time_t tartime;
  struct attr_item *attributes = NULL;
  int    ctr = 0;
  int extracting = 0;


  while (1)
    {
      ctr++;
      len = src->read(src->data, &buffer, BLOCKSIZE, src);
      if (len < 0)
	  error(src->throwError(src->data, &err, src));
      /*
       * Always expect complete blocks to process
       * the tar information.
       */
      if (len != BLOCKSIZE)
        {
          action = TGZ_INVALID; /* force error exit */
          remaining = 0;        /* force I/O cleanup */
        }

      /*
       * If we have to get a tar header
       */
      if (getheader >= 1)
        {
          /*
           * if we met the end of the tar
           * or the end-of-tar block,
           * we are done
           */
          if (len == 0 || buffer.header.name[0] == 0)
            break;

          tarmode = getoct(buffer.header.mode,8);
          tartime = (time_t)getoct(buffer.header.mtime,12);
          if (tarmode == -1 || tartime == (time_t)-1)
            {
              buffer.header.name[0] = 0;
              action = TGZ_INVALID;
            }

          if (getheader == 1)
            {
              strncpy(fname,buffer.header.name,SHORTNAMESIZE);
   	      extracting = 0;
              if (fname[SHORTNAMESIZE-1] != 0)
                  fname[SHORTNAMESIZE] = 0;
            }
          else
            {
              /*
               * The file name is longer than SHORTNAMESIZE
               */
              if (strncmp(fname,buffer.header.name,SHORTNAMESIZE-1) != 0)
                  error("bad long name");
              getheader = 1;
            }

          /*
           * Act according to the type flag
           */
          switch (buffer.header.typeflag)
            {
            case DIRTYPE:
               if (action == TGZ_LIST) {
                 cb(ctr, DIRTYPE, tartime, fname, remaining, data);
                  /* printf(" %s     <dir> %s\n",strtime(&tartime),fname); */
               }
               else if (action == TGZ_EXTRACT)
                {
		    /* makedir(fname); */
 	   	  extracting = 0;
                  push_attr(&attributes,fname,tarmode,tartime);
                }
              break;
            case REGTYPE:
            case AREGTYPE:
              remaining = getoct(buffer.header.size,12);
              if (remaining == -1)
                {
                  action = TGZ_INVALID;
                  break;
                }
              if (action == TGZ_LIST) {
                  cb(ctr, buffer.header.typeflag, tartime, fname, remaining, data);
                 /* printf(" %s %9d %s\n",strtime(&tartime),remaining,fname); */
              }
              else if (action == TGZ_EXTRACT)
                {
		    extracting = matchname(arg,argc,argv,fname);
                }
              getheader = 0;
              break;
            case GNUTYPE_LONGLINK:
            case GNUTYPE_LONGNAME:
              remaining = getoct(buffer.header.size,12);
              if (remaining < 0 || remaining >= BLOCKSIZE)
                {
                  action = TGZ_INVALID;
                  break;
                }
              len = src->read(src->data, fname, BLOCKSIZE, src);
              if (len < 0)
		  error(src->throwError(src->data, &err, src));
              if (fname[BLOCKSIZE-1] != 0 || (int)strlen(fname) > remaining)
                {
                  action = TGZ_INVALID;
                  break;
                }
              getheader = 2;
              break;
            default:
                if (action == TGZ_LIST) {
                    cb(ctr, '\0', tartime, fname, remaining, data);
                    /* printf(" %s     <---> %s\n",strtime(&tartime),fname); */
                }
              break;
            }
        }
      else
        {
          unsigned int bytes = (remaining > BLOCKSIZE) ? BLOCKSIZE : remaining;

	  if(extracting && action == TGZ_EXTRACT)
	      ((TarExtractCallbackFun ) cb)(fname, buffer.buffer, bytes, remaining, data);
          remaining -= bytes;
        }

      if (remaining == 0)
        {
          getheader = 1;
          if(extracting && action == TGZ_EXTRACT) /* Close this file. */
	      ((TarExtractCallbackFun ) cb)(fname, NULL, 0, remaining, data);
	  if (action != TGZ_INVALID)
                push_attr(&attributes,fname,tarmode,tartime);
        }

      /*
       * Abandon if errors are found
       */
      if (action == TGZ_INVALID)
        {
          error("broken archive");
          break;
        }
    }

  /*
   * Restore file modes and time stamps
   */
  restore_attr(&attributes);

  return 0;
}
예제 #20
0
static int
pccard_probe(struct device *dev, struct cfdata *cfd, void *aux)
{

	return (/*is_a600() || */is_a1200()) && matchname(aux, "pccard");
}
예제 #21
0
파일: openbsd.c 프로젝트: ColeJackes/pcp
/*
 * Initialise the agent (both daemon and DSO).
 * 
 * Do mapping from sysclt(3) names to mibs.
 * Collect some global constants.
 * Build the system-specific, but not dynamic, instance domains,
 * e.g. CPU_INDOM.
 * Initialize the kernel memory reader.
 */
void 
openbsd_init(pmdaInterface *dp)
{
    int			i;
    int			m;
    int			sts;
    struct clockinfo	clockrates;
    size_t		sz;
    int			mib[CTL_MAXNAME];	/* enough for longest mib key */
    char		iname[16];		/* enough for cpuNN.. */

    if (isDSO) {
	char	mypath[MAXPATHLEN];
	int sep = __pmPathSeparator();
	snprintf(mypath, sizeof(mypath), "%s%c" "openbsd" "%c" "help",
		pmGetConfig("PCP_PMDAS_DIR"), sep, sep);
	pmdaDSO(dp, PMDA_INTERFACE_5, "openbsd DSO", mypath);
    } else {
	__pmSetProcessIdentity(username);
    }

    if (dp->status != 0)
	return;

    dp->version.four.fetch = openbsd_fetch;
    dp->version.four.instance = openbsd_instance;

    pmdaSetFetchCallBack(dp, openbsd_fetchCallBack);

    pmdaInit(dp, indomtab, indomtablen, metrictab, metrictablen);

    /*
     * Link metrictab[] entries via m_user to map[] entries based on
     * matching sysctl(3) name
     *
     * also translate the sysctl(3) name to a mib
     */
    for (m = 0; m < metrictablen; m++) {
	if (pmid_cluster(metrictab[m].m_desc.pmid) != CL_SYSCTL) {
	    /* not using sysctl(3) */
	    continue;
	}
	for (i = 0; i < maplen; i++) {
	    if (matchname(map[i].m_pcpname, (char *)metrictab[m].m_user)) {
		if (map[i].m_mib == NULL) {
		    /*
		     * multiple metrictab[] entries may point to the same
		     * mib[] entry, but this is the first time for this
		     * mib[] entry ...
		     */
		    map[i].m_miblen = sizeof(mib);
		    sts = sysctlnametomib(map[i].m_name, mib, &map[i].m_miblen);
		    if (sts == 0) {
			map[i].m_mib = (int *)malloc(map[i].m_miblen*sizeof(map[i].m_mib[0]));
			if (map[i].m_mib == NULL) {
			    fprintf(stderr, "Error: %s (%s): failed mib alloc for sysctl metric \"%s\"\n", map[i].m_pcpname, pmIDStr(metrictab[m].m_desc.pmid), map[i].m_name);
			    __pmNoMem("openbsd_init: mib", map[i].m_miblen*sizeof(map[i].m_mib[0]), PM_FATAL_ERR);
			    /*NOTREACHED*/
			}
			memcpy(map[i].m_mib, mib, map[i].m_miblen*sizeof(map[i].m_mib[0]));
		    }
		    else {
			fprintf(stderr, "Error: %s (%s): failed sysctlnametomib(\"%s\", ...): %s\n", map[i].m_pcpname, pmIDStr(metrictab[m].m_desc.pmid), map[i].m_name, pmErrStr(-errno));
			metrictab[m].m_user = (void *)&bad_mib;
		    }
		}
#ifdef PCP_DEBUG
		if (pmDebug & DBG_TRACE_APPL0) {
		    int	p;
		    fprintf(stderr, "Info: %s (%s): sysctl metric \"%s\" -> ", (char *)metrictab[m].m_user, pmIDStr(metrictab[m].m_desc.pmid), map[i].m_name);
		    for (p = 0; p < map[i].m_miblen; p++) {
			if (p > 0) fputc('.', stderr);
			fprintf(stderr, "%d", map[i].m_mib[p]);
		    }
		    fputc('\n', stderr);
		}
#endif
		metrictab[m].m_user = (void *)&map[i];
		break;
	    }
	}
	if (i == maplen) {
	    fprintf(stderr, "Error: %s (%s): cannot match name in sysctl map[]\n", (char *)metrictab[m].m_user, pmIDStr(metrictab[m].m_desc.pmid));
	    metrictab[m].m_user = (void *)&bad_mib;
	}
    }

    /*
     * Collect some global constants needed later ...
     */
    mib[0] = CTL_KERN;
    mib[1] = KERN_CLOCKRATE;
    sz = sizeof(clockrates);
    sts = sysctl(mib, 2, &clockrates, &sz, NULL, 0);
    if (sts < 0) {
	fprintf(stderr, "Fatal Error: sysctl(\"kern.clockrate\", ...) failed: %s\n", pmErrStr(-errno));
	exit(1);
    }
    cpuhz = clockrates.stathz;
#ifdef PCP_DEBUG
    if (pmDebug & DBG_TRACE_APPL0)
	fprintf(stderr, "Info: CPU time \"hz\" = %d\n", cpuhz);
#endif

    mib[0] = CTL_HW;
    mib[1] = HW_NCPU;
    sz = sizeof(ncpu);
    sts = sysctl(mib, 2, &ncpu, &sz, NULL, 0);
    if (sts < 0) {
	fprintf(stderr, "Fatal Error: sysctl(\"hw.ncpu\", ...) failed: %s\n", pmErrStr(-errno));
	exit(1);
    }
#ifdef PCP_DEBUG
    if (pmDebug & DBG_TRACE_APPL0)
	fprintf(stderr, "Info: ncpu = %d\n", ncpu);
#endif

    mib[0] = CTL_HW;
    mib[1] = HW_PAGESIZE;
    sz = sizeof(pagesize);
    sts = sysctl(mib, 2, &pagesize, &sz, NULL, 0);
    if (sts < 0) {
	fprintf(stderr, "Fatal Error: sysctl(\"hw.pagesize\", ...) failed: %s\n", pmErrStr(-errno));
	exit(1);
    }
#ifdef PCP_DEBUG
    if (pmDebug & DBG_TRACE_APPL0)
	fprintf(stderr, "Info: VM pagesize = %d\n", pagesize);
#endif

    uname(&kernel_uname);

    /*
     * Build some instance domains ...
     */
    indomtab[CPU_INDOM].it_numinst = ncpu;
    indomtab[CPU_INDOM].it_set = (pmdaInstid *)malloc(ncpu * sizeof(pmdaInstid));
    if (indomtab[CPU_INDOM].it_set == NULL) {
	__pmNoMem("openbsd_init: CPU_INDOM it_set", ncpu * sizeof(pmdaInstid), PM_FATAL_ERR);
	/*NOTREACHED*/
    }
    for (i = 0; i < ncpu; i++) {
	indomtab[CPU_INDOM].it_set[i].i_inst = i;
	snprintf(iname, sizeof(iname), "cpu%d", i);
	indomtab[CPU_INDOM].it_set[i].i_name = strdup(iname);
	if (indomtab[CPU_INDOM].it_set[i].i_name == NULL) {
	    __pmNoMem("openbsd_init: CPU_INDOM strdup iname", strlen(iname), PM_FATAL_ERR);
	    /*NOTREACHED*/
	}
    }

    kmemread_init();
}