Exemple #1
0
void
setproctitle(const char *fmt, ...)
{
#if SPT_TYPE != SPT_NONE
	va_list ap;
	char buf[1024];
	int r;
	extern char *__progname;
#if SPT_TYPE == SPT_PSTAT
	union pstun pst;
#endif

#if SPT_TYPE == SPT_REUSEARGV
	if (argv_env_len <= 0)
		return;
#endif

	r = -1;
	va_start(ap, fmt);
	r = vsnprintf(buf, sizeof(buf), fmt, ap);
	va_end(ap);
	if (r == -1 || (size_t)r >= sizeof(buf))
		return;

#if SPT_TYPE == SPT_PSTAT
	pst.pst_command = buf;
	pstat(PSTAT_SETCMD, pst, strlen(buf), 0, 0);
#elif SPT_TYPE == SPT_REUSEARGV
	size_t len = strlcpy(argv_start, buf, argv_env_len);
	for(; len < argv_env_len; len++)
		argv_start[len] = SPT_PADCHAR;
#endif

#endif /* SPT_NONE */
}
Exemple #2
0
// verify that an inode is still valid.
// that is, there's a process with the given PID running, and it's an instance of the same program that created it.
// to speed this up, only check the hash of the process binary if the modtime has changed
// return 1 if valid 
// return 0 if not valid 
// return negative on error
int runfs_inode_is_valid( struct runfs_inode* inode, pid_t pid ) {
   
   int rc = 0;
   struct pstat ps;
   int flags = 0;
   
   memset( &ps, 0, sizeof(struct pstat) );
   
   if( inode->verify_discipline & RUNFS_VERIFY_HASH ) {
      flags |= PSTAT_HASH;
   }
   
   rc = pstat( pid, &ps, flags );
   if( rc < 0 ) {
      fskit_error("pstat(%d) rc = %d\n", pid, rc );
      return rc;
   }
   
   rc = runfs_inode_is_created_by_proc( inode, &ps, inode->verify_discipline );
   if( rc < 0 ) {
      fskit_error("runfs_inode_is_created_by_proc(%d) rc = %d\n", pid, rc );
      return rc;
   }
   
   return rc;
}
Exemple #3
0
/*
 * Set a new process title.
 * Returns the appropriate error code if if there's an error
 * (like the functionality is compile time disabled, or the
 * save_ps_args() was not called.
 * Else returns 0 on success.
 */
int set_ps_title(const char* title)
{
    int rc = is_ps_title_available();
    if (rc != PS_TITLE_SUCCESS)
        return rc;

    strncpy(ps_buffer, title, ps_buffer_size);
    ps_buffer[ps_buffer_size - 1] = '\0';
    ps_buffer_cur_len = strlen(ps_buffer);

#ifdef PS_USE_SETPROCTITLE
    setproctitle("%s", ps_buffer);
#endif

#ifdef PS_USE_PSTAT
    {
        union pstun pst;

        pst.pst_command = ps_buffer;
        pstat(PSTAT_SETCMD, pst, ps_buffer_cur_len, 0, 0);
    }
#endif /* PS_USE_PSTAT */

#ifdef PS_USE_PS_STRINGS
    PS_STRINGS->ps_nargvstr = 1;
    PS_STRINGS->ps_argvstr = ps_buffer;
#endif /* PS_USE_PS_STRINGS */

#ifdef PS_USE_CLOBBER_ARGV
    /* pad unused memory */
    if (ps_buffer_cur_len < ps_buffer_size)
    {
        memset(ps_buffer + ps_buffer_cur_len, PS_PADDING,
               ps_buffer_size - ps_buffer_cur_len);
    }
#endif /* PS_USE_CLOBBER_ARGV */

#ifdef PS_USE_WIN32
    {
    	MySetConsoleTitle set_title = NULL;
	HMODULE hMod = LoadLibrary("kernel32.dll");

	if (!hMod) {
            return PS_TITLE_WINDOWS_ERROR;
	}

	/* NOTE we don't use _UNICODE*/
	set_title = (MySetConsoleTitle)GetProcAddress(hMod, "SetConsoleTitleA");
	if (!set_title) {
            return PS_TITLE_WINDOWS_ERROR;
	}

        if (!set_title(ps_buffer)) {
            return PS_TITLE_WINDOWS_ERROR;
	}
    }
#endif /* PS_USE_WIN32 */

    return PS_TITLE_SUCCESS;
}
void
setproctitle(const char *fmt, ...)
{
#if SPT_TYPE != SPT_NONE
	va_list ap;
	char ptitle[1024];
	size_t len;
	size_t argvlen;
#if SPT_TYPE == SPT_PSTAT
	union pstun pst;
#endif

#if SPT_TYPE == SPT_REUSEARGV
	if (argv_env_len <= 0)
		return;
#endif

	va_start(ap, fmt);
	if (fmt != NULL) {
		vsnprintf(ptitle, sizeof(ptitle) , fmt, ap);
	}
	va_end(ap);

#if SPT_TYPE == SPT_PSTAT
	pst.pst_command = ptitle;
	pstat(PSTAT_SETCMD, pst, strlen(ptitle), 0, 0);
#elif SPT_TYPE == SPT_REUSEARGV
	len = strlcpy(argv_start, ptitle, argv_env_len);
	argvlen = len > argv_len ? argv_env_len : argv_len;
	for(; len < argvlen; len++)
		argv_start[len] = SPT_PADCHAR;
#endif

#endif /* SPT_NONE */
}
Exemple #5
0
int
main (int argc, char **argv)
{
  int i;

  if (argc <= 1) {
    getfh (".");
    getfh2 (".");
    pstat (".");
    pids (".");
  }
  else
    for (i = 1; i < argc; i++) {
      getfh (argv[i]);
      getfh2 (argv[i]);
      pstat (argv[i]);
      pids (argv[i]);
    }
  return 0;
}
void
vsf_sysutil_setproctitle_internal(const char* p_buf)
{
  struct mystr proctitle_str = INIT_MYSTR;
  union pstun p;
  str_alloc_text(&proctitle_str, "vsftpd: ");
  str_append_text(&proctitle_str, p_buf);
  p.pst_command = str_getbuf(&proctitle_str);
  pstat(PSTAT_SETCMD, p, 0, 0, 0);
  str_free(&proctitle_str);
}
Exemple #7
0
/******************************************************************************
 *                                                                            *
 * Function: setproctitle_set_status                                          *
 *                                                                            *
 * Purpose: set a process command line displayed by "ps" command.             *
 *                                                                            *
 * Comments: call this function when a process starts some interesting task.  *
 *           Program name argv[0] will be displayed "as-is" followed by ": "  *
 *           and a status message.                                            *
 *                                                                            *
 ******************************************************************************/
void	setproctitle_set_status(const char *status)
{
#if defined(PS_OVERWRITE_ARGV)
	static int	initialized = 0;

	if (1 == initialized)
	{
		size_t	msg_size;

		msg_size = zbx_strlcpy(ps_buf, status, ps_buf_size);

		if (prev_msg_size > msg_size)
			memset(ps_buf + msg_size + 1, '\0', ps_buf_size - msg_size - 1);

		prev_msg_size = msg_size;
	}
	else if (NULL != ps_buf)
	{
		size_t	start_pos;

		/* Initialization has not been moved to setproctitle_save_env() because setproctitle_save_env()	*/
		/* is called from the main process and we do not change its command line.			*/
		/* argv[] changing takes place only in child processes.						*/

#if defined(PS_CONCAT_ARGV)
		start_pos = strlen(argv_int[0]);
#else
		start_pos = strlen(ps_buf);
#endif
		if (start_pos + 2 < ps_buf_size)	/* is there space for ": " ? */
		{
			zbx_strlcpy(ps_buf + start_pos, ": ", (size_t)3);
			ps_buf += start_pos + 2;
			ps_buf_size -= start_pos + 2;	/* space after "argv[copy_first]: " for status message */

			memset(ps_buf, '\0', ps_buf_size);
			prev_msg_size = zbx_strlcpy(ps_buf, status, ps_buf_size);

			initialized = 1;
		}
	}
#elif defined(PS_PSTAT_ARGV)
	if (NULL != p_msg)
	{
		union pstun	pst;

		zbx_strlcpy(p_msg, status, ps_buf_size_msg);
		pst.pst_command = ps_buf;
		pstat(PSTAT_SETCMD, pst, strlen(ps_buf), 0, 0);
	}
#endif
}
Exemple #8
0
/*
 * Set a new process title.
 * Returns the appropriate error code if if there's an error
 * (like the functionality is compile time disabled, or the
 * save_ps_args() was not called.
 * Else returns 0 on success.
 */
int set_ps_title(const char* title)
{
    int rc = is_ps_title_available();
    if (rc != PS_TITLE_SUCCESS)
        return rc;

    strncpy(ps_buffer, title, ps_buffer_size);
    ps_buffer[ps_buffer_size - 1] = '\0';
    ps_buffer_cur_len = strlen(ps_buffer);

#ifdef PS_USE_SETPROCTITLE
    setproctitle("%s", ps_buffer);
#endif

#ifdef PS_USE_PSTAT
    {
        union pstun pst;

        pst.pst_command = ps_buffer;
        pstat(PSTAT_SETCMD, pst, ps_buffer_cur_len, 0, 0);
    }
#endif /* PS_USE_PSTAT */

#ifdef PS_USE_PS_STRINGS
    PS_STRINGS->ps_nargvstr = 1;
    PS_STRINGS->ps_argvstr = ps_buffer;
#endif /* PS_USE_PS_STRINGS */

#ifdef PS_USE_CLOBBER_ARGV
    /* pad unused memory */
    if (ps_buffer_cur_len < ps_buffer_size)
    {
        memset(ps_buffer + ps_buffer_cur_len, PS_PADDING,
               ps_buffer_size - ps_buffer_cur_len);
    }
#endif /* PS_USE_CLOBBER_ARGV */

#ifdef PS_USE_WIN32
    {
	wchar_t *ps_buffer_w = php_win32_cp_any_to_w(ps_buffer);

        if (!ps_buffer_w || !SetConsoleTitleW(ps_buffer_w)) {
            return PS_TITLE_WINDOWS_ERROR;
	}

	free(ps_buffer_w);
    }
#endif /* PS_USE_WIN32 */

    return PS_TITLE_SUCCESS;
}
Exemple #9
0
Fichier : fs.cpp Projet : 8l/vdev
// for creating, opening, or stating files, verify that the caller is permitted according to our ACLs 
// return 0 on success 
// return -EPERM if denied 
// return other -errno on error 
static int vdevfs_access_check( struct vdevfs* vdev, struct fskit_fuse_state* fs_state, char const* method_name, char const* path ) {
   
   int rc = 0;
   pid_t pid = 0;
   uid_t uid = 0;
   gid_t gid = 0;
   struct stat sb;
   struct pstat ps;
   
   memset( &sb, 0, sizeof(struct stat) );
   sb.st_mode = 0777;
   
   memset( &ps, 0, sizeof(struct pstat) );
   
   // stat the calling process
   pid = fskit_fuse_get_pid();
   uid = fskit_fuse_get_uid( fs_state );
   gid = fskit_fuse_get_gid( fs_state );
   
   vdev_debug("%s('%s') from user %d group %d task %d\n", method_name, path, uid, gid, pid );
   
   // see who's asking 
   rc = pstat( pid, &ps, 0 );
   if( rc != 0 ) {
      
      vdev_error("pstat(%d) rc = %d\n", pid, rc );
      return -EIO;
   }
   
   // apply the ACLs on the stat buffer
   rc = vdev_acl_apply_all( vdev->config, vdev->acls, vdev->num_acls, path, &ps, uid, gid, &sb );
   if( rc < 0 ) {
      
      vdev_error("vdev_acl_apply_all(%s, uid=%d, gid=%d, pid=%d) rc = %d\n", path, uid, gid, pid, rc );
      return -EIO;
   }
   
   // omit entirely?
   if( rc == 0 || (sb.st_mode & 0777) == 0 ) {
      
      // filter
      vdev_debug("DENY '%s'\n", path );
      return -EPERM;
   }
   else {
      
      // accept!
      return 0;
   }
}
Exemple #10
0
/*
 * Call this to update the ps status display to a fixed prefix plus an
 * indication of what you're currently doing passed in the argument.
 */
