Remove unnecessary os_procName and os_procNamePid functions
Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
parent
a2aab8eab2
commit
0bc263e537
34 changed files with 33 additions and 455 deletions
|
@ -149,17 +149,10 @@ dds_init(dds_domainid_t domain)
|
|||
|
||||
/* Set additional default participant properties */
|
||||
|
||||
gv.default_plist_pp.process_id = (unsigned)os_procIdSelf();
|
||||
gv.default_plist_pp.process_id = (unsigned)os_getpid();
|
||||
gv.default_plist_pp.present |= PP_PRISMTECH_PROCESS_ID;
|
||||
if (os_procName(progname, sizeof(progname)) > 0)
|
||||
{
|
||||
gv.default_plist_pp.exec_name = dds_string_dup(progname);
|
||||
}
|
||||
else
|
||||
{
|
||||
gv.default_plist_pp.exec_name = dds_string_alloc(32);
|
||||
(void) snprintf(gv.default_plist_pp.exec_name, 32, "%s: %u", DDSC_PROJECT_NAME, gv.default_plist_pp.process_id);
|
||||
}
|
||||
len = (uint32_t) (13 + strlen(gv.default_plist_pp.exec_name));
|
||||
gv.default_plist_pp.present |= PP_PRISMTECH_EXEC_NAME;
|
||||
if (os_gethostname(hostname, sizeof(hostname)) == os_resultSuccess)
|
||||
|
|
|
@ -41,7 +41,7 @@ static char*
|
|||
create_topic_name(const char *prefix, char *name, size_t size)
|
||||
{
|
||||
/* Get semi random g_topic name. */
|
||||
os_procId pid = os_procIdSelf();
|
||||
os_procId pid = os_getpid();
|
||||
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
|
||||
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
|
||||
return name;
|
||||
|
|
|
@ -47,7 +47,7 @@ static char*
|
|||
create_topic_name(const char *prefix, char *name, size_t size)
|
||||
{
|
||||
/* Get semi random g_topic name. */
|
||||
os_procId pid = os_procIdSelf();
|
||||
os_procId pid = os_getpid();
|
||||
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
|
||||
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
|
||||
return name;
|
||||
|
|
|
@ -51,7 +51,7 @@ static char*
|
|||
create_topic_name(const char *prefix, char *name, size_t size)
|
||||
{
|
||||
/* Get semi random g_topic name. */
|
||||
os_procId pid = os_procIdSelf();
|
||||
os_procId pid = os_getpid();
|
||||
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
|
||||
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
|
||||
return name;
|
||||
|
|
|
@ -312,7 +312,7 @@ static char*
|
|||
create_topic_name(const char *prefix, char *name, size_t size)
|
||||
{
|
||||
/* Get semi random g_topic name. */
|
||||
os_procId pid = os_procIdSelf();
|
||||
os_procId pid = os_getpid();
|
||||
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
|
||||
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
|
||||
return name;
|
||||
|
|
|
@ -68,7 +68,7 @@ static char*
|
|||
create_topic_name(const char *prefix, char *name, size_t size)
|
||||
{
|
||||
/* Get semi random g_topic name. */
|
||||
os_procId pid = os_procIdSelf();
|
||||
os_procId pid = os_getpid();
|
||||
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
|
||||
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
|
||||
return name;
|
||||
|
|
|
@ -68,7 +68,7 @@ static char*
|
|||
create_topic_name(const char *prefix, char *name, size_t size)
|
||||
{
|
||||
/* Get semi random g_topic name. */
|
||||
os_procId pid = os_procIdSelf();
|
||||
os_procId pid = os_getpid();
|
||||
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
|
||||
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
|
||||
return name;
|
||||
|
|
|
@ -61,7 +61,7 @@ static char*
|
|||
create_topic_name(const char *prefix, char *name, size_t size)
|
||||
{
|
||||
/* Get semi random g_topic name. */
|
||||
os_procId pid = os_procIdSelf();
|
||||
os_procId pid = os_getpid();
|
||||
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
|
||||
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
|
||||
return name;
|
||||
|
|
|
@ -65,7 +65,7 @@ static char*
|
|||
create_topic_name(const char *prefix, char *name, size_t size)
|
||||
{
|
||||
/* Get semi random g_topic name. */
|
||||
os_procId pid = os_procIdSelf();
|
||||
os_procId pid = os_getpid();
|
||||
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
|
||||
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
|
||||
return name;
|
||||
|
|
|
@ -85,7 +85,7 @@ static char*
|
|||
create_topic_name(const char *prefix, char *name, size_t size)
|
||||
{
|
||||
/* Get semi random g_topic name. */
|
||||
os_procId pid = os_procIdSelf();
|
||||
os_procId pid = os_getpid();
|
||||
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
|
||||
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
|
||||
return name;
|
||||
|
|
|
@ -43,7 +43,7 @@ static char*
|
|||
create_topic_name(const char *prefix, char *name, size_t size)
|
||||
{
|
||||
/* Get semi random g_topic name. */
|
||||
os_procId pid = os_procIdSelf();
|
||||
os_procId pid = os_getpid();
|
||||
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
|
||||
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
|
||||
return name;
|
||||
|
|
|
@ -69,7 +69,7 @@ static char*
|
|||
create_topic_name(const char *prefix, char *name, size_t size)
|
||||
{
|
||||
/* Get semi random g_topic name. */
|
||||
os_procId pid = os_procIdSelf();
|
||||
os_procId pid = os_getpid();
|
||||
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
|
||||
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
|
||||
return name;
|
||||
|
|
|
@ -38,7 +38,7 @@ static char*
|
|||
create_topic_name(const char *prefix, char *name, size_t size)
|
||||
{
|
||||
/* Get semi random g_topic name. */
|
||||
os_procId pid = os_procIdSelf();
|
||||
os_procId pid = os_getpid();
|
||||
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
|
||||
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
|
||||
return name;
|
||||
|
|
|
@ -43,7 +43,7 @@ static char*
|
|||
create_topic_name(const char *prefix, char *name, size_t size)
|
||||
{
|
||||
/* Get semi random g_topic name. */
|
||||
os_procId pid = os_procIdSelf();
|
||||
os_procId pid = os_getpid();
|
||||
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
|
||||
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
|
||||
return name;
|
||||
|
|
|
@ -61,7 +61,7 @@ static char*
|
|||
create_topic_name(const char *prefix, char *name, size_t size)
|
||||
{
|
||||
/* Get semi random g_topic name. */
|
||||
os_procId pid = os_procIdSelf();
|
||||
os_procId pid = os_getpid();
|
||||
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
|
||||
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
|
||||
return name;
|
||||
|
|
|
@ -67,7 +67,7 @@ void ddsi_iid_init (void)
|
|||
os_mutexInit (&gv.dds_iid.lock);
|
||||
#endif
|
||||
|
||||
gv.dds_iid.key[0] = (uint32_t) os_procIdSelf();
|
||||
gv.dds_iid.key[0] = (uint32_t) os_getpid();
|
||||
gv.dds_iid.key[1] = (uint32_t) tnow.v;
|
||||
gv.dds_iid.key[2] = (uint32_t) (tnow.v >> 32);
|
||||
gv.dds_iid.key[3] = 0xdeadbeef;
|
||||
|
|
|
@ -1050,7 +1050,7 @@ int rtps_init (void)
|
|||
|
||||
/* Template PP guid -- protected by privileged_pp_lock for simplicity */
|
||||
gv.next_ppguid.prefix.u[0] = locator_to_hopefully_unique_uint32 (&gv.ownloc);
|
||||
gv.next_ppguid.prefix.u[1] = (unsigned) os_procIdSelf ();
|
||||
gv.next_ppguid.prefix.u[1] = (unsigned) os_getpid ();
|
||||
gv.next_ppguid.prefix.u[2] = 1;
|
||||
gv.next_ppguid.entityid.u = NN_ENTITYID_PARTICIPANT;
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@ set(sources
|
|||
src/os_errno.c
|
||||
src/os_iter.c
|
||||
src/os_strlcpy.c
|
||||
src/os_dns.c)
|
||||
src/os_dns.c
|
||||
src/os_process.c)
|
||||
|
||||
string(TOLOWER ${CMAKE_SYSTEM_NAME} system_name)
|
||||
set(system_sources
|
||||
|
@ -38,8 +39,7 @@ set(system_sources
|
|||
os_platform_sync.c
|
||||
os_platform_thread.c
|
||||
os_platform_time.c
|
||||
os_platform_init.c
|
||||
os_platform_process.c)
|
||||
os_platform_init.c)
|
||||
|
||||
foreach(source ${system_sources})
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/${system_name}/${source}")
|
||||
|
|
|
@ -39,7 +39,6 @@ extern "C" {
|
|||
#include "os/posix/os_platform_sync.h"
|
||||
#include "os/posix/os_platform_thread.h"
|
||||
#include "os/posix/os_platform_stdlib.h"
|
||||
#include "os/posix/os_platform_process.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ extern "C" {
|
|||
#include "os/posix/os_platform_sync.h"
|
||||
#include "os/posix/os_platform_thread.h"
|
||||
#include "os/posix/os_platform_stdlib.h"
|
||||
#include "os/posix/os_platform_process.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
|
|
|
@ -32,45 +32,7 @@ extern "C" {
|
|||
* Possible Results:
|
||||
* - returns the process ID of the calling process
|
||||
*/
|
||||
OSAPI_EXPORT os_procId os_procIdSelf(void);
|
||||
|
||||
/** \brief Figure out the identity of the current process
|
||||
*
|
||||
* Possible Results:
|
||||
* - returns the actual length of procIdentity
|
||||
*
|
||||
* Postcondition:
|
||||
* - \b procIdentity is ""
|
||||
* the process identity could not be determined
|
||||
* - \b procIdentity is "<decimal number>" | "0x<hexadecimal number>"
|
||||
* only the process numeric identity could be determined
|
||||
* - \b procIdentity is "<process name> (<decimal number>)" | "<process name> (0x<hexadecimal number>)"
|
||||
* the process name and numeric identity could be determined
|
||||
*
|
||||
* \b procIdentity will not be filled beyond the specified \b procIdentitySize
|
||||
*/
|
||||
OSAPI_EXPORT int
|
||||
os_procNamePid(
|
||||
_Out_writes_z_(procIdentitySize) char *procIdentity,
|
||||
_In_ size_t procIdentitySize);
|
||||
|
||||
/** \brief Figure out the name of the current process
|
||||
*
|
||||
* Possible Results:
|
||||
* - returns the actual length of procName
|
||||
*
|
||||
* Postcondition:
|
||||
* - \b procName is ""
|
||||
* the process name could not be determined
|
||||
* - \b procName is "<process name>"
|
||||
* the process name could be determined
|
||||
*
|
||||
* \b procName will not be filled beyond the specified \b procNameSize
|
||||
*/
|
||||
OSAPI_EXPORT int
|
||||
os_procName(
|
||||
_Out_writes_z_(procNameSize) char *procName,
|
||||
_In_ size_t procNameSize);
|
||||
OSAPI_EXPORT os_procId os_getpid(void);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ extern "C" {
|
|||
#include "os/posix/os_platform_sync.h"
|
||||
#include "os/posix/os_platform_thread.h"
|
||||
#include "os/posix/os_platform_stdlib.h"
|
||||
#include "os/posix/os_platform_process.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
|
|
|
@ -43,7 +43,6 @@ extern "C" {
|
|||
|
||||
#include "os/windows/os_platform_socket.h"
|
||||
#include "os/windows/os_platform_sync.h"
|
||||
#include "os/windows/os_platform_process.h"
|
||||
#include "os/windows/os_platform_thread.h"
|
||||
#include "os/windows/os_platform_stdlib.h"
|
||||
#include "os/windows/os_platform_time.h"
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef OS_PLATFORM_PROCESS_H
|
||||
#define OS_PLATFORM_PROCESS_H
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
void os_processModuleInit(void);
|
||||
void os_processModuleExit(void);
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -9,16 +9,15 @@
|
|||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef OS_PLATFORM_PROCESS_H
|
||||
#define OS_PLATFORM_PROCESS_H
|
||||
#include "os/os.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
os_procId
|
||||
os_getpid(void)
|
||||
{
|
||||
#if defined(WIN32)
|
||||
return GetCurrentProcessId();
|
||||
#else
|
||||
/* Mapped to taskIdSelf() in VxWorks kernel mode. */
|
||||
return getpid();
|
||||
#endif
|
||||
void os_processModuleInit(void);
|
||||
void os_processModuleExit(void);
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -30,14 +30,12 @@ void os_osPlatformInit (void)
|
|||
{
|
||||
os_syncModuleInit();
|
||||
os_threadModuleInit();
|
||||
os_processModuleInit();
|
||||
}
|
||||
|
||||
/** \brief OS layer deinitialization
|
||||
*/
|
||||
void os_osPlatformExit (void)
|
||||
{
|
||||
os_processModuleExit();
|
||||
os_threadModuleExit();
|
||||
os_syncModuleExit();
|
||||
}
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#include "os/os.h"
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <mach-o/dyld.h>
|
||||
#endif
|
||||
|
||||
#include "../snippets/code/os_posix_process.c"
|
||||
|
||||
#define _OS_PROCESS_DEFAULT_NAME_LEN_ (512)
|
||||
int
|
||||
os_procName(
|
||||
char *procName,
|
||||
size_t procNameSize)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
char* exec, *processName = NULL;
|
||||
int ret;
|
||||
uint32_t usize = _OS_PROCESS_DEFAULT_NAME_LEN_;
|
||||
processName = os_malloc(usize);
|
||||
*processName = 0;
|
||||
if (_NSGetExecutablePath(processName, &usize) != 0) {
|
||||
/* processName is longer than allocated */
|
||||
processName = os_realloc(processName, usize + 1);
|
||||
if (_NSGetExecutablePath(processName, &usize) == 0) {
|
||||
/* path set successful */
|
||||
}
|
||||
}
|
||||
exec = strrchr(processName,'/');
|
||||
if (exec) {
|
||||
/* move everything following the last slash forward */
|
||||
memmove (processName, exec+1, strlen (exec+1) + 1);
|
||||
}
|
||||
ret = snprintf(procName, procNameSize, "%s", processName);
|
||||
os_free (processName);
|
||||
return ret;
|
||||
#else
|
||||
return snprintf(procName, procNameSize, "bla%lu", (unsigned long)getpid());
|
||||
#endif
|
||||
}
|
||||
#undef _OS_PROCESS_DEFAULT_NAME_LEN_
|
|
@ -1,114 +0,0 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
/** \file os/posix/code/os_process.c
|
||||
* \brief Posix process management
|
||||
*
|
||||
* Implements process management for POSIX
|
||||
*/
|
||||
|
||||
#include "os/os.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <sched.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
|
||||
static os_atomic_voidp_t os_procname = OS_ATOMIC_VOIDP_INIT(0);
|
||||
|
||||
/** \brief pointer to environment variables */
|
||||
#ifdef __APPLE__
|
||||
//not available on iOS, but also not currently used
|
||||
//#include <crt_externs.h>
|
||||
#else
|
||||
extern char **environ;
|
||||
#endif
|
||||
|
||||
/* protected functions */
|
||||
void
|
||||
os_processModuleInit(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
os_processModuleExit(void)
|
||||
{
|
||||
void *pname;
|
||||
do {
|
||||
pname = os_atomic_ldvoidp(&os_procname);
|
||||
} while (!os_atomic_casvoidp(&os_procname, pname, NULL));
|
||||
os_free(pname);
|
||||
}
|
||||
/* public functions */
|
||||
|
||||
/** \brief Return the process ID of the calling process
|
||||
*
|
||||
* Possible Results:
|
||||
* - returns the process ID of the calling process
|
||||
*/
|
||||
os_procId
|
||||
os_procIdSelf(void)
|
||||
{
|
||||
return getpid();
|
||||
}
|
||||
|
||||
/* _OS_PROCESS_DEFAULT_CMDLINE_LEN_ is defined as
|
||||
* strlen("/proc/<max_pid>/cmdline" + 1, max_pid = 32768 on Linux, so a reason-
|
||||
* able default is 20 */
|
||||
#define _OS_PROCESS_DEFAULT_CMDLINE_LEN_ (20)
|
||||
#define _OS_PROCESS_PROCFS_PATH_FMT_ "/proc/%d/cmdline"
|
||||
#define _OS_PROCESS_DEFAULT_NAME_LEN_ (512)
|
||||
|
||||
/** \brief Figure out the identity of the current process
|
||||
*
|
||||
* os_procNamePid determines the numeric, and if possible named
|
||||
* identity of a process. It will first check if the environment variable
|
||||
* SPLICE_PROCNAME is set (which is always the case if the process is started
|
||||
* via os_procCreate). If so, that value will be returned. Otherwise it will be
|
||||
* attempted to determine the commandline which started the process through the
|
||||
* procfs. If that fails, the PID will be returned.
|
||||
*
|
||||
* \param procIdentity Pointer to a char-buffer to which the result can be
|
||||
* written. If a name could be resolved, the result will
|
||||
* have the format "name <PID>". Otherwise it will just
|
||||
* be "<PID>".
|
||||
* \param procIdentitySize Size of the buffer pointed to by procIdentitySize
|
||||
* \return same as snprintf returns
|
||||
*/
|
||||
int
|
||||
os_procNamePid(
|
||||
char *procIdentity,
|
||||
size_t procIdentitySize)
|
||||
{
|
||||
int size;
|
||||
char process_name[_OS_PROCESS_DEFAULT_NAME_LEN_];
|
||||
|
||||
size = os_procName(process_name, _OS_PROCESS_DEFAULT_NAME_LEN_);
|
||||
if (size > 0) {
|
||||
size = snprintf(procIdentity, procIdentitySize, "%s <%"PRIprocId">", (char *)os_atomic_ldvoidp(&os_procname), os_procIdSelf());
|
||||
} else {
|
||||
/* No processname could be determined, so default to PID */
|
||||
size = snprintf(procIdentity, procIdentitySize, "<%"PRIprocId">", os_procIdSelf());
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
#undef _OS_PROCESS_DEFAULT_CMDLINE_LEN_
|
||||
#undef _OS_PROCESS_PROCFS_PATH_FMT_
|
||||
#undef _OS_PROCESS_DEFAULT_NAME_LEN_
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifdef _WRS_KERNEL
|
||||
|
||||
#include "os/os.h"
|
||||
|
||||
/** \brief Return the process ID of the calling process
|
||||
*
|
||||
* Possible Results:
|
||||
* - returns the process ID of the calling process
|
||||
*/
|
||||
os_procId
|
||||
os_procIdSelf(void)
|
||||
{
|
||||
return getpid(); /* Mapped to taskIdSelf() in kernel mode */
|
||||
}
|
||||
|
||||
#else
|
||||
#include "../posix/os_platform_process.c"
|
||||
#endif /* _WRS_KERNEL */
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
void os_osPlatformInit (void)
|
||||
{
|
||||
os_processModuleInit();
|
||||
os_threadModuleInit();
|
||||
os_timeModuleInit();
|
||||
os_socketModuleInit();
|
||||
|
@ -34,7 +33,6 @@ void os_osPlatformExit (void)
|
|||
os_socketModuleExit();
|
||||
os_timeModuleExit();
|
||||
os_threadModuleExit();
|
||||
os_processModuleExit();
|
||||
}
|
||||
|
||||
/* We need this on windows to make sure the main thread of MFC applications
|
||||
|
|
|
@ -1,144 +0,0 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
/** \file os/win32/code/os_process.c
|
||||
* \brief WIN32 process management
|
||||
*
|
||||
* Implements process management for WIN32
|
||||
*/
|
||||
#include "os/os.h"
|
||||
|
||||
#include <process.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* #642 fix : define mapping between scheduling abstraction and windows
|
||||
* Windows provides 6 scheduling classes for the process
|
||||
* IDLE_PRIORITY_CLASS
|
||||
* BELOW_NORMAL_PRIORITY_CLASS
|
||||
* NORMAL_PRIORITY_CLASS
|
||||
* ABOVE_NORMAL_PRIORITY_CLASS
|
||||
* HIGH_PRIORITY_CLASS
|
||||
* REALTIME_PRIORITY_CLASS */
|
||||
|
||||
/* These defaults should be modifiable through configuration */
|
||||
static const os_schedClass TIMESHARE_DEFAULT_SCHED_CLASS = NORMAL_PRIORITY_CLASS;
|
||||
static const os_schedClass REALTIME_DEFAULT_SCHED_CLASS = REALTIME_PRIORITY_CLASS;
|
||||
|
||||
static os_atomic_voidp_t os_procname = OS_ATOMIC_VOIDP_INIT(0);
|
||||
|
||||
/* Protected functions */
|
||||
void
|
||||
os_processModuleInit(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
os_processModuleExit(void)
|
||||
{
|
||||
void *pname;
|
||||
do {
|
||||
pname = os_atomic_ldvoidp(&os_procname);
|
||||
} while (!os_atomic_casvoidp(&os_procname, pname, NULL));
|
||||
os_free(pname);
|
||||
}
|
||||
|
||||
/** \brief Return the process ID of the calling process
|
||||
*
|
||||
* Possible Results:
|
||||
* - returns the process ID of the calling process
|
||||
*/
|
||||
os_procId
|
||||
os_procIdSelf(void)
|
||||
{
|
||||
/* returns a pseudo HANDLE to process, no need to close it */
|
||||
return GetProcessId (GetCurrentProcess());
|
||||
}
|
||||
|
||||
/** \brief Figure out the identity of the current process
|
||||
*
|
||||
* Possible Results:
|
||||
* - returns the actual length of procIdentity
|
||||
*
|
||||
* Postcondition:
|
||||
* - \b procIdentity is ""
|
||||
* the process identity could not be determined
|
||||
* - \b procIdentity is "<decimal number>"
|
||||
* only the process numeric identity could be determined
|
||||
* - \b procIdentity is "name <pid>"
|
||||
* the process name and numeric identity could be determined
|
||||
*
|
||||
* \b procIdentity will not be filled beyond the specified \b procIdentitySize
|
||||
*/
|
||||
#define _OS_PROC_PROCES_NAME_LEN (512)
|
||||
int
|
||||
os_procNamePid(
|
||||
_Out_writes_z_(procIdentitySize) char *procIdentity,
|
||||
_In_ size_t procIdentitySize)
|
||||
{
|
||||
int size;
|
||||
char process_name[_OS_PROC_PROCES_NAME_LEN];
|
||||
|
||||
size = os_procName(process_name, sizeof(process_name));
|
||||
|
||||
if (size > 0) {
|
||||
size = snprintf(procIdentity, procIdentitySize, "%s <%"PRIprocId">", process_name, os_procIdSelf());
|
||||
} else {
|
||||
/* No processname could be determined, so default to PID */
|
||||
size = snprintf(procIdentity, procIdentitySize, "<%"PRIprocId">", os_procIdSelf());
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int
|
||||
os_procName(
|
||||
_Out_writes_z_(procNameSize) char *procName,
|
||||
_In_ size_t procNameSize)
|
||||
{
|
||||
char *process_name;
|
||||
|
||||
if ((process_name = os_atomic_ldvoidp(&os_procname)) == NULL) {
|
||||
char *exec, *pname;
|
||||
DWORD nSize, allocated = 0;
|
||||
|
||||
do {
|
||||
/* While procNameSize could be used (since the caller cannot
|
||||
* store more data anyway, it is not used. This way the amount that
|
||||
* needs to be allocated to get the full-name can be determined. */
|
||||
allocated++;
|
||||
process_name = os_realloc(process_name, allocated * _OS_PROC_PROCES_NAME_LEN);
|
||||
/* First parameter NULL retrieves module-name of executable */
|
||||
nSize = GetModuleFileNameA(NULL, process_name, allocated * _OS_PROC_PROCES_NAME_LEN);
|
||||
|
||||
/* process_name will only be guaranteed to be NULL-terminated if nSize <
|
||||
* (allocated * _OS_PROC_PROCES_NAME_LEN), so continue until that's true */
|
||||
} while (nSize >= (allocated * _OS_PROC_PROCES_NAME_LEN));
|
||||
|
||||
exec = strrchr(process_name, '\\');
|
||||
if (exec) {
|
||||
/* skip all before the last '\' */
|
||||
exec++;
|
||||
memmove(process_name, exec, strlen(exec) + 1);
|
||||
/* Could potentially realloc; can't be bothered */
|
||||
}
|
||||
do {
|
||||
pname = os_atomic_ldvoidp(&os_procname);
|
||||
} while (pname == NULL && !os_atomic_casvoidp(&os_procname, NULL, process_name));
|
||||
if(pname) {
|
||||
os_free(process_name);
|
||||
process_name = pname;
|
||||
}
|
||||
}
|
||||
return snprintf(procName, procNameSize, "%s", process_name);
|
||||
}
|
||||
#undef _OS_PROC_PROCES_NAME_LEN
|
|
@ -42,9 +42,6 @@ os_threadAttr mutex_os_threadAttr;
|
|||
os_threadId mutex_os_threadId[4];
|
||||
os_time delay1 = { 5, 0 };
|
||||
os_time pdelay = { 1, 0 };
|
||||
os_procId mutex_os_procId;
|
||||
os_procId mutex_os_procId1;
|
||||
os_procId mutex_os_procId2;
|
||||
char buffer[512];
|
||||
int supported_resultBusy;
|
||||
int loop;
|
||||
|
|
|
@ -57,7 +57,6 @@ os_threadAttr rwlock_os_threadAttr;
|
|||
os_threadId rwlock_os_threadId[RWLOCK_THREADS];
|
||||
static int i;
|
||||
char buffer[512];
|
||||
os_procId rwlock_os_procId;
|
||||
int supported_resultBusy;
|
||||
int loop;
|
||||
static shared_data sd;
|
||||
|
|
|
@ -2196,7 +2196,7 @@ int MAIN(int argc, char *argv[]) {
|
|||
want_reader = 0;
|
||||
|
||||
save_argv0 (argv[0]);
|
||||
pid = (int) os_procIdSelf();
|
||||
pid = (int) os_getpid();
|
||||
|
||||
qreader[0] = "k=all";
|
||||
qreader[1] = "R=10000/inf/inf";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue