コード例 #1
0
/*
 * check if a found kernel is the one we are running atm
 */
static boolean_t is_current_kernel(void *kernel_header) {
	// search backwards for the kernel base address (mach-o header)
	mach_vm_address_t kernel_base = find_kernel_base();
	
	uint64_t *uuid1 = get_uuid(kernel_header);
	uint64_t *uuid2 = get_uuid((void*)kernel_base);
	
	if(!uuid1 || !uuid2) {
		return FALSE;
	}
	
	return uuid1[0] == uuid2[0] && uuid1[1] == uuid2[1];
}
コード例 #2
0
ファイル: nativedisk.c プロジェクト: 376473984/TrustedGRUB2
static int
iterate_device (const char *name, void *data)
{
  struct search_ctx *ctx = data;
  char *cur_uuid;

  if (get_uuid (name, &cur_uuid, 1))
    {
      if (grub_errno == GRUB_ERR_UNKNOWN_FS)
	grub_errno = 0;
      grub_print_error ();
      return 0;
    }

  grub_dprintf ("nativedisk", "checking %s: %s\n", name,
		cur_uuid);
  if (ctx->prefix_uuid && grub_strcasecmp (cur_uuid, ctx->prefix_uuid) == 0)
    {
      char *prefix;
      prefix = grub_xasprintf ("(%s)/%s", name, ctx->prefix_path);
      grub_env_set ("prefix", prefix);
      grub_free (prefix);
      ctx->prefix_found = 1;
    }
  if (ctx->root_uuid && grub_strcasecmp (cur_uuid, ctx->root_uuid) == 0)
    {
      grub_env_set ("root", name);
      ctx->root_found = 1;
    }
  return ctx->prefix_found && ctx->root_found;
}
コード例 #3
0
int add_ptn(struct ptable *ptbl, u64 first, u64 last, const char *name)
{
	struct efi_header *hdr = &ptbl->header;
	struct efi_entry *entry = ptbl->entry;
	unsigned n;

	if (first < 34) {
		fprintf(stderr,"partition '%s' overlaps partition table\n", name);
		return -1;
	}

	if (last > hdr->last_lba) {
		fprintf(stderr,"partition '%s' does not fit on disk\n", name);
		return -1;
	}
	for (n = 0; n < EFI_ENTRIES; n++, entry++) {
		if (entry->type_uuid[0])
			continue;
		memcpy(entry->type_uuid, partition_type_uuid, 16);
		get_uuid(entry->uniq_uuid);
		entry->first_lba = first;
		entry->last_lba = last;
		for (n = 0; (n < EFI_NAMELEN) && *name; n++)
			entry->name[n] = *name++;
		return 0;
	}
	fprintf(stderr,"out of partition table entries\n");
	return -1;
}
コード例 #4
0
ファイル: att.c プロジェクト: stefboerrigter/libgatt
uint16_t dec_read_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start,
						uint16_t *end, bt_uuid_t *uuid)
{
	const size_t min_len = sizeof(pdu[0]) + sizeof(*start) + sizeof(*end);
	uint8_t type;

	if (pdu == NULL)
		return 0;

	if (start == NULL || end == NULL || uuid == NULL)
		return 0;

	if (len == (min_len + 2))
		type = BT_UUID16;
	else if (len == (min_len + 16))
		type = BT_UUID128;
	else
		return 0;

	if (pdu[0] != ATT_OP_READ_BY_TYPE_REQ)
		return 0;

	*start = get_le16(&pdu[1]);
	*end = get_le16(&pdu[3]);

	get_uuid(type, &pdu[5], uuid);

	return len;
}
コード例 #5
0
ファイル: uuid.c プロジェクト: taysom/tau
int main(int argc, char *argv[]) {
	uuid_t a, b, c;
	char buf[100];
	char in[100];
	char out[100];
	int x,y;

#ifdef __APPLE__
	uuid_generate(a);
	uuid_generate(b);
#else
	uuid_generate_time_safe(a);
	uuid_generate_time_safe(b);
#endif
	uuid_unparse(a, buf);
	printf("%s\n", buf);
	pr_uuid(a);
	uuid_unparse(b, buf);
	printf("%s\n", buf);
	pr_uuid(b);
	snprintf(in, sizeof(in), "XYZZY.%s:%d:%d", buf, 3, 4);
	printf("%s\n", in);
	get_uuid(&in[6], c);
	sscanf(&in[42], ":%d:%d", &x, &y);
	uuid_unparse(c, out);
	printf("%s:%d:%d\n", out, x, y);

	uuid_unparse(a, buf);
	snprintf(in, sizeof(in), "XYZZY.%s", buf);
	sscanf(in, "XYZZY.%s", out);
	if (strcmp(buf, out) != 0) {
		printf("Error %s != %s\n", buf, out);
	}
	return 0;
}
コード例 #6
0
ファイル: network.c プロジェクト: aaronorosen/sos-agent
int get_uuid_and_confirm_client(agent_t *agent, int fd) 
{
   client_t * new_client; 
   struct client_hash_struct *client_hash;
   uuid_t uuid;
   
   get_uuid(agent->agent_fd_pool[fd], &uuid); 
     
   HASH_FIND_INT(agent->clients_hashes, uuid, client_hash); 

   if(client_hash == NULL) 
   {
 	   new_client = init_new_client(agent, &uuid); 
      new_client->agent_sock[new_client->num_parallel_connections] = 
         agent->agent_fd_pool[fd]; 
      new_client->agent_fd_poll[new_client->num_parallel_connections] = IN; 
      new_client->num_parallel_connections++; 

		if(check_for_transfer_request(agent, new_client, "AGENT")) {  
      	connect_host_side(agent, new_client); 
		}else { 
#ifdef DEBUG
         printf("DID NOT FIND!\n");  
#endif
      } 
      new_client->host_fd_poll  = OFF; 

   } 
   else 
   { 
      client_hash->client->agent_sock[client_hash->client->num_parallel_connections] = 
         agent->agent_fd_pool[fd]; 

      client_hash->client->agent_fd_poll[client_hash->client->num_parallel_connections] = IN; 
      client_hash->client->num_parallel_connections++; 
  
     if(client_hash->client->allowed_connections && client_hash->client->num_parallel_connections == client_hash->client->allowed_connections 
         && client_hash->client->host_fd_poll == IN)
     {
       client_hash->accept_start.tv_sec -=  TIMEOUT; 
     }
   }

 

   if(epoll_ctl(agent->event_pool, EPOLL_CTL_DEL, 
     agent->agent_fd_pool[fd], NULL)) 
   {
      perror("");
		printf("%s %d\n", __FILE__, __LINE__); 
		exit(1); 
   }

   agent->agent_fd_pool[fd] = EMPTY;  

   return EXIT_SUCCESS; 
}
コード例 #7
0
ファイル: election.c プロジェクト: dubrsl/pacemaker
/*	 A_DC_TAKEOVER	*/
void
do_dc_takeover(long long action,
               enum crmd_fsa_cause cause,
               enum crmd_fsa_state cur_state,
               enum crmd_fsa_input current_input, fsa_data_t * msg_data)
{
    int rc = pcmk_ok;
    xmlNode *cib = NULL;
    GListPtr gIter = NULL;
    const char *cluster_type = name_for_cluster_type(get_cluster_type());