void
set_ps_display(const char *activity)
{
#ifndef PS_USE_NONE
	/* no ps display for stand-alone backend */
	if (!IsUnderPostmaster)
		return;

#ifdef PS_USE_CLOBBER_ARGV
	/* If ps_buffer is a pointer, it might still be null */
	if (!ps_buffer)
		return;
#endif

	/* Update ps_buffer to contain both fixed part and activity */
	StrNCpy(ps_buffer + ps_buffer_fixed_size, activity,
			ps_buffer_size - ps_buffer_fixed_size);

	/* Transmit new setting to kernel, if necessary */

#ifdef PS_USE_SETPROCTITLE
	setproctitle("%s", ps_buffer);
#endif

#ifdef PS_USE_PSTAT
	{
		union pstun pst;

		pst.pst_command = ps_buffer;
		pstat(PSTAT_SETCMD, pst, strlen(ps_buffer), 0, 0);
	}
#endif   /* PS_USE_PSTAT */

#ifdef PS_USE_PS_STRINGS
	PS_STRINGS->ps_nargvstr = 1;
	PS_STRINGS->ps_argvstr = ps_buffer;
#endif   /* PS_USE_PS_STRINGS */

#ifdef PS_USE_CLOBBER_ARGV
	{
		int			buflen;

		/* pad unused memory */
		buflen = strlen(ps_buffer);
		MemSet(ps_buffer + buflen, PS_PADDING, ps_buffer_size - buflen);
	}
#endif   /* PS_USE_CLOBBER_ARGV */
#endif   /* not PS_USE_NONE */
}
Exemple #11
0
/*
 * Call this to update the ps status display to a fixed prefix plus an
 * indication of what you're currently doing passed in the argument.
 */
void
set_ps_display(const char *activity)
{
#ifndef PS_USE_NONE
#ifdef PS_USE_CLOBBER_ARGV
	/* If ps_buffer is a pointer, it might still be null */
	if (!ps_buffer)
		return;
#endif

	/* Update ps_buffer to contain both fixed part and activity */
	strncpy(ps_buffer + ps_buffer_fixed_size, activity,
			ps_buffer_size - ps_buffer_fixed_size);
	ps_buffer_cur_len = strlen(ps_buffer);

	/* Transmit new setting to kernel, if necessary */

#ifdef PS_USE_SETPROCTITLE
	setproctitle("%s", ps_buffer);
#endif

#ifdef PS_USE_PSTAT
	{
		union pstun pst;

		pst.pst_command = ps_buffer;
		pstat(PSTAT_SETCMD, pst, ps_buffer_cur_len, 0, 0);
	}
#endif   /* PS_USE_PSTAT */

#ifdef PS_USE_PS_STRINGS
	PS_STRINGS->ps_nargvstr = 1;
	PS_STRINGS->ps_argvstr = ps_buffer;
#endif   /* PS_USE_PS_STRINGS */

#ifdef PS_USE_CLOBBER_ARGV
	/* pad unused memory; need only clobber remainder of old status string */
	if (last_status_len > ps_buffer_cur_len)
		memset(ps_buffer + ps_buffer_cur_len, PS_PADDING,
			   last_status_len - ps_buffer_cur_len);
	last_status_len = ps_buffer_cur_len;
#endif   /* PS_USE_CLOBBER_ARGV */

#endif   /* not PS_USE_NONE */
}
Exemple #12
0
// set up a pidfile inode 
int runfs_inode_init( struct runfs_inode* inode, pid_t pid, int verify_discipline ) {
   
   int rc = 0;
   int flags = 0;
   
   if( verify_discipline & RUNFS_VERIFY_HASH ) {
      flags |= PSTAT_HASH;
   }
   
   rc = pstat( pid, &inode->ps, flags );
   if( rc != 0 ) {
      return rc;
   }
   
   inode->verify_discipline = verify_discipline;
   
   return 0;
}
Exemple #13
0
void
setproctitle(const char *fmt, ...)
{
#if SPT_TYPE != SPT_NONE
	va_list ap;
	char buf[1024];
	size_t len;
	int r;
	extern char *__progname;
#if SPT_TYPE == SPT_PSTAT
	union pstun pst;
#endif

#if SPT_TYPE == SPT_REUSEARGV
	if (argv_env_len <= 0)
		return;
#endif

	strlcpy(buf, __progname, sizeof(buf));

	r = -1;
	va_start(ap, fmt);
	if (fmt != NULL) {
		len = strlcat(buf, ": ", sizeof(buf));
		if (len < sizeof(buf))
			r = vsnprintf(buf + len, sizeof(buf) - len , fmt, ap);
	}
	va_end(ap);
	if (r == -1 || (size_t)r >= sizeof(buf) - len)
		return;

#if SPT_TYPE == SPT_PSTAT
	pst.pst_command = buf;
	pstat(PSTAT_SETCMD, pst, strlen(buf), 0, 0);
#elif SPT_TYPE == SPT_REUSEARGV
/*	debug("setproctitle: copy \"%s\" into len %d",
	    buf, argv_env_len); */
	len = strlcpy(argv_start, buf, argv_env_len);
	for(; len < argv_env_len; len++)
		argv_start[len] = SPT_PADCHAR;
#endif

#endif /* SPT_NONE */
}
Exemple #14
0
void
setproctitle(const char *fmt, ...)
{
#if SPT_TYPE != SPT_NONE
	va_list ap;
	char buf[1024], ptitle[1024];
	size_t len;
	extern char *__progname;
#if SPT_TYPE == SPT_PSTAT
	union pstun pst;
#endif

#if SPT_TYPE == SPT_REUSEARGV
	if (argv_env_len <= 0)
		return;
#endif

	strlcpy(buf, __progname, sizeof(buf));

	va_start(ap, fmt);
	if (fmt != NULL) {
		len = strlcat(buf, ": ", sizeof(buf));
		if (len < sizeof(buf))
			vsnprintf(buf + len, sizeof(buf) - len , fmt, ap);
	}
	va_end(ap);
	strnvis(ptitle, buf, sizeof(ptitle),
	    VIS_CSTYLE|VIS_NL|VIS_TAB|VIS_OCTAL);

#if SPT_TYPE == SPT_PSTAT
	pst.pst_command = ptitle;
	pstat(PSTAT_SETCMD, pst, strlen(ptitle), 0, 0);
#elif SPT_TYPE == SPT_REUSEARGV
/*	debug("setproctitle: copy \"%s\" into len %d", 
	    buf, argv_env_len); */
	len = strlcpy(argv_start, ptitle, argv_env_len);
	for(; len < argv_env_len; len++)
		argv_start[len] = SPT_PADCHAR;
#endif

#endif /* SPT_NONE */
}
Exemple #15
0
int sigar_os_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
                           sigar_proc_args_t *procargs)
{
    char *args, *arg;
#ifdef PSTAT_GETCOMMANDLINE
    char buf[1024]; /* kernel limit */

# ifdef pstat_getcommandline /* 11i v2 + */
    if (pstat_getcommandline(buf, sizeof(buf), sizeof(buf[0]), pid) == -1) {
        return errno;
    }
# else
    union pstun pu;

    pu.pst_command = buf;
    if (pstat(PSTAT_GETCOMMANDLINE, pu, sizeof(buf), sizeof(buf[0]), pid) == -1) {
        return errno;
    }
# endif /* pstat_getcommandline */

    args = buf;
#else
    struct pst_status status;

    if (pstat_getproc(&status, sizeof(status), 0, pid) == -1) {
        return errno;
    }

    args = status.pst_cmd;
#endif

    while (*args && (arg = sigar_getword(&args, ' '))) {
        SIGAR_PROC_ARGS_GROW(procargs);
        procargs->data[procargs->number++] = arg;
    }
    
    return SIGAR_OK;
}
Exemple #16
0
int
getloadavg (double loadavg[], int nelem)
{
  int elem = 0;			/* Return value.  */

#ifdef NO_GET_LOAD_AVG
#define LDAV_DONE
  /* Set errno to zero to indicate that there was no particular error;
     this function just can't work at all on this system.  */
  errno = 0;
  elem = -2;
#endif /* NO_GET_LOAD_AVG */

#if ! defined (LDAV_DONE) && defined (HAVE_KSTAT_H) && defined (HAVE_LIBKSTAT)
#define LDAV_DONE
/* getloadavg is best implemented using kstat (kernel stats), on
   systems (like SunOS5) that support it, since you don't need special
   privileges to use it.

   Initial implementation courtesy Zlatko Calusic <*****@*****.**>.
   Integrated to XEmacs by Hrvoje Niksic <*****@*****.**>.
   Additional cleanup by Hrvoje Niksic, based on code published by
   Casper Dik <*****@*****.**>.  */
  kstat_ctl_t *kc;
  kstat_t *ksp;
  static char *avestrings[] = { "avenrun_1min",
				"avenrun_5min",
				"avenrun_15min" };

  if (nelem > countof (avestrings))
    nelem = countof (avestrings);

  kc = kstat_open ();
  if (!kc)
    return -1;
  ksp = kstat_lookup (kc, "unix", 0, "system_misc");
  if (!ksp)
    {
      kstat_close (kc);
      return -1;
    }
  if (kstat_read (kc, ksp, 0) < 0)
    {
      kstat_close (kc);
      return -1;
    }
  for (elem = 0; elem < nelem; elem++)
    {
      kstat_named_t *kn =
	(kstat_named_t *) kstat_data_lookup (ksp, avestrings[elem]);
      if (!kn)
	{
	  kstat_close (kc);
	  return -1;
	}
      loadavg[elem] = (double)kn->value.ul / FSCALE;
    }
  kstat_close (kc);
#endif /* HAVE_KSTAT_H && HAVE_LIBKSTAT */

#if !defined (LDAV_DONE) && defined (HAVE_SYS_PSTAT_H)
#define LDAV_DONE
  /* This is totally undocumented, and is not guaranteed to work, but
     mayhap it might ....  If it does work, it will work only on HP-UX
     8.0 or later.  -- Darryl Okahata <*****@*****.**> */
#undef LOAD_AVE_TYPE		/* Make sure these don't exist. */
#undef LOAD_AVE_CVT
#undef LDAV_SYMBOL
  struct pst_dynamic	procinfo;
  union pstun		statbuf;

  statbuf.pst_dynamic = &procinfo;
  if (pstat (PSTAT_DYNAMIC, statbuf, sizeof (struct pst_dynamic), 0, 0) == -1)
    return (-1);
  loadavg[elem++] = procinfo.psd_avg_1_min;
  loadavg[elem++] = procinfo.psd_avg_5_min;
  loadavg[elem++] = procinfo.psd_avg_15_min;
#endif	/* HPUX */

#if !defined (LDAV_DONE) && defined (__linux__)
#define LDAV_DONE
#undef LOAD_AVE_TYPE

#ifndef LINUX_LDAV_FILE
#define LINUX_LDAV_FILE "/proc/loadavg"
#endif

  char ldavgbuf[40];
  double load_ave[3];
  int fd, count;

  fd = open (LINUX_LDAV_FILE, O_RDONLY);
  if (fd == -1)
    return -1;
  count = read (fd, ldavgbuf, 40);
  (void) close (fd);
  if (count <= 0)
    return -1;

  count = sscanf (ldavgbuf, "%lf %lf %lf",
		  &load_ave[0], &load_ave[1], &load_ave[2]);
  if (count < 1)
    return -1;

  for (elem = 0; elem < nelem && elem < count; elem++)
    loadavg[elem] = load_ave[elem];
#endif /* __linux__ */

#if !defined (LDAV_DONE) && defined (__NetBSD__) || defined (__OpenBSD__)
#define LDAV_DONE
#undef LOAD_AVE_TYPE

#ifndef NETBSD_LDAV_FILE
#define NETBSD_LDAV_FILE "/kern/loadavg"
#endif

  unsigned long int load_ave[3], scale;
  int count;
  FILE *fp;

  fp = fopen (NETBSD_LDAV_FILE, "r");
  if (fp == NULL)
    return -1;
  count = fscanf (fp, "%lu %lu %lu %lu\n",
		  &load_ave[0], &load_ave[1], &load_ave[2],
		  &scale);
  (void) fclose (fp);
  if (count != 4)
    return -1;

  for (elem = 0; elem < nelem; elem++)
    loadavg[elem] = (double) load_ave[elem] / (double) scale;
#endif /* __NetBSD__ or __OpenBSD__ */

#if !defined (LDAV_DONE) && defined (NeXT)
#define LDAV_DONE
  /* The NeXT code was adapted from iscreen 3.2.  */

  host_t host;
  struct processor_set_basic_info info;
  unsigned info_count;

  /* We only know how to get the 1-minute average for this system,
     so even if the caller asks for more than 1, we only return 1.  */

  if (!getloadavg_initialized)
    {
      if (processor_set_default (host_self (), &default_set) == KERN_SUCCESS)
	getloadavg_initialized = 1;
    }

  if (getloadavg_initialized)
    {
      info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
      if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host,
			     (processor_set_info_t) &info, &info_count)
	  != KERN_SUCCESS)
	getloadavg_initialized = 0;
      else
	{
	  if (nelem > 0)
	    loadavg[elem++] = (double) info.load_average / LOAD_SCALE;
	}
    }

  if (!getloadavg_initialized)
    return -1;
