This is Unofficial EPICS BASE Doxygen Site
osdProcess.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE Versions 3.13.7
7 * and higher are distributed subject to a Software License Agreement found
8 * in file LICENSE that is included with this distribution.
9 \*************************************************************************/
10 /*
11  * Operating System Dependent Implementation of osiProcess.h
12  *
13  * Author: Jeff Hill
14  *
15  */
16 
17 #ifndef _WIN32
18 #error This source is specific to WIN32
19 #endif
20 
21 #include <stdlib.h>
22 #include <stdio.h>
23 
24 #define STRICT
25 #include <windows.h>
26 
27 #include "osiProcess.h"
28 
29 LIBCOM_API osiGetUserNameReturn epicsStdCall osiGetUserName (char *pBuf, unsigned bufSizeIn)
30 {
31  DWORD bufsize;
32 
33  if ( bufSizeIn > 0xffffffff ) {
34  return osiGetUserNameFail;
35  }
36 
37  bufsize = (DWORD) bufSizeIn;
38 
39  if ( ! GetUserName (pBuf, &bufsize) ) {
40  return osiGetUserNameFail;
41  }
42 
43  if ( *pBuf == '\0' ) {
44  return osiGetUserNameFail;
45  }
46 
47  return osiGetUserNameSuccess;
48 }
49 
51  ( const char *pProcessName, const char *pBaseExecutableName )
52 {
53  BOOL status;
54  STARTUPINFO startupInfo;
55  PROCESS_INFORMATION processInfo;
56 
57  GetStartupInfo ( &startupInfo );
58  startupInfo.lpReserved = NULL;
59  startupInfo.lpTitle = (char *) pProcessName;
60  startupInfo.dwFlags = STARTF_USESHOWWINDOW;
61  startupInfo.wShowWindow = SW_SHOWMINNOACTIVE;
62 
63  status = CreateProcess (
64  NULL, /* pointer to name of executable module (not required if command line is specified) */
65  (char *) pBaseExecutableName, /* pointer to command line string */
66  NULL, /* pointer to process security attributes */
67  NULL, /* pointer to thread security attributes */
68  FALSE, /* handle inheritance flag */
69  CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS, /* creation flags */
70  NULL, /* pointer to new environment block (defaults to caller's environement) */
71  NULL, /* pointer to current directory name (defaults to caller's current directory) */
72  &startupInfo, /* pointer to STARTUPINFO */
73  &processInfo /* pointer to PROCESS_INFORMATION */
74  );
75  if ( status == 0 ) {
76  DWORD W32status;
77  LPVOID errStrMsgBuf;
78  LPVOID complteMsgBuf;
79 
80  W32status = FormatMessage (
81  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
82  NULL,
83  GetLastError (),
84  MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
85  (LPTSTR) &errStrMsgBuf,
86  0,
87  NULL
88  );
89 
90  if ( W32status ) {
91  char *pFmtArgs[6];
92  pFmtArgs[0] = "Failed to start executable -";
93  pFmtArgs[1] = (char *) pBaseExecutableName;
94  pFmtArgs[2] = errStrMsgBuf;
95  pFmtArgs[3] = "Changes may be required in your \"path\" environment variable.";
96 
97  W32status = FormatMessage(
98  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING |
99  FORMAT_MESSAGE_ARGUMENT_ARRAY | 80,
100  "%1 \"%2\". %3 %4",
101  0,
102  MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
103  (LPTSTR) &complteMsgBuf,
104  0,
105  pFmtArgs
106  );
107  if (W32status) {
108  fprintf (stderr, "%s\n", (char *) complteMsgBuf);
109  LocalFree (complteMsgBuf);
110  }
111  else {
112  fprintf (stderr, "%s\n", (char *) errStrMsgBuf);
113  }
114 
115  /* Free the buffer. */
116  LocalFree (errStrMsgBuf);
117  }
118  else {
119  fprintf (stderr, "!!WARNING!!\n");
120  fprintf (stderr, "Unable to locate executable \"%s\".\n", pBaseExecutableName);
121  fprintf (stderr, "You may need to modify your \"path\" environment variable.\n");
122  }
124  }
125 
127 }
#define FALSE
Definition: dbDefs.h:32
pvd::Status status
#define NULL
Definition: catime.c:38
osiSpawnDetachedProcessReturn
Definition: osiProcess.h:35
LIBCOM_API osiGetUserNameReturn epicsStdCall osiGetUserName(char *pBuf, unsigned bufSizeIn)
Definition: osdProcess.c:33
LIBCOM_API osiSpawnDetachedProcessReturn epicsStdCall osiSpawnDetachedProcess(const char *pProcessName, const char *pBaseExecutableName)
Definition: osdProcess.c:61
osiGetUserNameReturn
Definition: osiProcess.h:25
#define stderr
Definition: epicsStdio.h:32