static int spliceSystemRunning( char *domain) { DIR *key_dir; struct dirent *entry; char *shmName; int found = 0; char * dir_name = NULL; char * key_file_name = NULL; int key_file_name_size; dir_name = os_getTempDir(); key_dir = opendir (dir_name); if (key_dir) { entry = readdir (key_dir); while (entry != NULL) { if (strncmp (entry->d_name, "spddskey_", 9) == 0) { key_file_name_size = strlen(dir_name) + strlen(key_file_format) + 2; key_file_name = os_malloc (key_file_name_size); snprintf (key_file_name, key_file_name_size, "%s/%s", dir_name,entry->d_name); if ((shmName = matchUid (key_file_name, getuid()))) { if (strcmp (shmName, domain) == 0) { found = 1; } os_free (shmName); } os_free(key_file_name); } entry = readdir (key_dir); } closedir (key_dir); } return found; }
/** \brief Return the file-path of the key file related * to the identified shared memory * * \b os_posix_findKeyFile tries to find the key file related to \b name * in the \b temporary directory. The key files are prefixed with \b * /<temporary directory>/spddskey_. * * \b os_posix_findKeyFile first opens the directory \b temporary directory by * calling \b opendir. Then it reads all entries in serach for any entry * that starts with the name \b spddskey_ by reading the entry with * \b readdir. If the a matching entry is found, it calls os_posix_matchKeyFile * to check if the key file matches the identified \b name. If the * \b name matches the contents, the entry is found, and the path * is returned to the caller. The memory for the path is allocated * from heap and is expected to be freed by the caller. * * If no matching entry is found, NULL is returned to the caller. */ static char * os_posix_findKeyFile( const char *name) { DIR *key_dir; struct dirent *entry; char *kfn = NULL; char * dir_name = NULL; char * key_file_name = NULL; int key_file_name_size; dir_name = os_getTempDir(); key_dir = opendir(dir_name); if (key_dir) { entry = readdir(key_dir); while (entry != NULL) { if (strncmp(entry->d_name, "spddskey_", 9) == 0) { key_file_name_size = strlen(dir_name) + strlen(os_posix_key_file_format) + 2; key_file_name = os_malloc (key_file_name_size); snprintf(key_file_name, key_file_name_size, "%s/%s", dir_name, entry->d_name); if (os_posix_matchKeyFile(key_file_name, name)) { kfn = os_malloc(strlen(key_file_name) + 1); if (kfn != NULL) { os_strcpy(kfn, key_file_name); } entry = NULL; } else { entry = readdir(key_dir); } os_free (key_file_name); } else { entry = readdir(key_dir); } } closedir(key_dir); } return kfn; }
static int findSpliceSystemAndRemove( const char *domainName, os_time serviceTerminatePeriod) { DIR *key_dir; struct dirent *entry; char *shmName; int retCode = OSPL_EXIT_CODE_OK; char * dir_name = NULL; char * key_file_name = NULL; int key_file_name_size; dir_name = os_getTempDir(); key_dir = opendir (dir_name); if (key_dir) { entry = readdir (key_dir); while (entry != NULL) { if (strncmp (entry->d_name, "spddskey_", 9) == 0) { key_file_name_size = strlen(dir_name) + strlen(key_file_format) + 2; key_file_name = os_malloc (key_file_name_size); snprintf (key_file_name, key_file_name_size, "%s/%s", dir_name, entry->d_name); if ((shmName = matchKey (key_file_name, domainName))) { retCode = shutdownDDS (key_file_name, shmName, serviceTerminatePeriod); os_free (shmName); } os_free(key_file_name); } entry = readdir (key_dir); } closedir (key_dir); } else { /* unrecoverable */ retCode = OSPL_EXIT_CODE_UNRECOVERABLE_ERROR; } return retCode; }
static int findSpliceSystemAndShow(const char* specific_domain_name) { DIR *key_dir; struct dirent *entry; char *shmName; int found_count = 0; char * dir_name = NULL; char * key_file_name = NULL; int key_file_name_size; dir_name = os_getTempDir(); key_dir = opendir (dir_name); if (key_dir) { entry = readdir (key_dir); while (entry != NULL) { if (strncmp (entry->d_name, "spddskey_", 9) == 0) { key_file_name_size = strlen(dir_name) + strlen(key_file_format) + 2; key_file_name = os_malloc (key_file_name_size); snprintf (key_file_name, key_file_name_size, "%s/%s", dir_name, entry->d_name); if ((shmName = matchUid (key_file_name, geteuid()))) { if (specific_domain_name == NULL || (strcmp(specific_domain_name, shmName) == 0)) { printf("Splice System with domain name \"%s\" is found running\n", shmName); ++found_count; } os_free (shmName); } os_free(key_file_name); } entry = readdir (key_dir); } closedir (key_dir); } return found_count; }
static char * os_posix_getShmObjName( const char *name, void *map_address, int size) { int key_file_fd; int cmask; char * dir_name = NULL; char *key_file_name; unsigned int name_len; char *db_file_name; char buffer[50]; int invalid_access; int index; key_file_name = os_posix_findKeyFile(name); if ((map_address != NULL) && (key_file_name == NULL)) { dir_name = os_getTempDir(); name_len = strlen(dir_name) + strlen(os_posix_key_file_format) + 2; key_file_name = os_malloc(name_len); if (key_file_name != NULL) { snprintf(key_file_name, name_len, "%s/%s", dir_name, os_posix_key_file_format); key_file_fd = mkstemp(key_file_name); invalid_access = 0; cmask = os_posix_get_kfumask(); if ((cmask & (S_IRUSR | S_IWUSR)) && ((cmask & (S_IRUSR | S_IWUSR)) != (S_IRUSR | S_IWUSR))) { cmask |= (S_IRUSR | S_IWUSR); invalid_access = 1; } if ((cmask & (S_IRGRP | S_IWGRP)) && ((cmask & (S_IRGRP | S_IWGRP)) != (S_IRGRP | S_IWGRP))) { cmask |= (S_IRGRP | S_IWGRP); invalid_access = 1; } if ((cmask & (S_IROTH | S_IWOTH)) && ((cmask & (S_IROTH | S_IWOTH)) != (S_IROTH | S_IWOTH))) { cmask |= (S_IROTH | S_IWOTH); invalid_access = 1; } if (invalid_access) { int pmask = os_posix_get_kfumask(); OS_REPORT_7(OS_INFO, "os_posix_getShmObjName", 1, "The user file-creation mask (0%o%o%o) set for the " "service\n specifies exclusive read " "or write access for at least\n " "one of the access catagories.\n " "Read and write access should always be paired,\n" " both prohibit or granted for each " "access catagory.\n Therefore the " "service has set the user access permissions\n" " for the key file associated to " "this domain to (0%o%o%o).\nDomain : \"%s\"", (pmask & (S_IWUSR | S_IRUSR)) >> 6, (pmask & (S_IWGRP | S_IRGRP)) >> 3, pmask & (S_IWOTH | S_IROTH), (cmask & (S_IWUSR | S_IRUSR)) >> 6, (cmask & (S_IWGRP | S_IRGRP)) >> 3, cmask & (S_IWOTH | S_IROTH), name); } fchmod(key_file_fd, OS_PERMISSION & (~cmask)); write(key_file_fd, name, strlen(name) + 1); write(key_file_fd, "\n", 1); snprintf(buffer, sizeof (buffer), PA_ADDRFMT"\n", (PA_ADDRCAST)map_address); write(key_file_fd, buffer, strlen(buffer)); snprintf(buffer, sizeof (buffer), "%x\n", (unsigned int)size); write(key_file_fd, buffer, strlen(buffer)); snprintf(buffer, sizeof (buffer), "POSIX-SMO\n"); write(key_file_fd, buffer, strlen(buffer)); snprintf(buffer, sizeof (buffer), "%d\n", (int)getpid()); write(key_file_fd, buffer, strlen(buffer)); setpgrp(); /* Make this process the session leader. */ snprintf(buffer, sizeof (buffer), "%d\n", (int)getpgrp()); write(key_file_fd, buffer, strlen(buffer)); close(key_file_fd); }