#endif /* NeXT */

#if !defined (LDAV_DONE) && defined (UMAX)
#define LDAV_DONE
/* UMAX 4.2, which runs on the Encore Multimax multiprocessor, does not
   have a /dev/kmem.  Information about the workings of the running kernel
   can be gathered with inq_stats system calls.
   We only know how to get the 1-minute average for this system.  */

  struct proc_summary proc_sum_data;
  struct stat_descr proc_info;
  double load;
  REGISTER unsigned int i, j;

  if (cpus == 0)
    {
      REGISTER unsigned int c, i;
      struct cpu_config conf;
      struct stat_descr desc;

      desc.sd_next = 0;
      desc.sd_subsys = SUBSYS_CPU;
      desc.sd_type = CPUTYPE_CONFIG;
      desc.sd_addr = (char *) &conf;
      desc.sd_size = sizeof conf;

      if (inq_stats (1, &desc))
	return -1;

      c = 0;
      for (i = 0; i < conf.config_maxclass; ++i)
	{
	  struct class_stats stats;
	  memset ((char *) &stats, 0, sizeof stats);

	  desc.sd_type = CPUTYPE_CLASS;
	  desc.sd_objid = i;
	  desc.sd_addr = (char *) &stats;
	  desc.sd_size = sizeof stats;

	  if (inq_stats (1, &desc))
	    return -1;

	  c += stats.class_numcpus;
	}
      cpus = c;
      samples = cpus < 2 ? 3 : (2 * cpus / 3);
    }

  proc_info.sd_next = 0;
  proc_info.sd_subsys = SUBSYS_PROC;
  proc_info.sd_type = PROCTYPE_SUMMARY;
  proc_info.sd_addr = (char *) &proc_sum_data;
  proc_info.sd_size = sizeof (struct proc_summary);
  proc_info.sd_sizeused = 0;

  if (inq_stats (1, &proc_info) != 0)
    return -1;

  load = proc_sum_data.ps_nrunnable;
  j = 0;
  for (i = samples - 1; i > 0; --i)
    {
      load += proc_sum_data.ps_nrun[j];
      if (j++ == PS_NRUNSIZE)
	j = 0;
    }

  if (nelem > 0)
    loadavg[elem++] = load / samples / cpus;
#endif /* UMAX */

#if !defined (LDAV_DONE) && defined (DGUX)
#define LDAV_DONE
  /* This call can return -1 for an error, but with good args
     it's not supposed to fail.  The first argument is for no
     apparent reason of type `long int *'.  */
  dg_sys_info ((long int *) &load_info,
	       DG_SYS_INFO_LOAD_INFO_TYPE,
	       DG_SYS_INFO_LOAD_VERSION_0);

  if (nelem > 0)
    loadavg[elem++] = load_info.one_minute;
  if (nelem > 1)
    loadavg[elem++] = load_info.five_minute;
  if (nelem > 2)
    loadavg[elem++] = load_info.fifteen_minute;
#endif /* DGUX */

#if !defined (LDAV_DONE) && defined (OSF_MIPS)
#define LDAV_DONE

  struct tbl_loadavg load_ave;
  table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave));
  loadavg[elem++]
    = (load_ave.tl_lscale == 0
       ? load_ave.tl_avenrun.d[0]
       : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale));
#endif	/* OSF_MIPS */

#if !defined (LDAV_DONE) && (defined (WIN32_NATIVE) || defined (CYGWIN))
#define LDAV_DONE

  /* A faithful emulation is going to have to be saved for a rainy day.  */
  for ( ; elem < nelem; elem++)
    {
      loadavg[elem] = 0.0;
    }
#endif  /* WIN32_NATIVE or CYGWIN */

#if !defined (LDAV_DONE) && defined (OSF_ALPHA)
#define LDAV_DONE

  struct tbl_loadavg load_ave;
  table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave));
  for (elem = 0; elem < nelem; elem++)
    loadavg[elem]
      = (load_ave.tl_lscale == 0
       ? load_ave.tl_avenrun.d[elem]
       : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale));
#endif /* OSF_ALPHA */

#if !defined (LDAV_DONE) && defined(LOAD_AVE_TYPE)

  /* UNIX-specific code -- read the average from /dev/kmem.  */

#define LDAV_PRIVILEGED		/* This code requires special installation.  */

  LOAD_AVE_TYPE load_ave[3];

  /* Get the address of LDAV_SYMBOL.  */
  if (offset == 0)
    {
#ifndef sgi
#ifndef NLIST_STRUCT
      strcpy (nl[0].n_name, LDAV_SYMBOL);
      strcpy (nl[1].n_name, "");
#else /* NLIST_STRUCT */
#ifdef NLIST_NAME_UNION
      nl[0].n_un.n_name = LDAV_SYMBOL;
      nl[1].n_un.n_name = 0;
#else /* not NLIST_NAME_UNION */
      nl[0].n_name = (char *) LDAV_SYMBOL;
      nl[1].n_name = 0;
#endif /* not NLIST_NAME_UNION */
#endif /* NLIST_STRUCT */

#ifndef SUNOS_5
      if (
#if !(defined (_AIX) && !defined (ps2))
	  nlist (KERNEL_FILE, nl)
#else  /* _AIX */
	  knlist (nl, 1, sizeof (nl[0]))
#endif
	  >= 0)
	  /* Omit "&& nl[0].n_type != 0 " -- it breaks on Sun386i.  */
	  {
#ifdef FIXUP_KERNEL_SYMBOL_ADDR
	    FIXUP_KERNEL_SYMBOL_ADDR (nl);
#endif
	    offset = nl[0].n_value;
	  }
#endif /* !SUNOS_5 */
#else  /* sgi */
	  int ldav_off;

	  ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN);
	  if (ldav_off != -1)
	  offset = (long) ldav_off & 0x7fffffff;
#endif /* sgi */
	}

  /* Make sure we have /dev/kmem open.  */
  if (!getloadavg_initialized)
    {
#ifndef SUNOS_5
      channel = open ("/dev/kmem", 0);
      if (channel >= 0)
	{
	  /* Set the channel to close on exec, so it does not
	     litter any child's descriptor table.  */
#ifdef FD_SETFD
#ifndef FD_CLOEXEC
#define FD_CLOEXEC 1
#endif
	  (void) fcntl (channel, F_SETFD, FD_CLOEXEC);
#endif
	  getloadavg_initialized = 1;
	}
#else /* SUNOS_5 */
      /* We pass 0 for the kernel, corefile, and swapfile names
	 to use the currently running kernel.  */
      kd = kvm_open (0, 0, 0, O_RDONLY, 0);
      if (kd != 0)
	{
	  /* nlist the currently running kernel.  */
	  kvm_nlist (kd, nl);
	  offset = nl[0].n_value;
	  getloadavg_initialized = 1;
	}
#endif /* SUNOS_5 */
    }

  /* If we can, get the load average values.  */
  if (offset && getloadavg_initialized)
    {
      /* Try to read the load.  */
#ifndef SUNOS_5
      if (lseek (channel, offset, 0) == -1L
	  || read (channel, (char *) load_ave, sizeof (load_ave))
	  != sizeof (load_ave))
	{
	  close (channel);
	  getloadavg_initialized = 0;
	}
#else  /* SUNOS_5 */
      if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave))
	  != sizeof (load_ave))
        {
          kvm_close (kd);
          getloadavg_initialized = 0;
	}
#endif /* SUNOS_5 */
    }

  if (offset == 0 || !getloadavg_initialized)
    return -1;

  if (nelem > 0)
    loadavg[elem++] = LDAV_CVT (load_ave[0]);
  if (nelem > 1)
    loadavg[elem++] = LDAV_CVT (load_ave[1]);
  if (nelem > 2)
    loadavg[elem++] = LDAV_CVT (load_ave[2]);

