bool
AsciiProcessor::visible_cmd( const char * buf,
                             BuilderBase * build,
                             const char * & next,
                             int visible )
{
    int fref;

    if ( ! str2val( buf, fref, next ) )
    {
        P_ERROR( "no frame reference" );
        return CMD_ERR;
    }

    buf = next;

    if ( ! strskip( buf, DELIMITER_CHAR, next ) )
    {
        P_ERROR( "wrong delimiter char" );
        return CMD_ERR;
    }

    P_MSG( "build->set_cmd_set_frame_visible(" << fref << ");" );

    if ( ! build->set_cmd_set_frame_visible( fref, visible ) )
    {
        P_ERROR( "wrong frame reference" );
    }

    return CMD_OK;
}
bool
AsciiProcessor::emp_cmd( const char * buf,
                         BuilderBase * build,
                         const char * & next )
{
    int fref;

    if ( ! str2val( buf, fref, next ) )
    {
        P_ERROR( "EMP no frame reference" );
        return CMD_ERR;
    }

    buf = next;

    if ( ! strskip( buf, DELIMITER_CHAR, next ) )
    {
        P_ERROR( "wrong delimiter char" );
        return CMD_ERR;
    }

    build->set_cmd_empty_frame( fref );

    P_MSG( "build->set_cmd_empty_frame(" << fref << ");" );

    return CMD_OK;
}
Пример #3
0
static int latency_config_add_bucket(latency_config_t *conf,
                                     oconfig_item_t *ci) {
  if ((ci->values_num != 2) || (ci->values[0].type != OCONFIG_TYPE_NUMBER) ||
      (ci->values[1].type != OCONFIG_TYPE_NUMBER)) {
    P_ERROR("\"%s\" requires exactly two numeric arguments.", ci->key);
    return EINVAL;
  }

  if (ci->values[1].value.number &&
      ci->values[1].value.number <= ci->values[0].value.number) {
    P_ERROR("MIN must be less than MAX in \"%s\".", ci->key);
    return ERANGE;
  }

  if (ci->values[0].value.number < 0) {
    P_ERROR("MIN must be greater then or equal to zero in \"%s\".", ci->key);
    return ERANGE;
  }

  latency_bucket_t *tmp =
      realloc(conf->buckets, sizeof(*conf->buckets) * (conf->buckets_num + 1));
  if (tmp == NULL) {
    P_ERROR("realloc failed.");
    return ENOMEM;
  }
  conf->buckets = tmp;
  conf->buckets[conf->buckets_num].lower_bound =
      DOUBLE_TO_CDTIME_T(ci->values[0].value.number);
  conf->buckets[conf->buckets_num].upper_bound =
      DOUBLE_TO_CDTIME_T(ci->values[1].value.number);
  conf->buckets_num++;

  return 0;
} /* int latency_config_add_bucket */
bool
AsciiProcessor::background_color_cmd( const char * buf,
                                      BuilderBase * build,
                                      const char* & next )
{
    RGBcolor col;

    if ( ! get_col( buf, col, next ) )
    {
        P_ERROR( "wrong color [" << buf << "]" );
        return false;
    }

    buf = next;

    if ( ! strskip( buf, DELIMITER_CHAR, next ) )
    {
        P_ERROR( "wrong delimiter char" );
        return CMD_ERR;
    }

    build->set_cmd_set_background_color( col );

    return CMD_OK;
}
Пример #5
0
static int latency_config_add_percentile(latency_config_t *conf,
                                         oconfig_item_t *ci) {
  double percent;
  int status = cf_util_get_double(ci, &percent);
  if (status != 0)
    return status;

  if ((percent <= 0.0) || (percent >= 100)) {
    P_ERROR("The value for \"%s\" must be between 0 and 100, "
            "exclusively.",
            ci->key);
    return ERANGE;
  }

  double *tmp = realloc(conf->percentile,
                        sizeof(*conf->percentile) * (conf->percentile_num + 1));
  if (tmp == NULL) {
    P_ERROR("realloc failed.");
    return ENOMEM;
  }
  conf->percentile = tmp;
  conf->percentile[conf->percentile_num] = percent;
  conf->percentile_num++;

  return 0;
} /* int latency_config_add_percentile */
Пример #6
0
ConfigMap* ConfigMapParser::map() throw(PARSEEXCEPTION_THROW)
{
  expect(T::CMT_CBL);
  ConfigMap* cm = new ConfigMap();
  std::string* currComments = 0;
  if(token.type == T::CMT_COMMENT)
    currComments = comments();
  try
  {
    while(token.type == T::CMT_KEY)
    {
      std::string key = token.value;
      nextToken();
      try
      {
        expect(T::CMT_EQ);
        if(prefixValue(token))
        {
          ConfigValue* cv = value();
          if(currComments)
            cv->setComment(*currComments);
          try
          {
            (*cm)[key] = *cv;
          }
          catch(invalid_key& ik)
          {
            P_ERROR(ik.what());
          }
          delete cv;
        }
        else
        {
          P_ERROR("Expected begin of a value (`{`, `[` or VALUE), got `" + T::type2str(token.type) + "`");
        }
      }
      catch(ParseException)
      {
        if(currComments) delete currComments;
        throw;
      }
      expect(T::CMT_SEMICOLON);
    }
    expect(T::CMT_CBR);

    if(currComments)
      delete currComments;
    currComments = 0;
    if(token.type == T::CMT_COMMENT)
      currComments = comments();
  }
  catch(ParseException)
  {
    delete cm;
    if(currComments) delete currComments;
    throw;
  }
  if(currComments) delete currComments;
  return cm;
}
bool
AsciiProcessor::visual_area_cmd( const char * buf,
                                 BuilderBase * build,
                                 const char* & next )
{
    Area2d a;
    double d1;
    int res = get_max5_tuple( buf, 4,
                              a.center.x, a.center.y,
                              a.size_x, a.size_y,
                              d1,
                              next );

    if ( res != 4 )
    {
        P_ERROR( "SETAREA wrong area specification, retval= " << res );
        return CMD_ERR;
    }

    buf = next;

    if ( ! strskip( buf, DELIMITER_CHAR, next ) )
    {
        P_ERROR( "wrong delimiter char" );
        return CMD_ERR;
    }

    P_MSG( "build->set_cmd_set_view_area(area[(" << a.center.x << "," << a.center.y << ")," << a.size_x << "," << a.size_y << "]" << ");" );

    build->set_cmd_set_view_area( a );

    return CMD_OK;
}
Пример #8
0
Файл: cclient.c Проект: c3x04/cn
int main(void)
{
    struct addrinfo serv, *res;
    int sockfd;

    memset(&serv, 0, sizeof(serv));
    serv.ai_family = AF_UNSPEC;
    serv.ai_socktype = SOCK_STREAM;
    getaddrinfo(SERV_ADDR, SERV_PORT, &serv, &res);

    sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    if(sockfd < 0) {
        P_ERROR("Couldn't open socket")
    }

    connect(sockfd, res->ai_addr, res->ai_addrlen);
    while(1) {
        char send_buffer[1024] = {'\0'};
        char recv_buffer[1024] = {'\0'};
        printf("\n> ");
        fgets(send_buffer, 1024, stdin);
        int sent_len = send(sockfd, send_buffer, strlen(send_buffer), 0);
        if(sent_len < 0) {
            P_ERROR("Sending Failed")
        }
        memset(&send_buffer, 0, 1024);
        int recv_bytes = 0;
        if ((recv_bytes = recv(sockfd, recv_buffer, 1023, 0)) == -1) {
            P_ERROR("recv Failed !")
        }
        printf("#> %s", recv_buffer);
        memset(&recv_buffer, 0, 1024);
    }
    close(sockfd);
}
bool
AsciiProcessor::status_line_cmd( const char * buf,
                                 BuilderBase * build,
                                 const char * & next )
{
    int res = get_string( buf, characters, next );

    if ( res < 0 )
    {
        P_ERROR( "SL wrong text specification, retval= " << res );
        return CMD_ERR;
    }

    buf = next;

    if ( ! strskip( buf, DELIMITER_CHAR, next ) )
    {
        P_ERROR( "wrong delimiter char" );
        return CMD_ERR;
    }

    P_MSG( "build->set_cmd_set_status(characters);" );

    build->set_cmd_set_status_line( characters.cur_size, characters.tab );

    return CMD_OK;
}
Пример #10
0
P_LIB_API void
p_shm_buffer_clear (PShmBuffer *buf)
{
	ppointer	addr;
	psize		size;

	if (P_UNLIKELY (buf == NULL))
		return;

	if (P_UNLIKELY ((addr = p_shm_get_address (buf->shm)) == NULL)) {
		P_ERROR ("PShmBuffer::p_shm_buffer_clear: p_shm_get_address() failed");
		return;
	}

	size = p_shm_get_size (buf->shm);

	if (P_UNLIKELY (p_shm_lock (buf->shm, NULL) == FALSE)) {
		P_ERROR ("PShmBuffer::p_shm_buffer_clear: p_shm_lock() failed");
		return;
	}

	memset (addr, 0, size);

	if (P_UNLIKELY (p_shm_unlock (buf->shm, NULL) == FALSE))
		P_ERROR ("PShmBuffer::p_shm_buffer_clear: p_shm_unlock() failed");
}
Пример #11
0
/******************************************************************************
 *                              module init/exit                              *
 *****************************************************************************/