    crm_info("Taking over DC status for this partition");
    set_bit(fsa_input_register, R_THE_DC);

    for (gIter = stonith_cleanup_list; gIter != NULL; gIter = gIter->next) {
        char *target = gIter->data;
        const char *uuid = get_uuid(target);

        crm_notice("Marking %s, target of a previous stonith action, as clean", target);
        send_stonith_update(NULL, target, uuid);
        free(target);
    }
    g_list_free(stonith_cleanup_list);
    stonith_cleanup_list = NULL;

#if SUPPORT_COROSYNC
    if (is_classic_ais_cluster()) {
        send_ais_text(crm_class_quorum, NULL, TRUE, NULL, crm_msg_ais);
    }
#endif

    if (voted != NULL) {
        crm_trace("Destroying voted hash");
        g_hash_table_destroy(voted);
        voted = NULL;
    }

    set_bit(fsa_input_register, R_JOIN_OK);
    set_bit(fsa_input_register, R_INVOKE_PE);

    fsa_cib_conn->cmds->set_master(fsa_cib_conn, cib_scope_local);

    cib = create_xml_node(NULL, XML_TAG_CIB);
    crm_xml_add(cib, XML_ATTR_CRM_VERSION, CRM_FEATURE_SET);
    fsa_cib_update(XML_TAG_CIB, cib, cib_quorum_override, rc, NULL);
    fsa_register_cib_callback(rc, FALSE, NULL, feature_update_callback);

    update_attr_delegate(fsa_cib_conn, cib_none, XML_CIB_TAG_CRMCONFIG, NULL, NULL, NULL, NULL,
                         "dc-version", VERSION "-" BUILD_VERSION, FALSE, NULL);

    update_attr_delegate(fsa_cib_conn, cib_none, XML_CIB_TAG_CRMCONFIG, NULL, NULL, NULL, NULL,
                         "cluster-infrastructure", cluster_type, FALSE, NULL);