#define LDAV_DONE
#endif /* !LDAV_DONE && LOAD_AVE_TYPE */

  return elem;
}
Exemple #17
0
void parasol(char *command, int argc, char *argv[])
/* parasol - Parasol program - for launching programs in parallel on a computer cluster. */
{
char *subType = argv[0];

hubRudp = rudpMustOpen();
if (sameString(command, "add"))
    {
    if (argc < 1)
        usage();
    if (sameString(subType, "machine"))
	{
	if (argc != 3 && argc != 8)
	    usage();
	addMachine(argc, argv);
	}
    else if (sameString(subType, "job"))
	{
	if (argc < 2)
	    usage();
        addJob(argc-1, argv+1, optionExists("verbose"));
	}
    else if (sameString(subType, "spoke"))
        addSpoke();
    else
        usage();
    }
else if (sameString(command, "clear"))
    {
    if (argc != 1)
	usage();
    if (sameString(subType, "sick"))
	{
        clearSickBatch();
	}
    else
        usage();
    }
else if (sameString(command, "check"))
    {
    if (argc != 1)
	usage();
    if (sameString(subType, "dead"))
	{
        checkDeadNodesASAP();
	}
    else
        usage();
    }
else if (sameString(command, "remove"))
    {
    if (argc < 2)
        usage();
    if (sameString(subType, "machine"))
	{
	if (argc < 3)
	    usage();
        removeMachine(argv[1],argv[2]);
	}
    else if (sameString(subType, "job"))
        removeJob(argv[1]);
    else if (sameString(subType, "jobs"))
        removeUserJobs(argv[1], argc-2, argv+2);
    else
        usage();
    }
else if (sameString(command, "list"))
    {
    if (argc != 1)
        usage();
    if (sameString(subType, "machine") || sameString(subType, "machines"))
        hubCommandAndPrint("listMachines");
    else if (sameString(subType, "job") || sameString(subType, "jobs"))
	{
        if (optionExists("extended"))
	    hubCommandAndPrint("listJobsExtended");
        else
	    hubCommandAndPrint("listJobs");
	}
    else if (sameString(subType, "user") || sameString(subType, "users"))
        hubCommandAndPrint("listUsers");
    else if (sameString(subType, "batch") || sameString(subType, "batches"))
        hubCommandAndPrint("listBatches");
    else if (sameString(subType, "sick"))
        hubCommandAndPrint("listSick");
    else
        usage();
    }
else if (sameString(command, "pstat"))
    {
    pstat();
    }
else if (sameString(command, "pstat2"))
    {
    pstat2();
    }
else if (sameString(command, "plan"))
    {
    hubCommandAndPrint("plan");
    }
else if (sameString(command, "ping"))
    {
    int count = 1;
    if (argc >= 1)
        {
	if (!isdigit(argv[0][0]))
	    usage();
	count = atoi(argv[0]);
	}
    ping(count);
    }
else if (sameString(command, "status"))
    status();
else if (sameString(command, "flushResults"))
    {
    if (argc != 0)
        usage();
    flushResults();
    }
/* Not providing at this time for fear of abuse 
else if (sameString(command, "freeBatch"))
    {
    if (argc != 0)
        usage();
    freeBatch();
    }
*/
else
    usage();
}
Exemple #18
0
void print_results(int fflag)
	{
	long QTP, QFN, QFP, STP, SFN, SFP, VTP, VFN, VTN, VFP;

    /* Open output files.  If line-format output was selected, write column
       headings only if the files must be created from scratch. */
	if (strcmp(ofname, "-"))
		{
		if ((ofile = fopen(ofname, "r")) == NULL)
			{
			if ((ofile = fopen(ofname, "w")) == NULL)
				{
				(void)fprintf(stderr, "%s: can't create %s\n", pname, ofname);
				exit(0);
				}
			if (fflag == 2)
				{
				(void)fprintf(ofile,
			      "Record Nn' Vn' Fn' On'  Nv   Vv  Fv' Ov' No'");
				(void)fprintf(ofile,
			      " Vo' Fo'  Q Se   Q +P   V Se   V +P  V FPR\n");
				}
			else if (fflag == 5)
				{
				(void)fprintf(ofile,
			      "Record Nn' Sn' Vn' Fn' On'  Ns  Ss  Vs  Fs'");
				(void)fprintf(ofile,
			      " Os' Nv  Sv   Vv  Fv' Ov' No' So' Vo' Fo'");
				(void)fprintf(ofile,
					"  Q Se   Q +P   V Se   V +P   S Se   S +P RR err\n");
				}
			}
		else
			{
			(void)fclose(ofile);
			if ((ofile = fopen(ofname, "a")) == NULL)
				{
				(void)fprintf(stderr, "%s: can't modify %s\n", pname, ofname);
				exit(0);
				}
			}
		}
	else ofile = stdout;
	if (fflag == 2 || fflag == 5)
		{
		if (strcmp(sfname, "-"))
			{
			if ((sfile = fopen(sfname, "r")) == NULL)
				{
				if ((sfile = fopen(sfname, "w")) == NULL)
					{
					(void)fprintf(stderr,
						"%s: can't create %s\n", pname, sfname);
					exit(0);
					}
				if (fflag == 2) {
		    (void)fprintf(sfile,
			    "Record Nx   Vx   Fx   Qx  %% beats  %% N    ");
		    (void)fprintf(sfile, "%% V    %% F   Total Shutdown\n");
		    (void)fprintf(sfile,
			    "                           missed missed ");
		    (void)fprintf(sfile, "missed missed      Time\n");
		}
		else {
		    (void)fprintf(sfile,
			  "Record Nx   Sx   Vx   Fx   Qx  %% beats  %% N    ");
		    (void)fprintf(sfile,
				  "%% S    %% V    %% F   Total Shutdown\n");
		    (void)fprintf(sfile,
			    "                                missed missed ");
		    (void)fprintf(sfile, "missed missed missed      Time\n");
		}
	    }
	    else {
		(void)fclose(sfile);
		if ((sfile = fopen(sfname, "a")) == NULL) {
		    (void)fprintf(stderr,
				  "%s: can't modify %s\n", pname, sfname);
		    exit(0);
		}
	    }
	}
	else sfile = stdout;
    }
    else sfile = stdout;

    if (fflag == 1 || fflag == 3 || fflag == 4 || fflag == 6) {
	(void)fprintf(ofile, "Beat-by-beat comparison results for record %s\n",
		      record);
	(void)fprintf(ofile, "Reference annotator: %s\n", an[0].name);
	(void)fprintf(ofile, "     Test annotator: %s\n\n", an[1].name);
    }

    switch (fflag) {
      case 1:	/* print condensed format summary tables */
	(void)fprintf(ofile, "         Algorithm\n");
	(void)fprintf(ofile, "      n+f+q    v  o+x\n");
	(void)fprintf(ofile, "     ________________\n");
	(void)fprintf(ofile, "  N  | %4ld %4ld %4ld\n",
		      Nn+Ns+Nf+Nq + Sn+Ss+Sf+Sq, Nv + Sv, No+Nx + So+Sx);
	(void)fprintf(ofile, "  V  | %4ld %4ld %4ld\n",
		      Vn+Vs+Vf+Vq, Vv, Vo+Vx);
	(void)fprintf(ofile, " F+Q | %4ld %4ld %4ld\n",
		      Fn+Fs+Ff+Fq + Qn+Qs+Qf+Qq, Fv + Qv, Fo+Fx + Qo+Qx);
	(void)fprintf(ofile, " O+X | %4ld %4ld\n\n",
		      On+Os+Of+Oq + Xn+Xs+Xf+Xq, Ov+Xv);
	break;
      case 2:	/* print line-format output */
	(void)fprintf(ofile,
	      "%4s %5ld %3ld %3ld %3ld %3ld %4ld %3ld %3ld %3ld %3ld %3ld",
		      record,
		      Nn+Ns+Nf+Nq + Sn+Ss+Sf+Sq,
		      Vn+Vs+Vf+Vq,
		      Fn+Fs+Ff+Fq + Qn+Qs+Qf+Qq,
		      On+Os+Of+Oq + Xn+Xs+Xf+Xq,
		      Nv+Sv, Vv, Fv+Qv, Ov+Xv,
		      No+Nx+So+Sx, Vo+Vx, Fo+Fx+Qo+Qx);
	(void)fprintf(sfile, "%4s %4ld %4ld %4ld %4ld  ",
		      record, Nx+Sx, Vx, Fx, Qx);
	break;
      case 3:	/* print standard format summary tables */
	(void)fprintf(ofile, "               Algorithm\n");
	(void)fprintf(ofile, "        n    v    f    q    o    x\n");
	(void)fprintf(ofile, "   _______________________________\n");
	(void)fprintf(ofile, " N | %4ld %4ld %4ld %4ld %4ld %4ld\n",
		      Nn+Ns+Sn+Ss, Nv+Sv, Nf+Sf, Nq+Sq, No+So, Nx+Sx);
	(void)fprintf(ofile, " V | %4ld %4ld %4ld %4ld %4ld %4ld\n",
		      Vn+Vs, Vv, Vf, Vq, Vo, Vx);
	(void)fprintf(ofile, " F | %4ld %4ld %4ld %4ld %4ld %4ld\n",
		      Fn+Fs, Fv, Ff, Fq, Fo, Fx);
	(void)fprintf(ofile, " Q | %4ld %4ld %4ld %4ld %4ld %4ld\n",
		      Qn+Qs, Qv, Qf, Qq, Qo, Qx);
	(void)fprintf(ofile, " O | %4ld %4ld %4ld %4ld\n",
		      On+Os, Ov, Of, Oq);
	(void)fprintf(ofile, " X | %4ld %4ld %4ld %4ld\n\n",
		      Xn+Xs, Xv, Xf, Xq);
	break;
      case 4:	/* print condensed format summary tables, with SVEBs */
	(void)fprintf(ofile, "         Algorithm\n");
	(void)fprintf(ofile, "      n+f+q    s    v  o+x\n");
	(void)fprintf(ofile, "     _____________________\n");
	(void)fprintf(ofile, "  N  | %4ld %4ld %4ld %4ld\n",
		      Nn+Nf+Nq, Ns, Nv, No+Nx);
	(void)fprintf(ofile, "  S  | %4ld %4ld %4ld %4ld\n",
		      Sn+Sf+Sq, Ss, Sv, So+Sx);
	(void)fprintf(ofile, "  V  | %4ld %4ld %4ld %4ld\n",
		      Vn+Vf+Vq, Vs, Vv, Vo+Vx);
	(void)fprintf(ofile, " F+Q | %4ld %4ld %4ld %4ld\n",
		      Fn+Ff+Fq+Qn+Qf+Qq, Fs+Qs, Fv+Qv, Fo+Fx+Qo+Qx);
	(void)fprintf(ofile, " O+X | %4ld %4ld %4ld\n\n",
		      On+Of+Oq+Xn+Xf+Xq, Os+Xs, Ov+Xv);
	break;
      case 5:	/* print line-format output, with SVEBs */
	(void)fprintf(ofile,
		      "%4s %5ld %3ld %3ld %3ld %3ld %3ld %3ld %3ld %3ld %3ld",
		      record,
		      Nn+Nf+Nq,
		      Sn+Sf+Sq,
		      Vn+Vf+Vq,
		      Fn+Ff+Fq + Qn+Qf+Qq,
		      On+Of+Oq + Xn+Xf+Xq,
		      Ns, Ss, Vs, Fs+Qs, Os+Xs);
	(void)fprintf(ofile,
		      " %3ld %3ld %4ld %3ld %3ld %3ld %3ld %3ld %3ld",
		      Nv, Sv, Vv, Fv+Qv, Ov+Xv,
		      No+Nx, So+Sx, Vo+Vx, Fo+Fx+Qo+Qx);
	(void)fprintf(sfile,
		      "%4s %4ld %4ld %4ld %4ld %4ld  ",
		      record, Nx, Sx, Vx, Fx, Qx);
	break;
      case 6:	/* print standard format summary tables, with SVEBs */
      default:
	(void)fprintf(ofile, "               Algorithm\n");
	(void)fprintf(ofile, "        n    s    v    f    q    o    x\n");
	(void)fprintf(ofile, "   ____________________________________\n");
	(void)fprintf(ofile, " N | %4ld %4ld %4ld %4ld %4ld %4ld %4ld\n",
		      Nn, Ns, Nv, Nf, Nq, No, Nx);
	(void)fprintf(ofile, " S | %4ld %4ld %4ld %4ld %4ld %4ld %4ld\n",
		      Sn, Ss, Sv, Sf, Sq, So, Sx);
	(void)fprintf(ofile, " V | %4ld %4ld %4ld %4ld %4ld %4ld %4ld\n",
		      Vn, Vs, Vv, Vf, Vq, Vo, Vx);
	(void)fprintf(ofile, " F | %4ld %4ld %4ld %4ld %4ld %4ld %4ld\n",
		      Fn, Fs, Fv, Ff, Fq, Fo, Fx);
	(void)fprintf(ofile, " Q | %4ld %4ld %4ld %4ld %4ld %4ld %4ld\n",
		      Qn, Qs, Qv, Qf, Qq, Qo, Qx);
	(void)fprintf(ofile, " O | %4ld %4ld %4ld %4ld %4ld\n",
		      On, Os, Ov, Of, Oq);
	(void)fprintf(ofile, " X | %4ld %4ld %4ld %4ld %4ld\n\n",
		      Xn, Xs, Xv, Xf, Xq);
	break;
    }
	 QTP = Nn+Ns+Nv+Nf+Nq + Sn+Ss+Sv+Sf+Sq + Vn+Vs+Vv+Vf+Vq + Fn+Fs+Fv+Ff+Fq +
	Qn+Qs+Qv+Qf+Qq;
	 QFN = No+Nx + So+Sx + Vo+Vx + Fo+Fx + Qo+Qx;
	 QFP = On+Os+Ov+Of+Oq + Xn+Xs+Xv+Xf+Xq;
	 VTP = Vv;
	 VFN = Vn + Vs + Vf + Vq + Vo + Vx;
	 VTN = Nn+Ns+Nf+Nq + Sn+Ss+Sf+Sq + Fn+Fs+Ff+Fq + Qn+Qs+Qf+Qq + On+Os+Of+Oq +
	Xn+Xs+Xf+Xq;
	 VFP = Nv + Sv + Ov + Xv;
    STP = Ss;
    SFN = Sn + Sv + Sf + Sq + So + Sx;
    SFP = Ns + Vs + Fs + Os + Xs;
	 pstat("           QRS sensitivity", "%6.2f", QTP, QTP + QFN);
    pstat(" QRS positive predictivity", "%6.2f", QTP, QTP + QFP);
    pstat("           VEB sensitivity", "%6.2f", VTP, VTP + VFN);
    pstat(" VEB positive predictivity", "%6.2f", VTP, VTP + VFP);
    if (fflag < 4)
	pstat("   VEB false positive rate", "%6.3f", VFP, VTN + VFP);
    else {
	pstat("          SVEB sensitivity", "%6.2f", STP, STP + SFN);
	pstat("SVEB positive predictivity", "%6.2f", STP, STP + SFP);
    }
    if (fflag == 4 || fflag == 6) {
	(void)fprintf(ofile, "     RMS RR interval error: ");
	if (nrre)
	    (void)fprintf(ofile, "%6.2f ms",
			  sqrt(ssrre/nrre)*1000./strtim("1"));
	else
	    (void)fprintf(ofile, "     -");
    }
    else if (fflag == 5) {
	if (nrre)
	    (void)fprintf(ofile, " %6.2f", sqrt(ssrre/nrre)*1000./strtim("1"));
	else
	    (void)fprintf(ofile, "     -");
    }
    (void)fprintf(ofile, "\n");
    sstat("\n  Beats missed in shutdown", "%6.2f", Nx+Vx+Fx+Qx, QTP + QFN);
    sstat("      N missed in shutdown", "%6.2f", Nx, Nn+Ns+Nv+Nf+Nq+No+Nx);
    if (fflag >= 4)
	sstat("      S missed in shutdown", "%6.2f", Sx, Sn+Ss+Sv+Sf+Sq+So+Sx);
    sstat("      V missed in shutdown", "%6.2f", Vx, Vn+Vs+Vv+Vf+Vq+Vo+Vx);
    sstat("      F missed in shutdown", "%6.2f", Fx, Fn+Fs+Fv+Ff+Fq+Fo+Fx);
    if (fflag == 1 || fflag == 3 || fflag == 4 || fflag == 6)
	(void)fprintf(sfile, "       Total shutdown time: ");
	 (void)fprintf(sfile, "%5ld seconds\n", shut_down);

	if(ofile != NULL)
		fclose(ofile) ;
	}