static int __init mon_init(void)
{
    int rc;

    if (!MACHINE_IS_VM) {
        P_ERROR("not running under z/VM, driver not loaded\n");
        return -ENODEV;
    }

    /*
     * Register with IUCV and connect to *MONITOR service
     */
    rc = iucv_register(&monreader_iucv_handler, 1);
    if (rc) {
        P_ERROR("failed to register with iucv driver\n");
        return rc;
    }
    P_INFO("open, registered with IUCV\n");

    rc = segment_type(mon_dcss_name);
    if (rc < 0) {
        segment_warning(rc, mon_dcss_name);
        goto out_iucv;
    }
    if (rc != SEG_TYPE_SC) {
        P_ERROR("segment %s has unsupported type, should be SC\n",
            mon_dcss_name);
        rc = -EINVAL;
        goto out_iucv;
    }

    rc = segment_load(mon_dcss_name, SEGMENT_SHARED,
              &mon_dcss_start, &mon_dcss_end);
    if (rc < 0) {
        segment_warning(rc, mon_dcss_name);
        rc = -EINVAL;
        goto out_iucv;
    }
    dcss_mkname(mon_dcss_name, &user_data_connect[8]);

    rc = misc_register(&mon_dev);
    if (rc < 0 ) {
        P_ERROR("misc_register failed, rc = %i\n", rc);
        goto out;
    }
    P_INFO("Loaded segment %s from %p to %p, size = %lu Byte\n",
        mon_dcss_name, (void *) mon_dcss_start, (void *) mon_dcss_end,
        mon_dcss_end - mon_dcss_start + 1);
    return 0;

out:
    segment_unload(mon_dcss_name);
out_iucv:
    iucv_unregister(&monreader_iucv_handler, 1);
    return rc;
}
Пример #12
0
static int cu_tail_reopen(cu_tail_t *obj) {
  int seek_end = 0;
  struct stat stat_buf = {0};

  int status = stat(obj->file, &stat_buf);
  if (status != 0) {
    P_ERROR("utils_tail: stat (%s) failed: %s", obj->file, STRERRNO);
    return -1;
  }

  /* The file is already open.. */
  if ((obj->fh != NULL) && (stat_buf.st_ino == obj->stat.st_ino)) {
    /* Seek to the beginning if file was truncated */
    if (stat_buf.st_size < obj->stat.st_size) {
      P_INFO("utils_tail: File `%s' was truncated.", obj->file);
      status = fseek(obj->fh, 0, SEEK_SET);
      if (status != 0) {
        P_ERROR("utils_tail: fseek (%s) failed: %s", obj->file, STRERRNO);
        fclose(obj->fh);
        obj->fh = NULL;
        return -1;
      }
    }
    memcpy(&obj->stat, &stat_buf, sizeof(struct stat));
    return 1;
  }

  /* Seek to the end if we re-open the same file again or the file opened
   * is the first at all or the first after an error */
  if ((obj->stat.st_ino == 0) || (obj->stat.st_ino == stat_buf.st_ino))
    seek_end = 1;

  FILE *fh = fopen(obj->file, "r");
  if (fh == NULL) {
    P_ERROR("utils_tail: fopen (%s) failed: %s", obj->file, STRERRNO);
    return -1;
  }

  if (seek_end != 0) {
    status = fseek(fh, 0, SEEK_END);
    if (status != 0) {
      P_ERROR("utils_tail: fseek (%s) failed: %s", obj->file, STRERRNO);
      fclose(fh);
      return -1;
    }
  }

  if (obj->fh != NULL)
    fclose(obj->fh);
  obj->fh = fh;
  memcpy(&obj->stat, &stat_buf, sizeof(struct stat));

  return 0;
} /* int cu_tail_reopen */
Пример #13
0
void processAndLogNewSpawnException(SpawnException &e, const Options &options,
	ResourceLocator &resourceLocator, RandomGenerator &randomGenerator)
{
	ErrorRenderer renderer(resourceLocator);
	string errorId = randomGenerator.generateHexString(4);
	string appMessage = e.getErrorPage();
	char filename[PATH_MAX];
	stringstream stream;

	e.set("ERROR_ID", errorId);
	if (appMessage.empty()) {
		appMessage = "none";
	}

	try {
		int fd = -1;
		FdGuard guard(fd, true);
		string errorPage;

		errorPage = renderer.renderWithDetails(appMessage, options, &e);

		#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
			snprintf(filename, PATH_MAX, "%s/passenger-error-XXXXXX.html",
				getSystemTempDir());
			fd = mkstemps(filename, sizeof(".html") - 1);
		#else
			snprintf(filename, PATH_MAX, "%s/passenger-error.XXXXXX",
				getSystemTempDir());
			fd = mkstemp(filename);
		#endif
		if (fd == -1) {
			int e = errno;
			throw SystemException("Cannot generate a temporary filename",
				e);
		}

		writeExact(fd, errorPage);
	} catch (const SystemException &e2) {
		filename[0] = '\0';
		P_ERROR("Cannot render an error page: " << e2.what() << "\n" <<
			e2.backtrace());
	}

	stream << "Could not spawn process for application " << options.appRoot <<
		": " << e.what() << "\n" <<
		"  Error ID: " << errorId << "\n";
	if (filename[0] != '\0') {
		stream << "  Error details saved to: " << filename << "\n";
	}
	stream << "  Message from application: " << appMessage << "\n";
	P_ERROR(stream.str());
}
Пример #14
0
static void *srrd_create_thread(void *targs) /* {{{ */
{
  srrd_create_args_t *args = targs;
  char tmpfile[PATH_MAX];
  int status;

  status = lock_file(args->filename);
  if (status != 0) {
    if (status == EEXIST)
      P_NOTICE("srrd_create_thread: File \"%s\" is already being created.",
               args->filename);
    else
      P_ERROR("srrd_create_thread: Unable to lock file \"%s\".",
              args->filename);
    srrd_create_args_destroy(args);
    return 0;
  }

  snprintf(tmpfile, sizeof(tmpfile), "%s.async", args->filename);

  status = srrd_create(tmpfile, args->pdp_step, args->last_up, args->argc,
                       (void *)args->argv);
  if (status != 0) {
    P_WARNING("srrd_create_thread: srrd_create (%s) returned status %i.",
              args->filename, status);
    unlink(tmpfile);
    unlock_file(args->filename);
    srrd_create_args_destroy(args);
    return 0;
  }

  status = rename(tmpfile, args->filename);
  if (status != 0) {
    P_ERROR("srrd_create_thread: rename (\"%s\", \"%s\") failed: %s", tmpfile,
            args->filename, STRERRNO);
    unlink(tmpfile);
    unlock_file(args->filename);
    srrd_create_args_destroy(args);
    return 0;
  }

  DEBUG("srrd_create_thread: Successfully created RRD file \"%s\".",
        args->filename);

  unlock_file(args->filename);
  srrd_create_args_destroy(args);

  return 0;
} /* }}} void *srrd_create_thread */
Пример #15
0
	void MemoryBufferForQuery::LoadLexicon(istream& ifs){
		string line;
		vector<string> vct;
		vct.reserve(2);
		P_INFO("Loading Lexicon...");
		int nline = 0;
		while(ifs){
			line = "";
			getline(ifs, line);
			split(vct,line,is_any_of(" "),token_compress_on);
			if(vct.size()<2){
				continue;
			}
			size_t lineno = lexical_cast<int>(vct[0]);
			if(lineno < (size_t) nline + 1){
				P_FATAL("Mismatch (duplicate) line number, line (%d) \"%s\"",nline+1, line.c_str());
			}else if(lineno > nline + 1){
				P_ERROR("Mismatch (extra) line number, line (%d) \"%s\"",nline+1, line.c_str());
				while(lexicon.size() < lineno-1){
					lexicon.push_back(string());
				}
			}
			lexicon.push_back(vct[1]);
			dict.insert(DictType::value_type(vct[1],lineno));
			nline = lineno;
		}
		P_INFO("Loaded %d entries in lexicon", nline);
	}