    mainloop_set_trigger(config_read);
    free_xml(cib);
}
コード例 #8
0
ファイル: nm-conf.c プロジェクト: prusso/ubiquity
/* Get info for the connection setting for wired networks. */
void nm_get_wired_connection(nm_connection *connection)
{
    /* This is the first wired connection. */
    snprintf(connection->id, NM_MAX_LEN_ID, NM_DEFAULT_WIRED_NAME);

    /* Generate uuid. */
    get_uuid(connection->uuid);

    connection->type = WIRED;
}
コード例 #9
0
ファイル: nm-conf.c プロジェクト: prusso/ubiquity
void nm_get_wireless_connection(struct netcfg_interface *niface, nm_connection *connection)
{
    /* Use the wireless network name for connection id. */
    snprintf(connection->id, NM_MAX_LEN_ID, "%s", niface->essid);

    /* Generate uuid. */
    get_uuid(connection->uuid);

    connection->type = WIFI;
}
コード例 #10
0
ファイル: upnp.c プロジェクト: michal42/wphoto
static int ping_camera(const char *url)
{
	const char *cp;
	char *url2, *p;
	static const char *uuid;
	static size_t uuid_len;
	static const char path[] = "/desc_iml/MobileConnectedCamera.xml?uuid=";
	size_t base_len, len;
	char *outbuf, contenttype[LINE_SIZE];
	int err;

	/* Find the http://host:port part of the url */
	cp = strstr(url, "://");
	if (!cp) {
		fprintf(stderr, "Invalid device URL: %s\n", url);
		abort();
		return -1;
	}
	cp += 3;
	cp = strchr(cp, '/');
	if (!cp)
		cp = url + strlen(url);
	base_len = cp - url;
	if (base_len > 1024) {
		fprintf(stderr, "Device URL too long: %s\n", url);
		return -1;
	}
	if (!uuid) {
		uuid = get_uuid();
		uuid_len = strlen(uuid);
	}
	/* paste baseurl + path + uuid */
	len = base_len + sizeof(path) - 1 + uuid_len;
	url2 = malloc(len + 1);
	if (!url2) {
		perror("Memory allocation failure");
		return -1;
	}
	url2[len] = '\0';
	memcpy(url2, url, cp - url);
	p = url2 + (cp - url);
	memcpy(p, path, sizeof(path) - 1);
	p += sizeof(path) - 1;
	memcpy(p, uuid, uuid_len);
	fprintf(stderr, "url2: \"%s\"\n", url2);
	outbuf = NULL;
	err = UpnpDownloadUrlItem(url2, &outbuf, contenttype);
	/* FIXME: Check that the XML contains what we expect */
	free(outbuf);
	if (err)
		upnp_perror("UpnpDownloadUrlItem", err);
	return err;
}
コード例 #11
0
ファイル: t_uuid.c プロジェクト: xl0/iperf3
int
main(int argc, char **argv)
{
    char     uuid[37];
    get_uuid(uuid);
    if (strlen(uuid) != 36)
    {
	printf("uuid is not 37 characters long %s.\n", uuid);
	exit(-1);
    }
    exit(0);
}
コード例 #12
0
static qeo_platform_device_id qeo_get_device_uuid(const char* platform_storage_filepath, const char* generator_path)
{
    FILE* file = NULL;
    char* result_uuid = NULL;

    do {
        file = fopen(platform_storage_filepath, "r");
        if (file != NULL ) {
            fclose(file);
            qeo_log_i("Fetching the existing UUID");
            result_uuid = get_uuid(platform_storage_filepath);
            break;
        }

        qeo_log_i("Creating a new UUID, because %s not found", platform_storage_filepath);

        result_uuid = get_uuid(generator_path);
        if (NULL == result_uuid) {
            qeo_log_e("Failed to get UUID");
            break;
        }

        FILE* fp = fopen(platform_storage_filepath, "w");

        if (fp != NULL ) {
            qeo_log_i("Writing the new UUID");
            fprintf(fp, "%s", result_uuid);
            fclose(fp);
        }
        else {
            qeo_log_e("Failed to open %s", platform_storage_filepath);
        }
    } while (0);

    qeo_platform_device_id res = char_to_struct(result_uuid);

    free(result_uuid);

    return res;
}
コード例 #13
0
ファイル: coolsms.c プロジェクト: coolsms/c-sdk
user_opt user_opt_init(char *api_key, char *api_secret)
{
	user_opt user_info;
	char * uuid;
	strcpy(user_info.api_key, api_key);
	strcpy(user_info.api_secret, api_secret);
	get_timestamp(user_info.timestamp);
	uuid = get_uuid();
	strcpy(user_info.salt, uuid);
	get_signature(user_info.timestamp, user_info.salt, user_info.api_secret, user_info.signature);
	free(uuid);
	return user_info;
}
コード例 #14
0
QVariantMap CalaosWidget::toVariantMap() const
{
    QVariantMap m;

    m["module"] = get_module();
    m["uuid"] = get_uuid();
    m["x"] = get_posX();
    m["y"] = get_posY();
    m["width"] = get_width();
    m["height"] = get_height();
    m["config"] = moduleConfig;

    return m;
}
コード例 #15
0
ファイル: tree_stabilizer.hpp プロジェクト: 01org/intelRSD
 const Uuid stabilize_single_resource(const Uuid& resource_temporary_uuid,
                                      module::GenericManager<T>& manager,
                                      const std::string& unique_key) const {
     Uuid resource_persistent_uuid{};
     {
         auto resource = manager.get_entry_reference(resource_temporary_uuid);
         resource->set_unique_key(unique_key);
         resource->make_persistent_uuid();
         resource_persistent_uuid = resource->get_uuid();
     }
     log_persistent_uuid_generated(T::get_component().to_string(),
                                   resource_temporary_uuid,
                                   resource_persistent_uuid);
     return resource_persistent_uuid;
 }
コード例 #16
0
ファイル: math.C プロジェクト: viatsko/parser3
static void _uuid(Request& r, MethodParams& /*params*/) {
	uuid uuid=get_uuid();

	const size_t bufsize=36+1/*zero-teminator*/+1/*for faulty snprintfs*/;
	char* cstr=new(PointerFreeGC) char[bufsize];

	snprintf(cstr, bufsize,
			"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
			uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
			uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
			uuid.node[0], uuid.node[1], uuid.node[2],
			uuid.node[3], uuid.node[4], uuid.node[5]);

	r.write_pass_lang(*new String(cstr));
}
コード例 #17
0
ファイル: identifiable.cpp プロジェクト: amireh/libalgol
  void identifiable::__set_uuid(uuid_t uuid)
  {
    if (uuid_ != "0")
    {
      string_t msg =
        "Attempting to re-assign an object's UUID after it's been set! Object: "
        + uuid_;
      throw integrity_violation(msg);
    }

    uuid_ = uuid;

    on_uuid_set();

    for (identifiable* child : children_)
      child->__set_uuid(get_uuid());
  }