Exemple #19
0
int main(void)
{
   int r_bufid = 0, s_bufid = 0;
   cg_prob *p;
   int num_cuts = 0;
   double elapsed;
   struct timeval tout = {15, 0};

   p = (cg_prob *) calloc(1, sizeof(cg_prob));

   cg_initialize(p, 0);

   /*------------------------------------------------------------------------*\
    * The main loop -- executes continuously until the program exits
   \*------------------------------------------------------------------------*/

   while (TRUE){
      /* Wait until a message arrives */
      do{
	 r_bufid = treceive_msg(ANYONE, ANYTHING, &tout);
	 if (!r_bufid){
	    if (pstat(p->tree_manager) != PROCESS_OK){
	       printf("TM has died -- CG exiting\n\n");
	       exit(-401);
	    }
	 }
      }while (!r_bufid);
      if (cg_process_message(p, r_bufid) == USER_ERROR)
	 p->msgtag = USER_ERROR;
      /* If there is still something in the queue, process it */
      do{
	 r_bufid = nreceive_msg(ANYONE, ANYTHING);
	 if (r_bufid > 0)
	    if (cg_process_message(p, r_bufid) == USER_ERROR)
	       p->msgtag = USER_ERROR;
      }while (r_bufid != 0);

      /*---------------------------------------------------------------------
       * Now the message queue is empty. If the last message was NOT some
       * kind of LP_SOLUTION then we can't generate solutions now.
       * Otherwise, generate solutions!
       *---------------------------------------------------------------------*/
      if (p->msgtag == LP_SOLUTION_NONZEROS || p->msgtag == LP_SOLUTION_USER ||
	  p->msgtag == LP_SOLUTION_FRACTIONS){
	 if (p->par.do_findcuts)
	    if ((termcode = find_cuts_u(p, NULL, &num_cuts)) < 0)
	       printf("Warning: User error detected in cut generator\n\n");
	 /*-- send signal back to the LP that the cut generator is done -----*/
	 s_bufid = init_send(DataInPlace);
	 send_int_array(&num_cuts, 1);
	 elapsed = used_time(&p->tt);
	 send_dbl_array(&elapsed, 1);
	 send_int_array(&p->cur_sol.xindex, 1);
	 send_int_array(&p->cur_sol.xiter_num, 1);
	 send_msg(p->cur_sol.lp, NO_MORE_CUTS);
	 freebuf(s_bufid);
	 FREE(p->cur_sol.xind);
	 FREE(p->cur_sol.xval);
      }
   }

   return(0);
}
Exemple #20
0
Fichier : fs.cpp Projet : 8l/vdev
// readdir: equivocate about which devices exist, depending on who's asking
// omit entries if the ACLs forbid them
int vdevfs_readdir( struct fskit_core* core, struct fskit_match_group* grp, struct fskit_entry* fent, struct fskit_dir_entry** dirents, size_t num_dirents ) {
   
   int rc = 0;
   struct fskit_entry* child = NULL;
   
   // entries to omit in the listing
   vector<int> omitted_idx;
   
   pid_t pid = 0;
   uid_t uid = 0;
   gid_t gid = 0;
   
   struct vdevfs* vdev = (struct vdevfs*)fskit_core_get_user_data( core );
   struct fskit_fuse_state* fs_state = fskit_fuse_get_state();
   
   struct stat sb;
   struct pstat ps;
   char* child_path = NULL;
   
   pid = fskit_fuse_get_pid();
   uid = fskit_fuse_get_uid( fs_state );
   gid = fskit_fuse_get_gid( fs_state );
   
   vdev_debug("vdevfs_readdir(%s, %zu) from user %d group %d task %d\n", grp->path, num_dirents, uid, gid, pid );
   
   // see who's asking
   rc = pstat( pid, &ps, 0 );
   if( rc != 0 ) { 
      
      vdev_error("pstat(%d) rc = %d\n", pid, rc );
      return -EIO;
   }
   
   for( unsigned int i = 0; i < num_dirents; i++ ) {
      
      // skip . and ..
      if( strcmp(dirents[i]->name, ".") == 0 || strcmp(dirents[i]->name, "..") == 0 ) {
         continue;
      }
      
      // find the associated fskit_entry
      child = fskit_dir_find_by_name( fent, dirents[i]->name );
      
      if( child == NULL ) {
         // strange, shouldn't happen...
         continue;
      }
      
      fskit_entry_rlock( child );
      
      // construct a stat buffer from what we actually need 
      memset( &sb, 0, sizeof(struct stat) );
      
      sb.st_uid = child->owner;
      sb.st_gid = child->group;
      sb.st_mode = fskit_fullmode( child->type, child->mode );
      
      child_path = fskit_fullpath( grp->path, child->name, NULL );
      if( child_path == NULL ) {
         
         // can't continue; OOM
         fskit_entry_unlock( child );
         rc = -ENOMEM;
         break;
      }
      
      // filter it 
      rc = vdev_acl_apply_all( vdev->config, vdev->acls, vdev->num_acls, child_path, &ps, uid, gid, &sb );
      if( rc < 0 ) {
         
         vdev_error("vdev_acl_apply_all('%s', uid=%d, gid=%d, pid=%d) rc = %d\n", child_path, uid, gid, pid, rc );
         rc = -EIO;
      }
      else if( rc == 0 || (sb.st_mode & 0777) == 0 ) {
         
         // omit this one 
         vdev_debug("Filter '%s'\n", child->name );
         omitted_idx.push_back( i );
         
         rc = 0;
      }
      else {
         
         // success; matched
         rc = 0;
      }
      
      fskit_entry_unlock( child );
      
      free( child_path );
      
      // error?
      if( rc != 0 ) {
         break;
      }
   }
   
   // skip ACL'ed entries
   for( unsigned int i = 0; i < omitted_idx.size(); i++ ) {
      
      fskit_readdir_omit( dirents, omitted_idx[i] );
   }
   
   return rc;
}
Exemple #21
0
		/************************ GetRamSize ************************/
	UInt64 GetRamSize() {
			UInt64 ullTotalPhys = 128 * 1024 * 1024; // default : 128MB

#ifdef linux
	 		FILE * f = fopen( "/proc/meminfo", "r" );
	 		if (f)
	 		{
				char buffer[256];
				unsigned long total;

				ullTotalPhys = 0;

		  		while (fgets( buffer, sizeof(buffer), f ))
		  		{
		 		/* old style /proc/meminfo ... */
					if (sscanf( buffer, "Mem: %lu", &total))
					{
					 	ullTotalPhys += total;
					}

					/* new style /proc/meminfo ... */
					if (sscanf(buffer, "MemTotal: %lu", &total))
					 	ullTotalPhys = ((UInt64)total)*1024;
		  		}
		  		fclose( f );
			}
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__APPLE__)
			unsigned int val;
			int mib[2];

			mib[0] = CTL_HW;
			mib[1] = HW_PHYSMEM;
			size_t size_sys = sizeof(val);
			sysctl(mib, 2, &val, &size_sys, NULL, 0);
			if (val) ullTotalPhys = val;
#elif defined(__CYGWIN__)
			unsigned long pagesize=4096; // FIXME - sysconf(_SC_PAGESIZE) returns 65536 !?
					// see http://readlist.com/lists/cygwin.com/cygwin/0/3313.html
			unsigned long maxpages=sysconf(_SC_PHYS_PAGES);
			ullTotalPhys = ((UInt64)pagesize)*maxpages;
#elif defined ( sun ) || defined(__NETWARE__)
			unsigned long pagesize=sysconf(_SC_PAGESIZE);
			unsigned long maxpages=sysconf(_SC_PHYS_PAGES);
			ullTotalPhys = ((UInt64)pagesize)*maxpages;