Пример #16
0
void ConfigMapParser::expect(T::Type type) throw(PARSEEXCEPTION_THROW)
{
  if(token.type == type)
    nextToken();
  else
    P_ERROR("Expected `" + T::type2str(type) + "` got `" + T::type2str(token.type) + "`");
}
Пример #17
0
static int mon_close(struct inode *inode, struct file *filp)
{
    int rc, i;
    struct mon_private *monpriv = filp->private_data;

    /*
     * Close IUCV connection and unregister
     */
    rc = iucv_path_sever(monpriv->path, user_data_sever);
    if (rc)
        P_ERROR("close, iucv_sever failed with rc = %i\n", rc);
    else
        P_INFO("close, terminated connection to *MONITOR service\n");

    atomic_set(&monpriv->iucv_severed, 0);
    atomic_set(&monpriv->iucv_connected, 0);
    atomic_set(&monpriv->read_ready, 0);
    atomic_set(&monpriv->msglim_count, 0);
    monpriv->write_index  = 0;
    monpriv->read_index   = 0;

    for (i = 0; i < MON_MSGLIM; i++)
        kfree(monpriv->msg_array[i]);
    kfree(monpriv);
    clear_bit(MON_IN_USE, &mon_in_use);
    return 0;
}
Пример #18
0
static int mon_send_reply(struct mon_msg *monmsg,
              struct mon_private *monpriv)
{
    int rc;

