This is Unofficial EPICS BASE Doxygen Site
osiProcess.h File Reference
#include "libComAPI.h"
+ Include dependency graph for osiProcess.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef enum osiGetUserNameReturn osiGetUserNameReturn
 
typedef enum osiSpawnDetachedProcessReturn osiSpawnDetachedProcessReturn
 

Enumerations

enum  osiGetUserNameReturn { osiGetUserNameFail, osiGetUserNameSuccess }
 
enum  osiSpawnDetachedProcessReturn { osiSpawnDetachedProcessFail, osiSpawnDetachedProcessSuccess, osiSpawnDetachedProcessNoSupport }
 

Functions

LIBCOM_API osiGetUserNameReturn epicsStdCall osiGetUserName (char *pBuf, unsigned bufSize)
 
LIBCOM_API osiSpawnDetachedProcessReturn epicsStdCall osiSpawnDetachedProcess (const char *pProcessName, const char *pBaseExecutableName)
 

Typedef Documentation

Enumeration Type Documentation

Enumerator
osiGetUserNameFail 
osiGetUserNameSuccess 

Definition at line 25 of file osiProcess.h.

Enumerator
osiSpawnDetachedProcessFail 
osiSpawnDetachedProcessSuccess 
osiSpawnDetachedProcessNoSupport 

Definition at line 35 of file osiProcess.h.

Function Documentation

LIBCOM_API osiGetUserNameReturn epicsStdCall osiGetUserName ( char *  pBuf,
unsigned  bufSize 
)

Definition at line 33 of file osdProcess.c.

34 {
35  struct passwd *p;
36 
37  p = getpwuid ( getuid () );
38  if ( p && p->pw_name ) {
39  size_t len = strlen ( p->pw_name );
40  unsigned uiLength;
41 
42  if ( len > UINT_MAX || len <= 0 ) {
43  return osiGetUserNameFail;
44  }
45  uiLength = (unsigned) len;
46 
47  if ( uiLength + 1 >= bufSizeIn ) {
48  return osiGetUserNameFail;
49  }
50 
51  strncpy ( pBuf, p->pw_name, (size_t) bufSizeIn );
52 
53  return osiGetUserNameSuccess;
54  }
55  else {
56  return osiGetUserNameFail;
57  }
58 }
LIBCOM_API osiSpawnDetachedProcessReturn epicsStdCall osiSpawnDetachedProcess ( const char *  pProcessName,
const char *  pBaseExecutableName 
)

Definition at line 61 of file osdProcess.c.

62 {
63  int status;
64 
65  /*
66  * create a duplicate process
67  */
68  status = fork ();
69  if (status < 0) {
71  }
72 
73  /*
74  * return to the caller
75  * in the initiating (parent) process
76  */
77  if (status) {
79  }
80 
81  /*
82  * This is executed only by the new child process.
83  * Close all open files except for STDIO, so they will not
84  * be inherited by the new program.
85  */
86  {
87  int fd, maxfd = sysconf ( _SC_OPEN_MAX );
88  for ( fd = 0; fd <= maxfd; fd++ ) {
89  if (fd==STDIN_FILENO) continue;
90  if (fd==STDOUT_FILENO) continue;
91  if (fd==STDERR_FILENO) continue;
92  close (fd);
93  }
94  }
95 
96 #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) && _POSIX_THREAD_PRIORITY_SCHEDULING > 0
97  /*
98  * Drop real-time SCHED_FIFO priority
99  */
100  {
101  struct sched_param p;
102 
103  p.sched_priority = 0;
104  status = sched_setscheduler(0, SCHED_OTHER, &p);
105  }
106 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
107 
108  /*
109  * Run the specified executable
110  */
111  status = execlp (pBaseExecutableName, pBaseExecutableName, (char *)NULL);
112  if ( status < 0 ) {
113  fprintf ( stderr, "**** The executable \"%s\" couldn't be located\n", pBaseExecutableName );
114  fprintf ( stderr, "**** because of errno = \"%s\".\n", strerror (errno) );
115  fprintf ( stderr, "**** You may need to modify your PATH environment variable.\n" );
116  fprintf ( stderr, "**** Unable to start \"%s\" process.\n", pProcessName);
117  }
118  /* Don't run our parent's atexit() handlers */
119  _exit ( -1 );
120 }
pvd::Status status
#define NULL
Definition: catime.c:38
#define stderr
Definition: epicsStdio.h:32