#elif defined(hpux) || defined(__hpux)
			struct pst_static pst;
			union pstun pu;
						
			pu.pst_static = &pst;
			if ( pstat( PSTAT_STATIC, pu, (size_t)sizeof(pst), (size_t)0, 0 ) != -1 ) {
				ullTotalPhys = ((UInt64)pst.physical_memory)*pst.page_size;
			}
#elif defined(ENV_BEOS)
			system_info info;
			get_system_info(&info);
			ullTotalPhys = info.max_pages;
			ullTotalPhys *= 4096;
#else
#warning Generic GetRamSize
#endif
			return ullTotalPhys;
		}
Exemple #22
0
node_desc *create_explicit_node_desc(lp_prob *p)
{
   LPdata *lp_data = p->lp_data;
   int m = lp_data->m, n = lp_data->n;

   int bvarnum = p->base.varnum;
   var_desc **extravars = lp_data->vars + bvarnum;
   int extravarnum = n - bvarnum;

   int bcutnum = p->base.cutnum;
   row_data *rows = lp_data->rows;
   int extrarownum = m - bcutnum;
   int cutindsize;

   node_desc *desc = (node_desc *) calloc(1, sizeof(node_desc));

   /* Will need these anyway for basis */
   int *rstat = (int *) malloc(m * ISIZE);
   int *cstat = (int *) malloc(n * ISIZE);
   int *erstat = (extrarownum == 0) ? NULL : (int *) malloc(extrarownum*ISIZE);
   int *ecstat = (extravarnum == 0) ? NULL : (int *) malloc(extravarnum*ISIZE);

   int *ulist, *clist; /* this later uses tmp.i1 */
   int cutcnt, i, j;
#ifndef COMPILE_IN_LP
   int s_bufid, r_bufid;
#endif

   get_basis(lp_data, cstat, rstat);
   if (extrarownum > 0)
      memcpy(erstat, rstat + bcutnum, extrarownum * ISIZE);
   if (extravarnum > 0)
      memcpy(ecstat, cstat + bvarnum, extravarnum * ISIZE);

   /* To start with, send the non-indexed cuts (only those which will be
      saved) to the treemanager and ask for names */
   for (cutcnt = cutindsize = 0, i = bcutnum; i < m; i++){
      if ((rows[i].cut->branch & CUT_BRANCHED_ON) ||
	  !rows[i].free || (rows[i].free && rstat[i] != SLACK_BASIC)){
	 cutindsize++;
	 if (rows[i].cut->name < 0)
	    cutcnt++;
      }
   }
   if (cutcnt > 0){
#ifdef COMPILE_IN_LP
      row_data *tmp_rows = (row_data *) malloc(cutcnt*sizeof(row_data));
      
      for (j = 0, i = bcutnum; j < cutcnt; i++){
	 if (rows[i].cut->name < 0 &&
	     (!rows[i].free || (rows[i].free && rstat[i] != SLACK_BASIC)))
	    tmp_rows[j++] = rows[i];
      }
      unpack_cut_set(p->tm, 0, cutcnt, tmp_rows);
      FREE(tmp_rows);
#else
      s_bufid = init_send(DataInPlace);
      send_int_array(&cutcnt, 1);
      for (i = bcutnum; i < m; i++){
	 if (rows[i].cut->name < 0 &&
	     (!rows[i].free || (rows[i].free && rstat[i] != SLACK_BASIC)))
	    pack_cut(rows[i].cut);
      }
      send_msg(p->tree_manager, LP__CUT_NAMES_REQUESTED);
      freebuf(s_bufid);
#endif
   }

   /* create the uind list and the extravars basis description */
   desc->uind.type = EXPLICIT_LIST;
   desc->uind.added = 0;
   desc->uind.size = extravarnum;
   desc->basis.extravars.type = EXPLICIT_LIST;
   desc->basis.extravars.size = extravarnum;
   desc->basis.extravars.list = NULL;
   if (extravarnum > 0){
      desc->uind.list = ulist = (int *) malloc(extravarnum * ISIZE);
      desc->basis.extravars.stat = ecstat;
      for (i = extravarnum - 1; i >= 0; i--)
	 ulist[i] = extravars[i]->userind;
      if (lp_data->ordering == COLIND_ORDERED)
	 qsortucb_ii(ulist, ecstat, extravarnum);
   }else{
      desc->uind.list = NULL;
      desc->basis.extravars.stat = NULL;
   }
   /* create the basevars basis description */
   desc->basis.basevars.type = EXPLICIT_LIST;
   desc->basis.basevars.size = bvarnum;
   desc->basis.basevars.list = NULL;
   if (bvarnum)
      desc->basis.basevars.stat = cstat;
   else
      FREE(cstat);

   /* create the not_fixed list */
   desc->nf_status = lp_data->nf_status;
   if (desc->nf_status == NF_CHECK_AFTER_LAST ||
       desc->nf_status == NF_CHECK_UNTIL_LAST){
      desc->not_fixed.type = EXPLICIT_LIST;
      desc->not_fixed.added = 0;
      if ((desc->not_fixed.size = lp_data->not_fixed_num) > 0){
	 desc->not_fixed.list = (int *) malloc(desc->not_fixed.size * ISIZE);
	 memcpy(desc->not_fixed.list, lp_data->not_fixed,
		lp_data->not_fixed_num * ISIZE);
      }else{
	 desc->not_fixed.list = NULL;
      }
   }

#ifndef COMPILE_IN_LP
   /* At this point we will need the missing names */
   if (cutcnt > 0){
      static struct timeval tout = {15, 0};
      int *names = lp_data->tmp.i1; /* m */
      double start = wall_clock(NULL);
      do{
	 r_bufid = treceive_msg(p->tree_manager, LP__CUT_NAMES_SERVED, &tout);
	 if (! r_bufid){
	    if (pstat(p->tree_manager) != PROCESS_OK){
	       printf("TM has died -- LP exiting\n\n");
	       exit(-301);
	    }
	 }
      }while (! r_bufid);
      p->comp_times.idle_names += wall_clock(NULL) - start;
      receive_int_array(names, cutcnt);
      for (j = 0, i = bcutnum; j < cutcnt; i++){
	 if (rows[i].cut->name < 0 &&
	     (!rows[i].free || (rows[i].free && rstat[i] != SLACK_BASIC)))
	    rows[i].cut->name = names[j++];
      }
   }
#endif

   /* create the cutind list and the extrarows basis description */
   desc->cutind.type = EXPLICIT_LIST;
   desc->cutind.added = 0;
   desc->cutind.size = cutindsize;
   desc->basis.extrarows.type = EXPLICIT_LIST;
   desc->basis.extrarows.list = NULL;
   desc->basis.extrarows.size = cutindsize;
   if (cutindsize > 0){
      desc->cutind.list = clist = (int *) malloc(cutindsize * ISIZE);
      desc->basis.extrarows.stat = erstat;
      for (cutindsize = 0, i = bcutnum; i < m; i++){
	 if ((rows[i].cut->branch & CUT_BRANCHED_ON) ||
	     !rows[i].free || (rows[i].free && rstat[i] != SLACK_BASIC)){
	    clist[cutindsize] = rows[i].cut->name;
	    erstat[cutindsize++] = rstat[i];
	 }
      }
      qsortucb_ii(clist, erstat, cutindsize);
   }else{
      desc->cutind.list = NULL;
      desc->basis.extrarows.stat = NULL;
   }
   /* create the baserows basis description */
   desc->basis.baserows.type = EXPLICIT_LIST;
   desc->basis.baserows.size = bcutnum;
   desc->basis.baserows.list = NULL;
   if (bcutnum)
      desc->basis.baserows.stat = rstat;
   else
      FREE(rstat);

   /* Mark that there is a basis */
   desc->basis.basis_exists = TRUE;

   /* Add user description */
   add_to_desc_u(p, desc);

   return(desc);
}
Exemple #23
0
void
mowgli_proctitle_set(const char *fmt, ...)
{
#ifndef MOWGLI_SETPROC_USE_NONE
	va_list va;

# if defined(MOWGLI_SETPROC_USE_CHANGE_ARGV) || defined(MOWGLI_SETPROC_USE_CLOBBER_ARGV)

	if (!save_argv)
		return;

# endif

	va_start(va, fmt);
	vsnprintf(ps_buffer, ps_buffer_size, fmt, va);
	va_end(va);

	return_if_fail(*ps_buffer == '\0');

	ps_buffer_cur_len = ps_buffer_fixed_size = strlen(ps_buffer);

# ifdef MOWGLI_SETPROC_USE_CHANGE_ARGV
	save_argv[0] = ps_buffer;
	save_argv[1] = NULL;
# endif

# ifdef MOWGLI_SETPROC_USE_CLOBBER_ARGV

	for (int i = 1; i < save_argc; i++)
		save_argv[i] = ps_buffer + ps_buffer_size;

	/* Pad unused bytes */
	memset(ps_buffer + ps_buffer_cur_len, PS_PADDING, ps_buffer_size - ps_buffer_cur_len + 1);
# endif

# ifdef MOWGLI_SETPROC_USE_SETPROCTITLE
	setproctitle("%s", ps_buffer);
# endif

# ifdef MOWGLI_SETPROC_USE_PRCTL

	/* Limit us to 16 chars to be safe */
	char procbuf[16];
	mowgli_strlcpy(procbuf, ps_buffer, sizeof(procbuf));
	prctl(PR_SET_NAME, procbuf, 0, 0, 0);
# endif

# ifdef MOWGLI_SETPROC_USE_PSTAT
	union pstun pst;

	pst.pst_command = ps_buffer;
	pstat(PSTAT_SETCMD, pst, ps_buffer_cur_len, 0, 0);
# endif /* MOWGLI_SETPROC_USE_PSTAT */

# ifdef MOWGLI_SETPROC_USE_PS_STRINGS
	PS_STRINGS->ps_nargvstr = 1;
	PS_STRINGS->ps_argvstr = ps_buffer;
# endif /* MOWGLI_SETPROC_USE_PS_STRINGS */

# ifdef MOWGLI_SETPROC_USE_WIN32

	/*
	 * Win32 does not support showing any changed arguments. To make it at
	 * all possible to track which backend is doing what, we create a
	 * named object that can be viewed with for example Process Explorer.
	 */
	static HANDLE ident_handle = INVALID_HANDLE_VALUE;
	char name[PS_BUFFER_SIZE + 32];

	if (ident_handle != INVALID_HANDLE_VALUE)
		CloseHandle(ident_handle);

	sprintf(name, "mowgli_ident(%d): %s", getpid(), ps_buffer);

	ident_handle = CreateEvent(NULL, TRUE, FALSE, name);
# endif /* MOWGLI_SETPROC_USE_WIN32 */
#endif /* not MOWGLI_SETPROC_USE_NONE */
}
Exemple #24
0
void pr_proctitle_set(const char *fmt, ...) {
#ifndef PR_DEVEL_STACK_TRACE
  va_list msg;

  if (proc_flags & PR_PROCTITLE_FL_USE_STATIC) {
    return;
  }

# ifndef HAVE_SETPROCTITLE
#  if PF_ARGV_TYPE == PF_ARGV_PSTAT
  union pstun pst;
#  endif /* PF_ARGV_PSTAT */
  char *p;
  int i, procbuflen, maxlen = (prog_last_argv - prog_argv[0]) - 2;
# endif /* HAVE_SETPROCTITLE */

  if (!fmt)
    return;

  va_start(msg, fmt);

  memset(proc_title_buf, 0, sizeof(proc_title_buf));

# ifdef HAVE_SETPROCTITLE
#  if __FreeBSD__ >= 4 && !defined(FREEBSD4_0) && !defined(FREEBSD4_1)
  /* FreeBSD's setproctitle() automatically prepends the process name. */
  vsnprintf(proc_title_buf, sizeof(proc_title_buf), fmt, msg);

#  else /* FREEBSD4 */
  /* Manually append the process name for non-FreeBSD platforms. */
  snprintf(proc_title_buf, sizeof(proc_title_buf), "%s", "proftpd: ");
  vsnprintf(proc_title_buf + strlen(proc_title_buf),
    sizeof(proc_title_buf) - strlen(proc_title_buf), fmt, msg);

#  endif /* FREEBSD4 */
  setproctitle("%s", proc_title_buf);

# else /* HAVE_SETPROCTITLE */
  /* Manually append the process name for non-setproctitle() platforms. */
  snprintf(proc_title_buf, sizeof(proc_title_buf), "%s", "proftpd: ");
  vsnprintf(proc_title_buf + strlen(proc_title_buf),
    sizeof(proc_title_buf) - strlen(proc_title_buf), fmt, msg);

# endif /* HAVE_SETPROCTITLE */

  va_end(msg);

# ifdef HAVE_SETPROCTITLE
  return;
# else
  procbuflen = strlen(proc_title_buf);

#  if PF_ARGV_TYPE == PF_ARGV_NEW
  /* We can just replace argv[] arguments.  Nice and easy. */
  prog_argv[0] = proc_title_buf;
  for (i = 1; i < prog_argc; i++) {
    prog_argv[i] = "";
  }
#  endif /* PF_ARGV_NEW */

#  if PF_ARGV_TYPE == PF_ARGV_WRITEABLE
  /* We can overwrite individual argv[] arguments.  Semi-nice. */
  snprintf(prog_argv[0], maxlen, "%s", proc_title_buf);
  p = &prog_argv[0][procbuflen];

  while (p < prog_last_argv)
    *p++ = '\0';

  for (i = 1; i < prog_argc; i++) {
    prog_argv[i] = "";
  }

#  endif /* PF_ARGV_WRITEABLE */

#  if PF_ARGV_TYPE == PF_ARGV_PSTAT
  pst.pst_command = proc_title_buf;
  pstat(PSTAT_SETCMD, pst, procbuflen, 0, 0);

#  endif /* PF_ARGV_PSTAT */

#  if PF_ARGV_TYPE == PF_ARGV_PSSTRINGS
  PS_STRINGS->ps_nargvstr = 1;
  PS_STRINGS->ps_argvstr = proc_title_buf;
#  endif /* PF_ARGV_PSSTRINGS */

# endif /* HAVE_SETPROCTITLE */
#endif /* !PR_DEVEL_STACK_TRACE */
}
Exemple #25
0
// TODO: allow commandline options (v2)
// TODO: remove existing infs for similar devices (v2)
int __cdecl main(int argc_ansi, char** argv_ansi)
{
	DWORD r;
	BOOL b;
	int i, ret, argc = argc_ansi, si=0;
	char** argv = argv_ansi;
	wchar_t **wenv, **wargv;
	char* hardware_id = NULL;
	char* device_id = NULL;
	char* user_sid = NULL;
	char* inf_name = NULL;
	char path[MAX_PATH_LENGTH];
	char destname[MAX_PATH_LENGTH];
	uintptr_t syslog_reader_thid = -1L;

	// Connect to the messaging pipe
	pipe_handle = CreateFileA(INSTALLER_PIPE_NAME, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
		FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, NULL);
	if (pipe_handle == INVALID_HANDLE_VALUE) {
		// If we can't connect to the pipe, someone is probably trying to run us standalone
		printf("This application can not be run from the command line.\n");
		printf("Please use your initial installer application if you want to install the driver.\n");
		return WDI_ERROR_NOT_SUPPORTED;
	}

	if (init_dlls()) {
		plog("could not init DLLs");
		ret = WDI_ERROR_RESOURCE;
		goto out;
	}

	// Initialize COM for Restore Point disabling
	CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

	// libwdi provides the arguments as UTF-16 => read them and convert to UTF-8
	if (__wgetmainargs != NULL) {
		__wgetmainargs(&argc, &wargv, &wenv, 1, &si);
		argv = calloc(argc, sizeof(char*));
		for (i=0; i<argc; i++) {
			argv[i] = wchar_to_utf8(wargv[i]);
		}
	} else {
		plog("unable to access UTF-16 args - trying ANSI");
	}

	if (argc < 2) {
		printf("usage: %s <inf_name>\n", argv[0]);
		plog("missing inf_name parameter");
	}

	inf_name = argv[1];
	plog("got parameter %s", argv[1]);
	r = GetFullPathNameU(".", MAX_PATH_LENGTH, path, NULL);
	if ((r == 0) || (r > MAX_PATH_LENGTH)) {
		plog("could not retrieve absolute path of working directory");
		ret = WDI_ERROR_ACCESS;
		goto out;
	}
	safe_strcat(path, MAX_PATH_LENGTH, "\\");
	safe_strcat(path, MAX_PATH_LENGTH, inf_name);

	device_id = req_id(IC_GET_DEVICE_ID);
	hardware_id = req_id(IC_GET_HARDWARE_ID);
	// Will be used if we ever need to create a file, as the original user, from this app
	user_sid = req_id(IC_GET_USER_SID);
	ConvertStringSidToSidA(user_sid, &user_psid);

	// Setup the syslog reader thread
	syslog_ready_event = CreateEvent(NULL, TRUE, FALSE, NULL);
	syslog_terminate_event = CreateEvent(NULL, TRUE, FALSE, NULL);
	syslog_reader_thid = _beginthread(syslog_reader_thread, 0, 0);
	if ( (syslog_reader_thid == -1L)
	  || (WaitForSingleObject(syslog_ready_event, 2000) != WAIT_OBJECT_0) )	{
		plog("Unable to create syslog reader thread");
		SetEvent(syslog_terminate_event);
		// NB: if you try to close the syslog reader thread handle, you get a
		// "more recent driver was found" error from UpdateForPnP. Weird...
	}

	// Disable the creation of a restore point
	disable_system_restore(true);

	// Find if the device is plugged in
	send_status(IC_SET_TIMEOUT_INFINITE);
	if (hardware_id != NULL) {
		plog("Installing driver for %s - please wait...", hardware_id);
		b = UpdateDriverForPlugAndPlayDevicesU(NULL, hardware_id, path, INSTALLFLAG_FORCE, NULL);
		send_status(IC_SET_TIMEOUT_DEFAULT);
		if (b == true) {
			// Success
			plog("driver update completed");
			enumerate_device(device_id);
			ret = WDI_SUCCESS;
			goto out;
		}

		ret = process_error(GetLastError(), path);
		if (ret != WDI_SUCCESS) {
			goto out;
		}
	}

	// TODO: try URL for OEMSourceMediaLocation (v2)
	plog("Copying inf file (for the next time device is plugged) - please wait...");
	send_status(IC_SET_TIMEOUT_INFINITE);
	b = SetupCopyOEMInfU(path, NULL, SPOST_PATH, 0, destname, MAX_PATH_LENGTH, NULL, NULL);
	send_status(IC_SET_TIMEOUT_DEFAULT);
	if (b) {
		plog("copied inf to %s", destname);
		ret = WDI_SUCCESS;
		enumerate_device(device_id);
		goto out;
	}

	ret = process_error(GetLastError(), path);
	if (ret != WDI_SUCCESS) {
		goto out;
	}

	// If needed, flag removed devices for reinstallation. see:
	// http://msdn.microsoft.com/en-us/library/aa906206.aspx
	check_removed(hardware_id);

out:
	// Report any error status code and wait for target app to read it
	send_status(IC_INSTALLER_COMPLETED);
	pstat(ret);
	// Restore the system restore point creation original settings
	disable_system_restore(false);
	// TODO: have libwi send an ACK?
	Sleep(1000);
	SetEvent(syslog_terminate_event);
	if (argv != argv_ansi) {
		for (i=0; i<argc; i++) {
			safe_free(argv[i]);
		}
		safe_free(argv);
	}
	CloseHandle(syslog_ready_event);
	CloseHandle(syslog_terminate_event);
	CloseHandle((HANDLE)syslog_reader_thid);
	CloseHandle(pipe_handle);
	return ret;
}
Exemple #26
0
/*
 * Call this to update the ps status display to a fixed prefix plus an
 * indication of what you're currently doing passed in the argument.
 */