    P_DEBUG("read, REPLY: pathid = 0x%04X, msgid = 0x%08X, trgcls = "
        "0x%08X\n\n",
        monpriv->path->pathid, monmsg->msg.id, monmsg->msg.class);

    rc = iucv_message_reply(monpriv->path, &monmsg->msg,
                IUCV_IPRMDATA, NULL, 0);
    atomic_dec(&monpriv->msglim_count);
    if (likely(!monmsg->msglim_reached)) {
        monmsg->pos = 0;
        monmsg->mca_offset = 0;
        monpriv->read_index = (monpriv->read_index + 1) %
                      MON_MSGLIM;
        atomic_dec(&monpriv->read_ready);
    } else
        monmsg->replied_msglim = 1;
    if (rc) {
        P_ERROR("read, IUCV reply failed with rc = %i\n\n", rc);
        return -EIO;
    }
    return 0;
}
Пример #19
0
P_LIB_API void
p_hash_table_insert (PHashTable *table, ppointer key, ppointer value)
{
	PHashTableNode	*node;
	puint		hash;

	if (P_UNLIKELY (table == NULL))
		return;

	if ((node = pp_hash_table_find_node (table, key)) == NULL) {
		if (P_UNLIKELY ((node = p_malloc0 (sizeof (PHashTableNode))) == NULL)) {
			P_ERROR ("PHashTable::p_hash_table_insert: failed to allocate memory");
			return;
		}

		hash = pp_hash_table_calc_hash (key, table->size);

		/* Insert a new node in front of others */
		node->key   = key;
		node->value = value;
		node->next  = table->table[hash];

		table->table[hash] = node;
	} else
		node->value = value;
}
Пример #20
0
int latency_config(latency_config_t *conf, oconfig_item_t *ci) {
  int status = 0;

  for (int i = 0; i < ci->children_num; i++) {
    oconfig_item_t *child = ci->children + i;

    if (strcasecmp("Percentile", child->key) == 0)
      status = latency_config_add_percentile(conf, child);
    else if (strcasecmp("Bucket", child->key) == 0)
      status = latency_config_add_bucket(conf, child);
    else if (strcasecmp("BucketType", child->key) == 0)
      status = cf_util_get_string(child, &conf->bucket_type);
    else
      P_WARNING("\"%s\" is not a valid option within a \"%s\" block.",
                child->key, ci->key);

    if (status != 0)
      return status;
  }

  if ((status == 0) && (conf->percentile_num == 0) &&
      (conf->buckets_num == 0)) {
    P_ERROR("The \"%s\" block must contain at least one "
            "\"Percentile\" or \"Bucket\" option.",
            ci->key);
    return EINVAL;
  }

  return 0;
}
Пример #21
0
void latency_counter_add(latency_counter_t *lc, cdtime_t latency) /* {{{ */
{
  cdtime_t bin;

  if ((lc == NULL) || (latency == 0) || (latency > ((cdtime_t)LLONG_MAX)))
    return;

  lc->sum += latency;
  lc->num++;

  if ((lc->min == 0) && (lc->max == 0))
    lc->min = lc->max = latency;
  if (lc->min > latency)
    lc->min = latency;
  if (lc->max < latency)
    lc->max = latency;

  /* A latency of _exactly_ 1.0 ms is stored in the buffer 0, so
   * subtract one from the cdtime_t value so that exactly 1.0 ms get sorted
   * accordingly. */
  bin = (latency - 1) / lc->bin_width;
  if (bin >= HISTOGRAM_NUM_BINS) {
    change_bin_width(lc, latency);
    bin = (latency - 1) / lc->bin_width;
    if (bin >= HISTOGRAM_NUM_BINS) {
      P_ERROR("latency_counter_add: Invalid bin: %" PRIu64, bin);
      return;
    }
  }
  lc->histogram[bin]++;
} /* }}} void latency_counter_add */
bool
AsciiProcessor::del_cmd( const char * buf,
                         BuilderBase * build,
                         const char* & next )
{
    int fref;

    if ( ! str2val( buf, fref, next ) )
    {
        P_ERROR( "DEL no frame or object reference" );
        return CMD_ERR;
    }

    buf = next;

    int oref;

    if ( str2val( buf, oref, next ) )
    {
        buf = next;

        if ( ! strskip( buf, DELIMITER_CHAR, next ) )
        {
            P_ERROR( "wrong delimiter char" );
            return CMD_ERR;
        }

        build->set_cmd_remove_object( fref, oref );

        P_MSG( "build->set_cmd_remove_object(fref,oref);" );
        return CMD_OK;
    }

    if ( ! strskip( buf, DELIMITER_CHAR, next ) )
    {
        P_ERROR( "wrong delimiter char" );
        return CMD_ERR;
    }

    build->set_cmd_remove_frame( fref );

    P_MSG( "build->set_cmd_remove_frame(fref);" );

    return CMD_OK;
}
Пример #23
0
static void
pp_shm_clean_handle (PShm *shm)
{
	if (P_UNLIKELY (shm->addr != NULL && UnmapViewOfFile ((char *) shm->addr) == 0))
		P_ERROR ("PShm::pp_shm_clean_handle: UnmapViewOfFile() failed");

	if (P_UNLIKELY (shm->shm_hdl != P_SHM_INVALID_HDL && CloseHandle (shm->shm_hdl) == 0))
		P_ERROR ("PShm::pp_shm_clean_handle: CloseHandle() failed");

	if (P_LIKELY (shm->sem != NULL)) {
		p_semaphore_free (shm->sem);
		shm->sem = NULL;
	}

	shm->shm_hdl = P_SHM_INVALID_HDL;
	shm->addr    = NULL;
	shm->size    = 0;
}
Пример #24
0
P_LIB_API PMutex *
p_mutex_new (void)
{
	PMutex *ret;

	if ((P_UNLIKELY (ret = p_malloc0 (sizeof (PMutex))) == NULL)) {
		P_ERROR ("PMutex::p_mutex_new: failed to allocate memory");
		return NULL;
	}

	if (P_UNLIKELY (mutex_init (&ret->hdl, USYNC_THREAD, NULL) != 0)) {
		P_ERROR ("PMutex::p_mutex_new: mutex_init() failed");
		p_free (ret);
		return NULL;
	}

	return ret;
}
Пример #25
0
P_LIB_API PSpinLock *
p_spinlock_new (void)
{
	PSpinLock *ret;

	if (P_UNLIKELY ((ret = p_malloc0 (sizeof (PSpinLock))) == NULL)) {
		P_ERROR ("PSpinLock::p_spinlock_new: failed to allocate memory");
		return NULL;
	}

	if (P_UNLIKELY ((ret->mutex = p_mutex_new ()) == NULL)) {
		P_ERROR ("PSpinLock::p_spinlock_new: p_mutex_new() failed");
		p_free (ret);
		return NULL;
	}

	return ret;
}
Пример #26
0
P_LIB_API PRWLock *
p_rwlock_new (void)
{
	PRWLock *ret;

	if (P_UNLIKELY ((ret = p_malloc0 (sizeof (PRWLock))) == NULL)) {
		P_ERROR ("PRWLock::p_rwlock_new: failed to allocate memory");
		return NULL;
	}

	if (P_UNLIKELY (rwlock_init (&ret->hdl, USYNC_THREAD, NULL) != 0)) {
		P_ERROR ("PRWLock::p_rwlock_new: rwlock_init() failed");
		p_free (ret);
		return NULL;
	}

	return ret;
}
Пример #27
0
P_LIB_API PCondVariable *
p_cond_variable_new (void)
{
	PCondVariable *ret;

	if (P_UNLIKELY ((ret = p_malloc0 (sizeof (PCondVariable))) == NULL)) {
		P_ERROR ("PCondVariable::p_cond_variable_new: failed to allocate memory");
		return NULL;
	}

	if (P_UNLIKELY (pp_cond_variable_init_func (ret) != TRUE)) {
		P_ERROR ("PCondVariable::p_cond_variable_new: failed to initialize");
		p_free (ret);
		return NULL;
	}

	return ret;
}
Пример #28
0
/******************************************************************************
 *                               file operations                              *
 *****************************************************************************/