コード例 #18
0
ファイル: rb-rack-io.c プロジェクト: boazsegev/iodine
static VALUE rio_get_io(int argc, VALUE *argv, VALUE self) {
  if (TCPSOCKET_CLASS == Qnil)
    return Qfalse;
  intptr_t fduuid = get_uuid(self);
  // hijack the IO object
  VALUE fd = INT2FIX(sock_uuid2fd(fduuid));
  VALUE env = rb_ivar_get(self, env_id);
  // make sure we're not repeating ourselves
  VALUE new_io = rb_hash_aref(env, R_HIJACK_IO);
  if (new_io != Qnil)
    return new_io;
  // VALUE new_io = how the f**k do we create a new IO from the fd?
  new_io = RubyCaller.call2(TCPSOCKET_CLASS, for_fd_id, 1,
                            &fd); // TCPSocket.for_fd(fd) ... cool...
  rb_hash_aset(env, R_HIJACK_IO, new_io);
  if (argc)
    rb_hash_aset(env, R_HIJACK_CB, *argv);
  return new_io;
}
コード例 #19
0
ファイル: acl_bind.cpp プロジェクト: 01org/intelRSD
void endpoint::AclBind<true>::post(const server::Request& request, server::Response& response) {
    static const constexpr char TRANSACTION_NAME[] = "PostAclBind";

    const auto json = JsonValidator::validate_request_body<schema::AclPostSchema>(request);
    const auto acl_port_pair = get_acl_and_port_uuid(request, json);

    if (NetworkComponents::get_instance()->get_acl_port_manager().entry_exists(acl_port_pair.first,
                                                                               acl_port_pair.second)) {
        THROW(agent_framework::exceptions::InvalidValue, "rest",
              "Port " + std::to_string(
                  NetworkComponents::get_instance()->get_port_manager().uuid_to_rest_id(acl_port_pair.second))
              + " is already bound to ACL " + request.params[PathParam::ACL_ID]);
    }

    const requests::AddAclPort add_acl_port_request{
        acl_port_pair.first,
        attribute::Array<std::string>(std::vector<std::string>{acl_port_pair.second}),
        attribute::Oem()
    };

    const auto parent_switch =
        model::find<agent_framework::model::EthernetSwitch>(request.params).get();
    const auto agent_id = parent_switch.get_agent_id();
    const auto& gami_agent = psme::core::agent::AgentManager::get_instance()->get_agent(agent_id);

    auto add_acl_port = [&, gami_agent] {
        const auto add_acl_port_response = gami_agent->execute<responses::AddAclPort>(add_acl_port_request);

        model::handler::HandlerManager::get_instance()->
            get_handler(enums::Component::Acl)->
            load(gami_agent, parent_switch.get_uuid(),
                 enums::Component::EthernetSwitch, acl_port_pair.first, true);

        NetworkComponents::get_instance()->get_acl_port_manager().add_entry(acl_port_pair.first, acl_port_pair.second,
                                                                            agent_id);
        response.set_status(server::status_2XX::NO_CONTENT);
    };

    gami_agent->execute_in_transaction(TRANSACTION_NAME, add_acl_port);
}
コード例 #20
0
crm_node_t *crm_update_ccm_node(
    const oc_ev_membership_t *oc, int offset, const char *state, uint64_t seq)
{
    crm_node_t *node = NULL;
    const char *uuid = NULL;
    CRM_CHECK(oc->m_array[offset].node_uname != NULL, return NULL);
    uuid = get_uuid(oc->m_array[offset].node_uname);
    node = crm_update_peer(oc->m_array[offset].node_id,
			   oc->m_array[offset].node_born_on, seq, -1, 0,
			   uuid, oc->m_array[offset].node_uname, NULL, state);

    if(safe_str_eq(CRM_NODE_ACTIVE, state)) {
	/* Heartbeat doesn't send status notifications for nodes that were already part of the cluster */
	crm_update_peer_proc(
	    oc->m_array[offset].node_uname, crm_proc_ais, ONLINESTATUS);

	/* Nor does it send status notifications for processes that were already active */
	crm_update_peer_proc(
	   oc->m_array[offset].node_uname, crm_proc_crmd, ONLINESTATUS);
    }
    return node;
}
コード例 #21
0
ファイル: formatdisk.c プロジェクト: frugalware/setup
int mountdev(char *dev, char *mountpoint, GList **config)
{
	char *type=NULL;
	char *tmp=NULL;
	FILE* fp;

	// open fstab
	if ((fp = fopen((char*)data_get(*config, "fstab"), "a")) == NULL)
	{
		perror(_("Could not open output file for writing"));
		return(-1);
	}

	// mount
	tmp = g_strdup_printf("%s/%s", TARGETDIR, mountpoint);
	makepath(tmp);
	FREE(tmp);

	umount_if_needed(mountpoint);
	tmp = g_strdup_printf("mount %s %s/%s",
			dev, TARGETDIR, mountpoint);
	fw_system(tmp);
	FREE(tmp);
	// unlink a possible stale lockfile
	tmp = g_strdup_printf("%s/%s/tmp/pacman-g2.lck", TARGETDIR, mountpoint);
	unlink(tmp);
	FREE(tmp);

	// make fstab entry
	type = findmount(dev, 0);
	char *uuid = get_uuid(dev);
	fprintf(fp, "%-16s %-16s %-11s %-16s %-3s %s\n", uuid, mountpoint,
		type, "defaults", "1", "1");
	free(uuid);
	free(type);
	fclose(fp);
	return(0);
}
コード例 #22
0
ファイル: metrics.hpp プロジェクト: 01org/intelRSD
void build_metrics(const std::string& resource_uuid, const DiscoveryContext& dc, const DiscoveryParams<TYPE>&) {
    const auto resource = agent_framework::module::get_manager<ModelType<TYPE>>()
        .get_entry(resource_uuid);
    const auto resource_key = ::telemetry::get_resource_key(resource);
    for (auto& resource_sensor : dc.telemetry_service->get_resource_sensors()) {
        if (resource_sensor->get_resource() == resource_key) {

            auto& definition = resource_sensor->get_definition();
            if (!definition.has_persistent_uuid()) {
                telemetry::stabilize(definition, definition.to_json().dump());
            }
            telemetry::add(definition, dc.event_collector);

            agent_framework::model::Metric metric;
            metric.set_component_uuid(resource.get_uuid());
            metric.set_component_type(resource.get_component());
            metric.set_metric_definition_uuid(definition.get_uuid());
            metric.set_name(definition.get_metric_jsonptr());
            telemetry::stabilize(metric, static_cast<const agent_framework::model::Resource&>(resource));
            telemetry::add(metric, dc.event_collector);
        }
    }
}
コード例 #23
0
ファイル: formatdisk.c プロジェクト: frugalware/setup
int doswap(GList *partlist, GList **config)
{
	char *fn, *item, *ptr;
	FILE* fp;
	int i;

	// create an initial fstab
	fn = strdup("/tmp/setup_XXXXXX");
	mkstemp(fn);
	if ((fp = fopen(fn, "wb")) == NULL)
	{
		perror(_("Could not open output file for writing"));
		FREE(fn);
		return(-1);
	}
	fprintf(fp, "%-16s %-16s %-11s %-16s %-3s %s\n",
		"none", "/proc", "proc", "defaults", "0", "0");
	fprintf(fp, "%-16s %-16s %-11s %-16s %-3s %s\n",
		"none", "/sys", "sysfs", "defaults", "0", "0");
	fprintf(fp, "%-16s %-16s %-11s %-16s %-3s %s\n",
		"devpts", "/dev/pts", "devpts", "gid=5,mode=620", "0", "0");
	fprintf(fp, "%-16s %-16s %-11s %-16s %-3s %s\n",
		"usbfs", "/proc/bus/usb", "usbfs", "devgid=23,devmode=664", "0", "0");
	fprintf(fp, "%-16s %-16s %-11s %-16s %-3s %s\n",
		"tmpfs", "/dev/shm", "tmpfs", "defaults", "0", "0");

	// format the partitions
	for (i=0; i<g_list_length(partlist); i++)
	{
		char *tmp;
		dialog_vars.input_result[0]='\0';
		item = strdup((char*)g_list_nth_data(partlist, i));
		ptr = selmkswapmode(item);
		if(ptr == NULL)
			return(-1);
		if(!strcmp("format", ptr))
		{
			tmp = g_strdup_printf(_("Formatting %s as a swap "
						"partition"), item);
			fw_info(_("Formatting swap partition"), tmp);
			FREE(tmp);
			tmp = g_strdup_printf("%s %s", MKSWAP, item);
			fw_system(tmp);
			FREE(tmp);
		}
		else if (!strcmp("check", ptr))
		{
			tmp = g_strdup_printf(_("Formatting %s as a swap "
						"partition and checking for bad blocks"), item);
			fw_info(_("Formatting swap partition"), tmp);
			FREE(tmp);
			tmp = g_strdup_printf("%s -c %s", MKSWAP, item);
			fw_system(tmp);
			FREE(tmp);
		}
		ptr = g_strdup_printf("%s %s", SWAPON, item);
		fw_system(ptr);
		FREE(ptr);
		char *uuid = get_uuid(item);
		fprintf(fp, "%-16s %-16s %-11s %-16s %-3s %s\n",
			uuid, "swap", "swap", "defaults", "0", "0");
		free(uuid);
	}

	fclose(fp);

	// save fstab location for later
	data_put(config, "fstab", fn);
	// re-detect parts so that new swap partitions will recognized as swap
	// partitions
	detect_parts(0);
	return(0);
}
コード例 #24
0
ファイル: te_utils.c プロジェクト: satoyoshi/pacemaker
static void
tengine_stonith_notify(stonith_t * st, stonith_event_t * st_event)
{
    static char *client_id = NULL;
    if(client_id == NULL) {
        client_id = g_strdup_printf("%s.%d", crm_system_name, getpid());
    }

    if (st_event == NULL) {
        crm_err("Notify data not found");
        return;
    }

    if (st_event->result == pcmk_ok && crm_str_eq(st_event->target, fsa_our_uname, TRUE)) {
        crm_err("We were alegedly just fenced by %s for %s!", st_event->executioner,
                st_event->origin);
        register_fsa_error_adv(C_FSA_INTERNAL, I_ERROR, NULL, NULL, __FUNCTION__);
        return;
    }

    if (st_event->result == pcmk_ok &&
        safe_str_eq(st_event->operation, T_STONITH_NOTIFY_FENCE)) {
        reset_st_fail_count(st_event->target);
    }

    crm_notice("Peer %s was%s terminated (%s) by %s for %s: %s (ref=%s) by client %s",
               st_event->target, st_event->result == pcmk_ok ? "" : " not",
               st_event->action,
               st_event->executioner ? st_event->executioner : "<anyone>",
               st_event->origin, pcmk_strerror(st_event->result), st_event->id,
               st_event->client_origin ? st_event->client_origin : "<unknown>");

#if SUPPORT_CMAN
    if (st_event->result == pcmk_ok && is_cman_cluster()) {
        int local_rc = 0;
        char *target_copy = strdup(st_event->target);

        /* In case fenced hasn't noticed yet
         *
         * Any fencing that has been inititated will be completed by way of the fence_pcmk redirect
         */
        local_rc = fenced_external(target_copy);
        if (local_rc != 0) {
            crm_err("Could not notify CMAN that '%s' is now fenced: %d", st_event->target,
                    local_rc);
        } else {
            crm_notice("Notified CMAN that '%s' is now fenced", st_event->target);
        }
        free(target_copy);
    }
#endif

     if (st_event->result == pcmk_ok) {
         const char *uuid = get_uuid(st_event->target);
        gboolean we_are_executioner = safe_str_eq(st_event->executioner, fsa_our_uname);

        crm_trace("target=%s dc=%s", st_event->target, fsa_our_dc);
        if(AM_I_DC) {
            /* The DC always sends updates */
            send_stonith_update(NULL, st_event->target, uuid);

            if (st_event->client_origin && safe_str_neq(st_event->client_origin, client_id)) {

                /* Abort the current transition graph if it wasn't us
                 * that invoked stonith to fence someone
                 */
                crm_info("External fencing operation from %s fenced %s", st_event->client_origin, st_event->target);
                abort_transition(INFINITY, tg_restart, "External Fencing Operation", NULL);
            }

            /* Assume it was our leader if we dont currently have one */
        } else if (fsa_our_dc == NULL || safe_str_eq(fsa_our_dc, st_event->target)) {
            crm_notice("Target %s our leader %s (recorded: %s)",
                       fsa_our_dc ? "was" : "may have been", st_event->target,
                       fsa_our_dc ? fsa_our_dc : "<unset>");

            /* Given the CIB resyncing that occurs around elections,
             * have one node update the CIB now and, if the new DC is different,
             * have them do so too after the election
             */
            if (we_are_executioner) {
                send_stonith_update(NULL, st_event->target, uuid);
            }
            stonith_cleanup_list = g_list_append(stonith_cleanup_list, strdup(st_event->target));

        }
     }
}
コード例 #25
0
ファイル: swapoff.c プロジェクト: ArakniD/util-linux
int main(int argc, char *argv[])
{
	int status = 0, c;
	size_t i;

	static const struct option long_opts[] = {
		{ "all", 0, 0, 'a' },
		{ "help", 0, 0, 'h' },
		{ "verbose", 0, 0, 'v' },
		{ "version", 0, 0, 'V' },
		{ NULL, 0, 0, 0 }
	};

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	atexit(close_stdout);

	while ((c = getopt_long(argc, argv, "ahvVL:U:",
				 long_opts, NULL)) != -1) {
		switch (c) {
		case 'a':		/* all */
			++all;
			break;
		case 'h':		/* help */
			usage(stdout);
			break;
		case 'v':		/* be chatty */
			++verbose;
			break;
		case 'V':		/* version */
			printf(UTIL_LINUX_VERSION);
			return EXIT_SUCCESS;
		case 'L':
			add_label(optarg);
			break;
		case 'U':
			add_uuid(optarg);
			break;
		case '?':
		default:
			usage(stderr);
		}
	}
	argv += optind;

	if (!all && !numof_labels() && !numof_uuids() && *argv == NULL)
		usage(stderr);

	mnt_init_debug(0);
	mntcache = mnt_new_cache();

	for (i = 0; i < numof_labels(); i++)
		status |= swapoff_by("LABEL", get_label(i), !QUIET);

	for (i = 0; i < numof_uuids(); i++)
		status |= swapoff_by("UUID", get_uuid(i), !QUIET);

	while (*argv != NULL)
		status |= do_swapoff(*argv++, !QUIET, !CANONIC);

	if (all)
		status |= swapoff_all();

	free_tables();
	mnt_unref_cache(mntcache);

	return status;
}
コード例 #26
0
int smpd_dbs_create(char *name)
{
    /*char guid_str[100];*/
    smpd_database_node_t *pNode, *pNodeTest;

    smpd_enter_fn(FCNAME);

#ifdef USE_WIN_MUTEX_PROTECT
    /* Lock */
    WaitForSingleObject(smpd_process.hDBSMutex, INFINITE);
#endif

    pNode = smpd_process.pDatabase;
    if (pNode)
    {
	while (pNode->pNext)
	    pNode = pNode->pNext;
	pNode->pNext = (smpd_database_node_t*)MPIU_Malloc(sizeof(smpd_database_node_t));
	pNode = pNode->pNext;
    }
    else
    {
	smpd_process.pDatabase = (smpd_database_node_t*)MPIU_Malloc(sizeof(smpd_database_node_t));
	pNode = smpd_process.pDatabase;
    }
    pNode->pNext = NULL;
    pNode->pData = NULL;
    pNode->pIter = NULL;
    do
    {
	/*
	sprintf(pNode->pszName, "%d", smpd_process.nNextAvailableDBSID);
	smpd_process.nNextAvailableDBSID++;
	*/
	get_uuid(pNode->pszName);
	if (pNode->pszName[0] == '\0')
	{
#ifdef USE_WIN_MUTEX_PROTECT
	    /* Unlock */
	    ReleaseMutex(smpd_process.hDBSMutex);
#endif
	    smpd_exit_fn(FCNAME);
	    return SMPD_DBS_FAIL;
	}
	pNodeTest = smpd_process.pDatabase;
	while (strcmp(pNodeTest->pszName, pNode->pszName) != 0)
	    pNodeTest = pNodeTest->pNext;
    } while (pNodeTest != pNode);
    strcpy(name, pNode->pszName);

#ifdef USE_WIN_MUTEX_PROTECT
    /* Unlock */
    ReleaseMutex(smpd_process.hDBSMutex);
#endif

    /* put a unique id in the kvs database */
    /*
    get_uuid(guid_str);
    smpd_dbs_put(name, PMI_KVS_ID_KEY, guid_str);
    */

    smpd_exit_fn(FCNAME);
    return SMPD_DBS_SUCCESS;
}
コード例 #27
0
int main(int argc, char **argv)
{
	struct ptable ptbl;
	struct efi_entry *entry;
	struct efi_header *hdr = &ptbl.header;
	struct stat s;
	u32 n;
	u64 sz, blk;
	int fd;
	const char *device;
	int real_disk = 0;

	if (argc < 2)
		return usage();

	if (!strcmp(argv[1], "write")) {
		if (argc < 3)
			return usage();
		device = argv[2];
		argc -= 2;
		argv += 2;
		real_disk = 1;
	} else if (!strcmp(argv[1], "test")) {
		argc -= 1;
		argv += 1;
		real_disk = 0;
		sz = 2097152 * 16;
		fprintf(stderr,"< simulating 16GB disk >\n\n");
	} else {
		return usage();
	}

	if (real_disk) {
		if (!strcmp(device, "/dev/sda") || 
		    !strcmp(device, "/dev/sdb")) {
			fprintf(stderr,"error: refusing to partition sda or sdb\n");
			return -1;
		}
		
		fd = open(device, O_RDWR);
		if (fd < 0) {
			fprintf(stderr,"error: cannot open '%s'\n", device);
			return -1;
		}
		if (ioctl(fd, BLKGETSIZE64, &sz)) {
			fprintf(stderr,"error: cannot query block device size\n");
			return -1;
		}
		sz /= 512;
		fprintf(stderr,"blocks %lld\n", sz);
	}

	memset(&ptbl, 0, sizeof(ptbl));

	init_mbr(ptbl.mbr, sz - 1);

	memcpy(hdr->magic, EFI_MAGIC, sizeof(hdr->magic));
	hdr->version = EFI_VERSION;
	hdr->header_sz = sizeof(struct efi_header);
	hdr->header_lba = 1;
	hdr->backup_lba = sz - 1;
	hdr->first_lba = 34;
	hdr->last_lba = sz - 1;
	get_uuid(hdr->volume_uuid);
	hdr->entries_lba = 2;
	hdr->entries_count = 128;
	hdr->entries_size = sizeof(struct efi_entry);

	while (argc > 1) {
		if (argv[1][0] == '@') {
			char line[256], *p;
			FILE *f;
			f = fopen(argv[1] + 1, "r");
			if (!f) {
				fprintf(stderr,"cannot read partitions from '%s\n", argv[1]);
				return -1;
			}
			while (fgets(line, sizeof(line), f)) {
				p = line + strlen(line);
				while (p > line) {
					p--;
					if (*p > ' ')
						break;
					*p = 0;
				}
				p = line;
				while (*p && (*p <= ' '))
					p++;
				if (*p == '#')
					continue;
				if (*p == 0)
					continue;
				if (parse_ptn(&ptbl, p))
					return -1;
			}
			fclose(f);
		} else {	
			if (parse_ptn(&ptbl, argv[1]))
				return -1;
		}
		argc--;
		argv++;
	}

	n = crc32(0, Z_NULL, 0);
	n = crc32(n, (void*) ptbl.entry, sizeof(ptbl.entry));
	hdr->entries_crc32 = n;

	n = crc32(0, Z_NULL, 0);
	n = crc32(n, (void*) &ptbl.header, sizeof(ptbl.header));
	hdr->crc32 = n;

	show(&ptbl);

	if (real_disk) {
  		write(fd, &ptbl, sizeof(ptbl));
		fsync(fd);

		if (ioctl(fd, BLKRRPART, 0)) {
			fprintf(stderr,"could not re-read partition table\n");
		}
		close(fd);
	}
	return 0;
}
コード例 #28
0
crm_node_t *
crm_get_peer(unsigned int id, const char *uname)
{
    crm_node_t *node = NULL;
    CRM_ASSERT(id > 0 || uname != NULL);

    crm_peer_init();

    if (uname != NULL) {
        node = g_hash_table_lookup(crm_peer_cache, uname);
    }

    if (node == NULL && id > 0) {
        node = g_hash_table_lookup(crm_peer_id_cache, GUINT_TO_POINTER(id));

        if (node && node->uname && uname) {
            crm_crit("Node %s and %s share the same cluster node id '%u'!", node->uname, uname, id);
            
            /* NOTE: Calling crm_new_peer() means the entry in 
             * crm_peer_id_cache will point to the new entity
             */

            /* TODO: Replace the old uname instead? */
            node = crm_new_peer(id, uname);
            CRM_ASSERT(node->uname != NULL);
        }
    }

    if (node == NULL) {
        node = crm_new_peer(id, uname);
        if(uname) {
            const char *uuid = get_uuid(uname);
            crm_update_peer(__FUNCTION__, 0, 0, 0, -1, 0, uuid, uname, NULL, NULL);
        }
    }

    CRM_ASSERT(node);

    if (node && uname && node->uname == NULL) {
        node->uname = strdup(uname);
        crm_info("Node %u is now known as %s", id, uname);
        g_hash_table_insert(crm_peer_cache, node->uname, node);
        if (crm_status_callback) {
            crm_status_callback(crm_status_uname, node, NULL);
        }
    }

    if (node && node->uname && node->uuid == NULL) {
        const char *uuid = get_node_uuid(id, node->uname);

        if (node->uuid) {
            crm_info("Node %u has uuid %s", id, node->uuid);
        } else if (uuid) {
            node->uuid = strdup(uuid);
        }
    }

    if (node && id > 0 && id != node->id) {
        g_hash_table_remove(crm_peer_id_cache, GUINT_TO_POINTER(node->id));
        g_hash_table_insert(crm_peer_id_cache, GUINT_TO_POINTER(id), node);
        node->id = id;
        crm_info("Node %s now has id: %u", crm_str(uname), id);
    }

    return node;
}
コード例 #29
0
ファイル: nativedisk.c プロジェクト: 376473984/TrustedGRUB2
static grub_err_t
grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
		     int argc, char **args_in)
{
  char *uuid_root = 0, *uuid_prefix, *prefdev = 0;
  const char *prefix = 0;
  const char *path_prefix = 0;
  int mods_loaded = 0;
  grub_dl_t *mods;
  const char **args;
  int i;

  if (argc == 0)
    {
      argc = ARRAY_SIZE (modnames_def);
      args = modnames_def;
    }
  else
    args = (const char **) args_in;

  prefix = grub_env_get ("prefix");

  if (! prefix)
    return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "prefix");

  if (prefix)
    path_prefix = (prefix[0] == '(') ? grub_strchr (prefix, ')') : NULL;
  if (path_prefix)
    path_prefix++;
  else
    path_prefix = prefix;

  mods = grub_malloc (argc * sizeof (mods[0]));
  if (!mods)
    return grub_errno;

  if (get_uuid (NULL, &uuid_root, 0))
    return grub_errno;

  prefdev = grub_file_get_device_name (prefix);
  if (grub_errno)
    {
      grub_print_error ();
      prefdev = 0;
    }

  if (get_uuid (prefdev, &uuid_prefix, 0))
    {
      grub_free (uuid_root);
      return grub_errno;
    }

  grub_dprintf ("nativedisk", "uuid_prefix = %s, uuid_root = %s\n",
		uuid_prefix, uuid_root);

  for (mods_loaded = 0; mods_loaded < argc; mods_loaded++)
    {
      char *filename;
      grub_dl_t mod;
      grub_file_t file = NULL;
      grub_ssize_t size;
      void *core = 0;

      mod = grub_dl_get (args[mods_loaded]);
      if (mod)
	{
	  mods[mods_loaded] = 0;
	  continue;
	}

      filename = grub_xasprintf ("%s/" GRUB_TARGET_CPU "-" GRUB_PLATFORM "/%s.mod",
				 prefix, args[mods_loaded]);
      if (! filename)
	goto fail;

      file = grub_file_open (filename);
      grub_free (filename);
      if (! file)
	goto fail;

      size = grub_file_size (file);
      core = grub_malloc (size);
      if (! core)
	{
	  grub_file_close (file);
	  goto fail;
	}

      if (grub_file_read (file, core, size) != (grub_ssize_t) size)
	{
	  grub_file_close (file);
	  grub_free (core);
	  goto fail;
	}

      grub_file_close (file);

      mods[mods_loaded] = grub_dl_load_core_noinit (core, size);
      if (! mods[mods_loaded])
	goto fail;
    }

  for (i = 0; i < argc; i++)
    if (mods[i])
      grub_dl_init (mods[i]);

  if (uuid_prefix || uuid_root)
    {
      struct search_ctx ctx;
      grub_fs_autoload_hook_t saved_autoload;

      /* No need to autoload FS since obviously we already have the necessary fs modules.  */
      saved_autoload = grub_fs_autoload_hook;
      grub_fs_autoload_hook = 0;

      ctx.root_uuid = uuid_root;
      ctx.prefix_uuid = uuid_prefix;
      ctx.prefix_path = path_prefix;
      ctx.prefix_found = !uuid_prefix;
      ctx.root_found = !uuid_root;

      /* FIXME: try to guess the correct values.  */
      grub_device_iterate (iterate_device, &ctx);

      grub_fs_autoload_hook = saved_autoload;
    }
  grub_free (uuid_root);
  grub_free (uuid_prefix);

  return GRUB_ERR_NONE;

 fail:
  grub_free (uuid_root);
  grub_free (uuid_prefix);

  for (i = 0; i < mods_loaded; i++)
    if (mods[i])
      {
	mods[i]->fini = 0;
	grub_dl_unload (mods[i]);
      }
  return grub_errno;
}
コード例 #30
0
ファイル: te_utils.c プロジェクト: huiser/pacemaker
static void
tengine_stonith_notify(stonith_t * st, const char *event, xmlNode * msg)
{
    int rc = -99;
    const char *origin = NULL;
    const char *target = NULL;
    const char *executioner = NULL;
    xmlNode *action = get_xpath_object("//st-data", msg, LOG_ERR);

    if (action == NULL) {
        crm_log_xml(LOG_ERR, "Notify data not found", msg);
        return;
    }

    crm_log_xml(LOG_DEBUG, "stonith_notify", msg);
    crm_element_value_int(msg, F_STONITH_RC, &rc);
    origin = crm_element_value(action, F_STONITH_ORIGIN);
    target = crm_element_value(action, F_STONITH_TARGET);
    executioner = crm_element_value(action, F_STONITH_DELEGATE);

    if (rc == stonith_ok && crm_str_eq(target, fsa_our_uname, TRUE)) {
        crm_err("We were alegedly just fenced by %s for %s!", executioner, origin);
        register_fsa_error_adv(C_FSA_INTERNAL, I_ERROR, NULL, NULL, __FUNCTION__);

    } else if (rc == stonith_ok) {
        crm_info("Peer %s was terminated (%s) by %s for %s (ref=%s): %s",
                 target,
                 crm_element_value(action, F_STONITH_OPERATION),
                 executioner, origin,
                 crm_element_value(action, F_STONITH_REMOTE), stonith_error2string(rc));
    } else {
        crm_err("Peer %s could not be terminated (%s) by %s for %s (ref=%s): %s",
                target,
                crm_element_value(action, F_STONITH_OPERATION),
                executioner ? executioner : "<anyone>", origin,
                crm_element_value(action, F_STONITH_REMOTE), stonith_error2string(rc));
    }

#ifdef SUPPORT_CMAN
    if (rc == stonith_ok && is_cman_cluster()) {
        int local_rc = 0;
        int confirm = 0;
        char *target_copy = crm_strdup(target);

        /* In case fenced hasn't noticed yet */
        local_rc = fenced_external(target_copy);
        if (local_rc != 0) {
            crm_err("Could not notify CMAN that '%s' is now fenced: %d", target, local_rc);
        } else {
            crm_notice("Notified CMAN that '%s' is now fenced", target);
        }

        /* In case fenced is already trying to shoot it */
        confirm = open("/var/run/cluster/fenced_override", O_NONBLOCK|O_WRONLY);
        if (confirm) {
            int len = strlen(target_copy);

            errno = 0;
            local_rc = write(confirm, target_copy, len);
            write(confirm, "\n", 1);

            if(errno == EBADF) {
                crm_trace("CMAN not expecting %s to be fenced (yet)", target);

            } else if (local_rc < len) {
                crm_perror(LOG_ERR, "Confirmation of CMAN fencing event for '%s' failed: %d", target, local_rc);

            } else {
                fsync(confirm);
                crm_notice("Confirmed CMAN fencing event for '%s'", target);
            }
            close(confirm);
        }
    }
#endif

    if (rc == stonith_ok && safe_str_eq(target, origin)) {
        if (fsa_our_dc == NULL || safe_str_eq(fsa_our_dc, target)) {
            crm_notice("Target was our leader %s (recorded: %s)",
                       target, fsa_our_dc ? fsa_our_dc : "<unset>");
            /* Given the CIB resyncing that occurs around elections,
             * have one node update the CIB now and, if the new DC is different,
             * have them do so too after the election
             */
            if (safe_str_eq(executioner, fsa_our_uname)) {
                const char *uuid = get_uuid(target);

                send_stonith_update(NULL, target, uuid);
            } else {
                stonith_cleanup_list = g_list_append(stonith_cleanup_list, crm_strdup(target));
            }
        }
    }
}