void
setproctitle(const char *fmt, ...)
{
#if SETPROCTITLE_STRATEGY == PS_USE_PSTAT
	union pstun pst;
#endif
#if SETPROCTITLE_STRATEGY != PS_USE_NONE
	ssize_t used;
	va_list ap;

	/* no ps display if you didn't call save_ps_display_args() */
	if (save_argv == NULL)
		return;
#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
	/* If ps_buffer is a pointer, it might still be null */
	if (ps_buffer == NULL)
		return;
#endif /* PS_USE_CLOBBER_ARGV */

	/*
	 * Overwrite argv[] to point at appropriate space, if needed
	 */
#if SETPROCTITLE_STRATEGY == PS_USE_CHANGE_ARGV
	save_argv[0] = ps_buffer;
	save_argv[1] = NULL;
#endif /* PS_USE_CHANGE_ARGV */

#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
	save_argv[1] = NULL;
#endif /* PS_USE_CLOBBER_ARGV */

	/*
	 * Make fixed prefix of ps display.
	 */

	va_start(ap, fmt);
	if (fmt == NULL)
		snprintf(ps_buffer, ps_buffer_size, "%s", __progname);
	else {
		used = snprintf(ps_buffer, ps_buffer_size, "%s: ", __progname);
		if (used == -1 || used >= ps_buffer_size)
			used = ps_buffer_size;
		vsnprintf(ps_buffer + used, ps_buffer_size - used, fmt, ap);
	}
	va_end(ap);

#if SETPROCTITLE_STRATEGY == PS_USE_PSTAT
	pst.pst_command = ps_buffer;
	pstat(PSTAT_SETCMD, pst, strlen(ps_buffer), 0, 0);
#endif   /* PS_USE_PSTAT */

#if SETPROCTITLE_STRATEGY == PS_USE_PS_STRINGS
	PS_STRINGS->ps_nargvstr = 1;
	PS_STRINGS->ps_argvstr = ps_buffer;
#endif   /* PS_USE_PS_STRINGS */

#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
	/* pad unused memory */
	used = strlen(ps_buffer);
	memset(ps_buffer + used, SETPROCTITLE_PS_PADDING, 
	    ps_buffer_size - used);
#endif   /* PS_USE_CLOBBER_ARGV */

#endif /* PS_USE_NONE */
}
Exemple #27
0
int
main(int argc, char *argv[])
{
    static const char stat[][2] = { "R", "Z", "S" };
    static const char pol[][5] = { "FIFO", "RR  " };
    static struct threadinfo ti;
    static struct procinfo pi;
    int ch, rc, ps_flag = 0;
    pid_t last_pid = -2;

    while ((ch = getopt(argc, argv, "lx")) != -1)
        switch(ch) {
        case 'x':
            ps_flag |= PSFX;
            break;
        case 'l':
            ps_flag |= PSFL;
            break;

        case '?':
        default:
            fprintf(stderr, "usage: ps [-lx]\n");
            exit(1);
        }
    argc -= optind;
    argv += optind;

    if (object_lookup("!proc", &procobj))
        exit(1);

    if (ps_flag & PSFL)
        printf("  PID  PPID PRI STAT POL      TIME WCHAN       CMD\n");
    else
        printf("  PID     TIME CMD\n");

    rc = 0;
    ti.cookie = 0;
    do {
        /*
         * Get thread info from kernel.
         */
        rc = sys_info(INFO_THREAD, &ti);
        if (!rc) {
            /*
             * Get process info from server.
             */
            if (pstat(ti.task, &pi) && !(ps_flag & PSFX))
                continue;

            if (ps_flag & PSFL) {
                if (pi.pid == -1)
                    printf("    -     -"); /* kernel */
                else
                    printf("%5d %5d", pi.pid, pi.ppid);

                printf(" %3d %s    %s %8d "
                       "%-11s %-11s\n",
                       ti.priority, stat[pi.stat-1],
                       pol[ti.policy],
                       ti.time, ti.slpevt, ti.taskname);
            } else {
                if (!(ps_flag & PSFX) && (pi.pid == last_pid))
                    continue;
                if (pi.pid == -1)
                    printf("    -"); /* kernel */
                else
                    printf("%5d", pi.pid);

                printf(" %8d %-11s\n", ti.time, ti.taskname);
                last_pid = pi.pid;
            }
        }
    } while (rc == 0);
    exit(0);
}
Exemple #28
0
/*VARARGS1*/
void
setproctitle(const char *fmt, ...)
{
# if SPT_TYPE != SPT_NONE
	register char *p;
	register int i;
	SETPROC_STATIC char buf[SPT_BUFSIZE];
	VA_LOCAL_DECL
#  if SPT_TYPE == SPT_PSTAT
	union pstun pst;
#  endif
#  if SPT_TYPE == SPT_SCO
	off_t seek_off;
	static int kmem = -1;
	static int kmempid = -1;
	struct user u;
#  endif

	p = buf;

	/* print application name heading for grep */
//	(void) strcpy(p, ApplicationPrefix);
	(void) strcpy(p, "SuckMT : ");
	p += strlen(p);

	/* print the argument string */
	VA_START(fmt);
	(void) vsnprintf(p, SPACELEFT(buf, p), fmt, ap);
	VA_END;

	i = strlen(buf);

#  if SPT_TYPE == SPT_PSTAT
	pst.pst_command = buf;
	pstat(PSTAT_SETCMD, pst, i, 0, 0);
#  endif
#  if SPT_TYPE == SPT_PSSTRINGS
	PS_STRINGS->ps_nargvstr = 1;
	PS_STRINGS->ps_argvstr = buf;
#  endif
#  if SPT_TYPE == SPT_SYSMIPS
	sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf);