static int mon_open(struct inode *inode, struct file *filp)
{
    struct mon_private *monpriv;
    int rc;

    /*
     * only one user allowed
     */
    rc = -EBUSY;
    if (test_and_set_bit(MON_IN_USE, &mon_in_use))
        goto out;

    rc = -ENOMEM;
    monpriv = mon_alloc_mem();
    if (!monpriv)
        goto out_use;

    /*
     * Connect to *MONITOR service
     */
    monpriv->path = iucv_path_alloc(MON_MSGLIM, IUCV_IPRMDATA, GFP_KERNEL);
    if (!monpriv->path)
        goto out_priv;
    rc = iucv_path_connect(monpriv->path, &monreader_iucv_handler,
                   MON_SERVICE, NULL, user_data_connect, monpriv);
    if (rc) {
        P_ERROR("iucv connection to *MONITOR failed with "
            "IPUSER SEVER code = %i\n", rc);
        rc = -EIO;
        goto out_path;
    }
    /*
     * Wait for connection confirmation
     */
    wait_event(mon_conn_wait_queue,
           atomic_read(&monpriv->iucv_connected) ||
           atomic_read(&monpriv->iucv_severed));
    if (atomic_read(&monpriv->iucv_severed)) {
        atomic_set(&monpriv->iucv_severed, 0);
        atomic_set(&monpriv->iucv_connected, 0);
        rc = -EIO;
        goto out_path;
    }
    P_INFO("open, established connection to *MONITOR service\n\n");
    filp->private_data = monpriv;
    return nonseekable_open(inode, filp);

out_path:
    kfree(monpriv->path);
out_priv:
    mon_free_mem(monpriv);
out_use:
    clear_bit(MON_IN_USE, &mon_in_use);
out:
    return rc;
}
Пример #29
0
static void mon_iucv_path_severed(struct iucv_path *path, u8 ipuser[16])
{
    struct mon_private *monpriv = path->private;

    P_ERROR("IUCV connection severed with rc = 0x%X\n", ipuser[0]);
    iucv_path_sever(path, NULL);
    atomic_set(&monpriv->iucv_severed, 1);
    wake_up(&mon_conn_wait_queue);
    wake_up_interruptible(&mon_read_wait_queue);
}
Пример #30
0
static srrd_create_args_t *srrd_create_args_create(const char *filename,
                                                   unsigned long pdp_step,
                                                   time_t last_up, int argc,
                                                   const char **argv) {
  srrd_create_args_t *args;

  args = calloc(1, sizeof(*args));
  if (args == NULL) {
    P_ERROR("srrd_create_args_create: calloc failed.");
    return NULL;
  }
  args->filename = NULL;
  args->pdp_step = pdp_step;
  args->last_up = last_up;
  args->argv = NULL;

  args->filename = strdup(filename);
  if (args->filename == NULL) {
    P_ERROR("srrd_create_args_create: strdup failed.");
    srrd_create_args_destroy(args);
    return NULL;
  }

  args->argv = calloc((size_t)(argc + 1), sizeof(*args->argv));
  if (args->argv == NULL) {
    P_ERROR("srrd_create_args_create: calloc failed.");
    srrd_create_args_destroy(args);
    return NULL;
  }

  for (args->argc = 0; args->argc < argc; args->argc++) {
    args->argv[args->argc] = strdup(argv[args->argc]);
    if (args->argv[args->argc] == NULL) {
      P_ERROR("srrd_create_args_create: strdup failed.");
      srrd_create_args_destroy(args);
      return NULL;
    }
  }
  assert(args->argc == argc);
  args->argv[args->argc] = NULL;

  return args;
} /* srrd_create_args_t *srrd_create_args_create */