ProfileRankSampler::ProfileRankSampler(const std::string shm_key, size_t table_size) : m_table_shmem(nullptr) , m_table(nullptr) , m_region_entry(GEOPM_INVALID_PROF_MSG) , m_is_name_finished(false) { std::string key_path("/dev/shm/" + shm_key); (void)unlink(key_path.c_str()); errno = 0; // Ignore errors from the unlink call. m_table_shmem = geopm::make_unique<SharedMemory>(shm_key, table_size); m_table = geopm::make_unique<ProfileTable>(m_table_shmem->size(), m_table_shmem->pointer()); }
int main() { int graph[MAX][MAX]; int i; for (i = 0; i < MAX; i++) { int j; for (j = 0; j < MAX; j++) graph[i][j] = 0; } int row, col, weight; for (i = 0; i < 11; i++) { scanf("%d%d%d", &row, &col, &weight); graph[row][col] = weight; } key_path(graph); return 0; }
TEST_F(SharedMemoryTest, fd_check) { struct stat buf; std::string key_path("/dev/shm"); m_shm_key += "-fd_check"; key_path += m_shm_key; config_shmem(); sleep(5); EXPECT_EQ(stat(key_path.c_str(), &buf), 0) << "Something (likely systemd) is removing shmem entries after creation.\n" << "See https://superuser.com/a/1179962 for more information."; config_shmem_u(); cleanup_shmem_u(); cleanup_shmem(); EXPECT_EQ(stat(key_path.c_str(), &buf), -1); EXPECT_EQ(errno, ENOENT); }
static int pkcs8_dir_remove(void *_handle, const char *id) { if (!_handle || !id) { return DNSSEC_EINVAL; } pkcs8_dir_handle_t *handle = _handle; _cleanup_free_ char *filename = key_path(handle->dir_name, id); if (!filename) { return DNSSEC_ENOMEM; } if (unlink(filename) == -1) { return dnssec_errno_to_error(errno); } return DNSSEC_EOK; }
void KeyShare::CheckPath() { QDir key_path(_path, "*.pub"); foreach(const QString &key_name, key_path.entryList()) { QString path = _path + "/" + key_name; QFile key_file(path); key_file.open(QIODevice::ReadOnly); QSharedPointer<QSslCertificate> cert(new QSslCertificate(&key_file, QSsl::Der)); QSslKey pubkey = cert->publicKey(); QSharedPointer<AsymmetricKey> key(new DsaPublicKey(pubkey.toDer())); if(!key->IsValid()) { qDebug() << "Invalid key:" << path; continue; } QString name = key_name.left(key_name.length() - 4); AddCertificate(name, cert); } }
/*! * Open a key file and get the descriptor. */ static int key_open(const char *dir_name, const char *id, int flags, mode_t mode, int *fd_ptr) { assert(dir_name); assert(id); assert(fd_ptr); _cleanup_free_ char *filename = key_path(dir_name, id); if (!filename) { return DNSSEC_ENOMEM; } int fd = open(filename, flags, mode); if (fd == -1) { return dnssec_errno_to_error(errno); } *fd_ptr = fd; return DNSSEC_EOK; }
static void SetUpTestCase() { // We store the allocated objects in these results so that we can // have a consolidated 'cleanup()' function. This makes all the // 'EXIT()' calls more readable and less error prone. Result<EVP_PKEY*> private_key = None(); Result<X509*> certificate = None(); Result<EVP_PKEY*> scrap_key = None(); Result<X509*> scrap_certificate = None(); auto cleanup = [&private_key, &certificate, &scrap_key, &scrap_certificate]( bool failure = true) { if (private_key.isSome()) { EVP_PKEY_free(private_key.get()); } if (certificate.isSome()) { X509_free(certificate.get()); } if (scrap_key.isSome()) { EVP_PKEY_free(scrap_key.get()); } if (scrap_certificate.isSome()) { X509_free(scrap_certificate.get()); } // If we are under a failure condition, clean up any files we // already generated. The expected behavior is that they will be // cleaned up in 'TearDownTestCase()'; however, we call ABORT // during 'SetUpTestCase()' failures. if (failure) { cleanup_directories(); } }; // Generate the authority key. private_key = process::network::openssl::generate_private_rsa_key(); if (private_key.isError()) { ABORT("Could not generate private key: " + private_key.error()); } // Figure out the hostname that 'INADDR_LOOPBACK' will bind to. // Set the hostname of the certificate to this hostname so that // hostname verification of the certificate will pass. Try<std::string> hostname = net::getHostname(net::IP(INADDR_LOOPBACK)); if (hostname.isError()) { cleanup(); ABORT("Could not determine hostname of 'INADDR_LOOPBACK': " + hostname.error()); } // Generate an authorized certificate. certificate = process::network::openssl::generate_x509( private_key.get(), private_key.get(), None(), 1, 365, hostname.get()); if (certificate.isError()) { cleanup(); ABORT("Could not generate certificate: " + certificate.error()); } // Write the authority key to disk. Try<Nothing> key_write = process::network::openssl::write_key_file(private_key.get(), key_path()); if (key_write.isError()) { cleanup(); ABORT("Could not write private key to disk: " + key_write.error()); } // Write the authorized certificate to disk. Try<Nothing> certificate_write = process::network::openssl::write_certificate_file( certificate.get(), certificate_path()); if (certificate_write.isError()) { cleanup(); ABORT("Could not write certificate to disk: " + certificate_write.error()); } // Generate a scrap key. scrap_key = process::network::openssl::generate_private_rsa_key(); if (scrap_key.isError()) { cleanup(); ABORT("Could not generate a scrap private key: " + scrap_key.error()); } // Write the scrap key to disk. key_write = process::network::openssl::write_key_file( scrap_key.get(), scrap_key_path()); if (key_write.isError()) { cleanup(); ABORT("Could not write scrap key to disk: " + key_write.error()); } // Generate a scrap certificate. scrap_certificate = process::network::openssl::generate_x509( scrap_key.get(), scrap_key.get()); if (scrap_certificate.isError()) { cleanup(); ABORT("Could not generate a scrap certificate: " + scrap_certificate.error()); } // Write the scrap certificate to disk. certificate_write = process::network::openssl::write_certificate_file( scrap_certificate.get(), scrap_certificate_path()); if (certificate_write.isError()) { cleanup(); ABORT("Could not write scrap certificate to disk: " + certificate_write.error()); } // Since we successfully set up all our state, we call cleanup // with failure set to 'false'. cleanup(false); }