#  endif
#  if SPT_TYPE == SPT_SCO
	if (kmem < 0 || kmempid != getpid())
	{
		if (kmem >= 0)
			close(kmem);
		kmem = open(_PATH_KMEM, O_RDWR, 0);
		if (kmem < 0)
			return;
		(void) fcntl(kmem, F_SETFD, 1);
		kmempid = getpid();
	}
	buf[PSARGSZ - 1] = '\0';
	seek_off = UVUBLK + (off_t) u.u_psargs - (off_t) &u;
	if (lseek(kmem, (off_t) seek_off, SEEK_SET) == seek_off)
		(void) write(kmem, buf, PSARGSZ);
#  endif
#  if SPT_TYPE == SPT_REUSEARGV
	if (i > LastArgv - Argv[0] - 2)
	{
		i = LastArgv - Argv[0] - 2;
		buf[i] = '\0';
	}
	(void) strcpy(Argv[0], buf);
	p = &Argv[0][i];
	while (p < LastArgv)
		*p++ = SPT_PADCHAR;
	Argv[1] = NULL;
#  endif
#  if SPT_TYPE == SPT_CHANGEARGV
	Argv[0] = buf;
	Argv[1] = 0;
#  endif
# endif /* SPT_TYPE != SPT_NONE */
}
Exemple #29
0
/*
 * Call this to update the ps status display to a fixed prefix plus an
 * indication of what you're currently doing passed in the argument.
 */
void
set_ps_display(const char *activity, bool force)
{

    if (!force && !update_process_title)
        return;

#ifndef PS_USE_NONE

#ifdef PS_USE_CLOBBER_ARGV
    /* If ps_buffer is a pointer, it might still be null */
    if (!ps_buffer)
        return;
#endif

    /* Update ps_buffer to contain both fixed part and activity */
    spt_strlcpy(ps_buffer + ps_buffer_fixed_size, activity,
            ps_buffer_size - ps_buffer_fixed_size);

    /* Transmit new setting to kernel, if necessary */

#ifdef PS_USE_SETPROCTITLE
    setproctitle("%s", ps_buffer);
#endif

#ifdef PS_USE_PSTAT
    {
        union pstun pst;

        pst.pst_command = ps_buffer;
        pstat(PSTAT_SETCMD, pst, strlen(ps_buffer), 0, 0);
    }
#endif   /* PS_USE_PSTAT */

#ifdef PS_USE_PS_STRINGS
    PS_STRINGS->ps_nargvstr = 1;
    PS_STRINGS->ps_argvstr = ps_buffer;
#endif   /* PS_USE_PS_STRINGS */

#ifdef PS_USE_CLOBBER_ARGV
    {
        size_t      buflen;

        /* pad unused memory */
        buflen = strlen(ps_buffer);
        /* clobber remainder of old status string */
        if (last_status_len > buflen)
            memset(ps_buffer + buflen, PS_PADDING, last_status_len - buflen);
        last_status_len = buflen;
    }
#endif   /* PS_USE_CLOBBER_ARGV */

#ifdef PS_USE_PRCTL
    prctl(PR_SET_NAME, ps_buffer);
#endif

#ifdef PS_USE_WIN32
    {
        /*
         * Win32 does not support showing any changed arguments. To make it at
         * all possible to track which backend is doing what, we create a
         * named object that can be viewed with for example Process Explorer.
         */
        static HANDLE ident_handle = INVALID_HANDLE_VALUE;
        char        name[PS_BUFFER_SIZE + 32];

        if (ident_handle != INVALID_HANDLE_VALUE)
            CloseHandle(ident_handle);

        sprintf(name, "python(%d): %s", _getpid(), ps_buffer);

        ident_handle = CreateEvent(NULL, TRUE, FALSE, name);
    }
#endif   /* PS_USE_WIN32 */
#endif   /* not PS_USE_NONE */
}
Exemple #30
0
/****** uti/os/sge_nprocs() ***************************************************
*  NAME
*     sge_nprocs() -- Number of processors in this machine
*
*  SYNOPSIS
*     int sge_nprocs()
*
*  FUNCTION
*     Use this function to get the number of processors in
*     this machine
*
*  RESULT
*     int - number of procs
*
*  NOTES
*     MT-NOTE: sge_nprocs() is MT safe (SOLARIS, NEC, IRIX, ALPHA, HPUX, LINUX)
******************************************************************************/
int sge_nprocs()
{
    int nprocs=1; /* default */
#if defined(NECSX4) || defined(NECSX5)
    int fd;
    int fsg_id;
    rsg_info_t info;
    char fsg_dev_string[256];
#endif

    /* NEC SX 4/16, NEC SX 4/32 */
#if defined(NECSX4) || defined(NECSX5)
    /*
     * Using RSG values alone is unreliable.
     */
#if 0
    nprocs = 0;
    for (fsg_id=0; fsg_id<32; fsg_id++) {
        sprintf(fsg_dev_string, "/dev/rsg/%d", fsg_id);
        fd = open(fsg_dev_string, O_RDONLY);
        if (fd > 0) {
            if (ioctl(fd, RSG_INFO, &info) == -1) {
                close(fd);
                continue;
            }
            close(fd);

            nprocs += info.cprb.init_cpu;
        }
    }
    if (nprocs == 0) {
        nprocs=1;
    }
#elif 1
#if defined(CNFGAPNUM)
    /*
     * SUPER-UX >= 11.x provides a function.
     */
    nprocs = syssx(CNFGAPNUM);
#else
    {
        /*
         * As with sge_loadmem(), get RB info and tally
         * it up.
         */
        char       fsg_dev_string[256];
        int        fd, fsg_id;
        rsg_id_t   id;
        rsg_info_t info;
        cpurb_t    cpurbs[MAXRBNUM];
        int        i;

        /* initialize */
        for (i = 0; i < MAXRBNUM; i++) {
            memset(&cpurbs[i], 0, sizeof(cpurb_t));
        }

        /* read in RB info (don't be fooled by RSG names) */
        for (fsg_id = 0; fsg_id < MAXRSGNUM; fsg_id++) {
            sprintf(fsg_dev_string, "/dev/rsg/%d", fsg_id);
            fd = open(fsg_dev_string, O_RDONLY);
            if (fd >= 0) {
                if ((ioctl(fd, RSG_ID, &id) == -1) ||
                        (ioctl(fd, RSG_INFO, &info) == -1)) {
                    close(fd);
                    continue;
                }
                close(fd);

                /* copy for later use */
                memcpy(&cpurbs[id.cprbid], &info.cprb, sizeof(cpurb_t));
            }
        }

        nprocs = 0;
        for (i = 0; i < MAXRBNUM; i++) {
            nprocs += cpurbs[i].init_cpu;
        }
    }
#endif /* CNFGAPNUM */
#endif

#endif

#if defined(DARWIN)
    struct host_basic_info cpu_load_data;

    mach_msg_type_number_t host_count = sizeof(cpu_load_data)/sizeof(integer_t);
    mach_port_t host_priv_port = mach_host_self();

    host_info(host_priv_port, HOST_BASIC_INFO , (host_info_t)&cpu_load_data, &host_count);

    nprocs =  cpu_load_data.avail_cpus;

#endif


#ifdef __sgi
    nprocs = sysmp(MP_NPROCS);
#endif

#if defined(ALPHA)
    int start=0;

    getsysinfo(GSI_CPUS_IN_BOX,(char*)&nprocs,sizeof(nprocs),&start);
#endif

#if defined(SOLARIS) || defined(AIX) || defined(LINUX)
    nprocs = sysconf(_SC_NPROCESSORS_ONLN);
#endif

#if defined(__hpux)
    union pstun pstatbuf;
    struct pst_dynamic dinfo;

    pstatbuf.pst_dynamic = &dinfo;
    if (pstat(PSTAT_DYNAMIC,pstatbuf,sizeof(dinfo),NULL,NULL)==-1) {
        perror(MSG_PERROR_PSTATDYNAMIC);
        exit(1);
    }
    nprocs = dinfo.psd_proc_cnt;
#endif

#ifdef CRAY
    nprocs = sysconf(_SC_CRAY_NCPU);
#endif

#if defined(FREEBSD)
    size_t nprocs_len = sizeof(nprocs);

    if (sysctlbyname("hw.ncpu", &nprocs, &nprocs_len, NULL, 0) == -1) {
        nprocs = -1;
    }
#endif

#if defined(NETBSD)
    int mib[2];
    size_t nprocs_len;

    nprocs_len = sizeof(nprocs);
    mib[0]     = CTL_HW;
    mib[1]     = HW_NCPU;

    if (sysctl(mib, sizeof(mib)/sizeof(int), &nprocs, &nprocs_len, NULL, 0) == -1) {
        nprocs = -1;
    }
#endif

#if defined(INTERIX)
    /* TODO: HP: don't set nprocs==-1 to 0, overwrite it with value from
     *       external load sensor.
     */
    nprocs = -1;
#endif

    if (nprocs <= 0) {
        nprocs = 1;
    }

    return nprocs;
}