static void
prepare_output (DrvData    *or_data,
		const char *dev_dir_name,
		const char *trigger_name)
{
	IIOSensorData data;

	int fp, buf_len = 127;

	data.data = g_malloc(or_data->buffer_data->scan_size * buf_len);

	/* Attempt to open non blocking to access dev */
	fp = open (or_data->dev_path, O_RDONLY | O_NONBLOCK);
	if (fp == -1) { /* If it isn't there make the node */
		g_warning ("Failed to open %s : %s", or_data->dev_path, strerror(errno));
		goto bail;
	}

	/* Actually read the data */
	data.read_size = read (fp, data.data, buf_len * or_data->buffer_data->scan_size);
	if (data.read_size == -1 && errno == EAGAIN) {
		g_debug ("No new data available");
	} else {
		process_scan(data, or_data);
	}

	close(fp);

bail:
	g_free(data.data);
}
main () {

   /* Find my group and member IDs for $getjpi */  
   status = sys$getjpiw(0,0,0,getjpi_items,&jpi_iosb,0,0);
   if (!(status & 1)) lib$signal(status);
   if (!(jpi_iosb.iosb_status & 1)) lib$signal(jpi_iosb.iosb_status);

   /* Build the pscan stuff */
   assert (psitems[1].code == PSCAN$_GRP);
   psitems[1].val = mygrp;
   assert (psitems[2].code == PSCAN$_MEM);
   psitems[2].val = mymem;

   /* Build the context for $getjpi */
   status = sys$process_scan(&ps_ctx, &psitems);
   if (!(status & 1)) lib$signal(status);
   status = lib$date_time(&time_desc);
   printf("\n         Checking uptime agent status at: %s\n",timestring);


   printf("\n               Image         Node       Pid       CPUsec        ppgcnt  gpgcnt\n");
   printf("----------------------------------------------------------------------------------\n");

   /* Run the context until all processes found */
   while (TRUE) {
      status = sys$getjpiw (EFN$C_ENF, &ps_ctx, 0, getjpi_items, &jpi_iosb, 0, 0);
      if (jpi_iosb.iosb_status == SS$_NOMOREPROC) {
         printf("----------------------------------------------------------------------------------\n");
         break;
      }else{
         if (!(jpi_iosb.iosb_status & 1)) lib$signal(jpi_iosb.iosb_status);
         total_mem = pages + gblpages;
         lib$trim_filespec(&img_desc,&short_desc,&sizeof(shortname));  /* Just the filename  */
         if (strstr(shortname,"UPTIME-AGENT") != NULL) { 
            status = sys$asctim(&timlen,&time_desc,&logintime,timeflag);  /* Convert binary time */
            printf ("%20s       %6s  %x     %8.1f        %6d  %6d\n",
               shortname,nodename,mypid,(float)cputime/100,pages,gblpages);   
         } 
      }
   }
}
Пример #3
0
void yf::AuthSimple::process(mp::Package &package) const
{
    Z_GDU *gdu = package.request().get();

    if (!gdu || gdu->which != Z_GDU_Z3950) {
        // Pass on the package -- This means that authentication is
        // waived, which may not be the correct thing for non-Z APDUs
        // as it means that SRW sessions don't demand authentication
        return package.move();
    }

    if (m_p->got_userRegister) {
        switch (gdu->u.z3950->which) {
        case Z_APDU_initRequest:
            return process_init(package);
        case Z_APDU_searchRequest:
            return process_search(package);
        case Z_APDU_scanRequest:
            return process_scan(package);
        // In theory, we should check database authorisation for
        // extended services, too (A) the proxy currently does not
        // implement XS and turns off its negotiation bit; (B) it
        // would be insanely complex to do as the top-level XS request
        // structure does not carry a database name, but it is buried
        // down in some of the possible EXTERNALs used as
        // taskSpecificParameters; and (C) since many extended
        // services modify the database, we'd need to more exotic
        // authorisation database than we want to support.
        default:
            break;
        }
    }

    if (m_p->got_targetRegister && gdu->u.z3950->which == Z_APDU_initRequest)
        return check_targets(package);

    // Operations other than those listed above do not require authorisation
    return package.move();
}
Пример #4
0
int
main(int argc, const char *argv[])
{
    struct sigaction sa;
    int restart;
    
    /* Set up the signal handlers */
    /* TODO: We need to handle every signal that could possibly kill us */
    memset (&sa, 0, sizeof(struct sigaction));
    sa.sa_handler = &quit_signal;
    sigaction (SIGQUIT, &sa, NULL);
    sigaction (SIGINT, &sa, NULL);
    sigaction (SIGTERM, &sa, NULL);
    
    sa.sa_handler = &catch_signal;
    sigaction(SIGHUP, &sa, NULL);
    sigaction(SIGPIPE, &sa, NULL);

    sa.sa_handler = &child_signal;
    sigaction (SIGCHLD, &sa, NULL);

    /* Set this first in case we need to output some data */
    /* If we ever open the logger with syslog instead, we'll have to
     * make sure and close the logger before we deamonize and then
     * call logger_init() again afterwards */
    logger_init(LOG_TYPE_STDOUT, "opendax");
    process_init();
    /* TODO: We should have individual configuration objects that we retrieve
     * from this function, instead of the global data in the source file. */
    opt_configure(argc, argv);

    if(opt_daemonize()) {
        daemonize("opendax");
        logger_init(LOG_TYPE_SYSLOG, "opendax");
    }
    process_start_all();

    _print_process_list();

    while(1) { /* Main loop */
        /* TODO: This might could be some kind of condition
           variable or signal thing instead of just the sleep(). */
        restart = process_scan();
        if(restart < 1000) {
            usleep(restart * 1000);
        } else {
            sleep(1);
        }
        /* If the quit flag is set then we clean up and get out */
        if(quitflag) {
            xlog(LOG_MAJOR, "Master quiting due to signal %d", quitflag);
            /* TODO: Should stop all running modules and wait for them
               to exit.  If they fail then kill -9 those rascals*/
            kill(0, SIGTERM); /* ...this'll do for now */
            closelog();
            exit(-1);
        }
 
    }
    exit(0);
}
Пример #5
0
Boolean Process::loadProcessInfo (int &pIndex)
{
    int status;
    unsigned long maxprocount;
    __int64 qpid;
    char handle[100];
    unsigned long jpictx2; /* The context for JPI calls */
    item_list itmlst3[MAXITMLST];
    int procCount;
    Boolean stat;

    /* If this is the first process request. Rebuild proc_table */
    if (pIndex == 0)
    {
        /* Lock the mutex on proc_table */
        pthread_mutex_lock(&proc_table_mutex);

        /* Free the old proc_table */
        if (proc_table != NULL)
        {
            free(proc_table);
            proc_table = NULL;
            proc_table_count = 0;
        }

        /* Find the maximum process that could run on the system */
        if ((maxprocount = getmaxprocount ()) == 0)
        {
            /* Un lock the mutex on proc_table */
            pthread_mutex_unlock(&proc_table_mutex);
            /* Return false */
            return false;
        }

        /* Allocate memory to proc_table */
        proc_table =
            (proc_info_t) calloc (maxprocount + 1, sizeof (struct proc_info));

        /* Error in allocating Memory. return false */
        if (NULL == proc_table)
        {
            /* Un lock the mutex on proc_table */
            pthread_mutex_unlock(&proc_table_mutex);
            return false;
        }

        jpictx2 = 0;
        procCount = 0;
        itmlst3[0].wlength = 0;
        itmlst3[0].wcode = PSCAN$_MODE;
        itmlst3[0].pbuffer = (void *) JPI$K_OTHER;
        itmlst3[0].pretlen = NULL;
        itmlst3[1].wlength = 0;
        itmlst3[1].wcode = 0;
        itmlst3[1].pbuffer = NULL;
        itmlst3[1].pretlen = NULL;

        status = sys$process_scan (&jpictx2, itmlst3);
        if (!$VMS_STATUS_SUCCESS (status))
        {
            /* Free the proc_table */
            free (proc_table);
            proc_table = NULL;
            proc_table_count = 0;

            /* Un lock the mutex on proc_table */
            pthread_mutex_unlock(&proc_table_mutex);

            /* Return failure */
            return false;
        }

        stat = buildProcessTable(jpictx2, procCount, itmlst3, proc_table);
        proc_table_count += procCount;

        jpictx2 = 0;
        procCount = 0;
        itmlst3[0].wlength = 0;
        itmlst3[0].wcode = PSCAN$_MODE;
        itmlst3[0].pbuffer = (void *) JPI$K_BATCH;
        itmlst3[0].pretlen = NULL;
        itmlst3[1].wlength = 0;
        itmlst3[1].wcode = 0;
        itmlst3[1].pbuffer = NULL;
        itmlst3[1].pretlen = NULL;

        status = sys$process_scan (&jpictx2, itmlst3);
        if (!$VMS_STATUS_SUCCESS (status))
        {
            /* Free the proc_table */
            free (proc_table);
            proc_table = NULL;
            proc_table_count = 0;

            /* Un lock the mutex on proc_table */
            pthread_mutex_unlock(&proc_table_mutex);

            /* Return failure */
            return false;
        }

        stat = buildProcessTable(jpictx2, procCount, itmlst3,
                                 &proc_table[proc_table_count]);
        proc_table_count += procCount;

        jpictx2 = 0;
        procCount = 0;
        itmlst3[0].wlength = 0;
        itmlst3[0].wcode = PSCAN$_MODE;
        itmlst3[0].pbuffer = (void *) JPI$K_NETWORK;
        itmlst3[0].pretlen = NULL;
        itmlst3[1].wlength = 0;
        itmlst3[1].wcode = 0;
        itmlst3[1].pbuffer = NULL;
        itmlst3[1].pretlen = NULL;

        status = sys$process_scan (&jpictx2, itmlst3);
        if (!$VMS_STATUS_SUCCESS (status))
        {
            /* Free the proc_table */
            free (proc_table);
            proc_table = NULL;
            proc_table_count = 0;

            /* Un lock the mutex on proc_table */
            pthread_mutex_unlock(&proc_table_mutex);

            /* Return failure */
            return false;
        }

        stat = buildProcessTable(jpictx2, procCount, itmlst3,
                                 &proc_table[proc_table_count]);
        proc_table_count += procCount;

        jpictx2 = 0;
        itmlst3[0].wlength = 0;
        itmlst3[0].wcode = PSCAN$_MODE;
        itmlst3[0].pbuffer = (void *) JPI$K_INTERACTIVE;
        itmlst3[0].pretlen = NULL;
        itmlst3[1].wlength = 0;
        itmlst3[1].wcode = 0;
        itmlst3[1].pbuffer = NULL;
        itmlst3[1].pretlen = NULL;

        status = sys$process_scan (&jpictx2, itmlst3);
        if (!$VMS_STATUS_SUCCESS (status))
        {
            /* Free the proc_table */
            free (proc_table);
            proc_table = NULL;
            proc_table_count = 0;

            /* Un lock the mutex on proc_table */
            pthread_mutex_unlock(&proc_table_mutex);

            /* Return failure */
            return false;
        }

        stat = buildProcessTable(jpictx2, procCount, itmlst3,
                                 &proc_table[proc_table_count]);
        proc_table_count += procCount;

        /* Un lock the mutex on proc_table */
        pthread_mutex_unlock(&proc_table_mutex);
    } /* End if (pIndex == 0), rebuild of proc_table */

    return getProcessInfo(pIndex);
}
Пример #6
0
Boolean Process::loadProcessInfo (int &pIndex)
{
  int status;
  unsigned long maxprocount;
  __int64 qpid;
  char handle[100];

  Boolean stat;

  if ((maxprocount = getmaxprocount ()) == 0)
  {
    return false;
  }

  if (pIndex == 0)
  {
    if (proc_table != NULL)
    {
      free (proc_table);
    }
    proc_table = (proc_info_t) calloc (maxprocount + 1, sizeof (struct proc_info));
    pInfo = pData = proc_table;

    jpictx2 = 0;
    procCount = 0;
    ii = 1;

    itmlst3[0].wlength = 0;
    itmlst3[0].wcode = PSCAN$_MODE;
    itmlst3[0].pbuffer = (void *) JPI$K_OTHER;
    itmlst3[0].pretlen = NULL;
    itmlst3[1].wlength = 0;
    itmlst3[1].wcode = 0;
    itmlst3[1].pbuffer = NULL;
    itmlst3[1].pretlen = NULL;

    status = sys$process_scan (&jpictx2, itmlst3);
    if (!$VMS_STATUS_SUCCESS (status))
    {
      return status;
    }

    stat = buildProcessTable();

    jpictx2 = 0;
    itmlst3[0].wlength = 0;
    itmlst3[0].wcode = PSCAN$_MODE;
    itmlst3[0].pbuffer = (void *) JPI$K_BATCH;
    itmlst3[0].pretlen = NULL;
    itmlst3[1].wlength = 0;
    itmlst3[1].wcode = 0;
    itmlst3[1].pbuffer = NULL;
    itmlst3[1].pretlen = NULL;

    status = sys$process_scan (&jpictx2, itmlst3);
    if (!$VMS_STATUS_SUCCESS (status))
    {
      return status;
    }

    stat = buildProcessTable();

    jpictx2 = 0;
    itmlst3[0].wlength = 0;
    itmlst3[0].wcode = PSCAN$_MODE;
    itmlst3[0].pbuffer = (void *) JPI$K_NETWORK;
    itmlst3[0].pretlen = NULL;
    itmlst3[1].wlength = 0;
    itmlst3[1].wcode = 0;
    itmlst3[1].pbuffer = NULL;
    itmlst3[1].pretlen = NULL;

    status = sys$process_scan (&jpictx2, itmlst3);
    if (!$VMS_STATUS_SUCCESS (status))
    {
      return status;
    }

    stat = buildProcessTable();

    jpictx2 = 0;
    itmlst3[0].wlength = 0;
    itmlst3[0].wcode = PSCAN$_MODE;
    itmlst3[0].pbuffer = (void *) JPI$K_INTERACTIVE;
    itmlst3[0].pretlen = NULL;
    itmlst3[1].wlength = 0;
    itmlst3[1].wcode = 0;
    itmlst3[1].pbuffer = NULL;
    itmlst3[1].pretlen = NULL;

    status = sys$process_scan (&jpictx2, itmlst3);
    if (!$VMS_STATUS_SUCCESS (status))
    {
      return status;
    }

    stat = buildProcessTable();

    pInfo = pData;
  }
  else
  {
    if (ii < procCount)
    {
      pInfo++;
      ii++;
    }
    else
    {
      return false;
    }
  }

  if (procCount > 0)
  {
    return true;
  }
  else
  {
    return false;
  }
}