ReactOS  0.4.12-dev-51-ge94618b
service.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SZAPPNAME   "nfsd"
 
#define SZSERVICENAME   "pnfs"
 
#define SZSERVICEDISPLAYNAME   "NFSv4.1 Client"
 
#define SZDEPENDENCIES   ""
 

Functions

VOID ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv)
 
VOID ServiceStop ()
 
BOOL ReportStatusToSCMgr (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint)
 
void AddToMessageLog (LPTSTR lpszMsg)
 

Macro Definition Documentation

◆ SZAPPNAME

#define SZAPPNAME   "nfsd"

Definition at line 65 of file service.h.

Referenced by main().

◆ SZDEPENDENCIES

#define SZDEPENDENCIES   ""

Definition at line 71 of file service.h.

Referenced by CmdInstallService().

◆ SZSERVICEDISPLAYNAME

#define SZSERVICEDISPLAYNAME   "NFSv4.1 Client"

Definition at line 69 of file service.h.

Referenced by CmdDebugService(), CmdInstallService(), CmdRemoveService(), and ControlHandler().

◆ SZSERVICENAME

#define SZSERVICENAME   "pnfs"

Definition at line 67 of file service.h.

Referenced by AddToMessageLog(), CmdInstallService(), CmdRemoveService(), main(), and service_main().

Function Documentation

◆ AddToMessageLog()

void AddToMessageLog ( LPTSTR  lpszMsg)

Definition at line 289 of file service.c.

Referenced by main(), and ReportStatusToSCMgr().

290 {
291  TCHAR szMsg [(sizeof(SZSERVICENAME) / sizeof(TCHAR)) + 100 ];
292  HANDLE hEventSource;
293  LPTSTR lpszStrings[2];
294 
295  if ( !bDebug )
296  {
297  dwErr = GetLastError();
298 
299  // Use event logging to log the error.
300  //
301  hEventSource = RegisterEventSource(NULL, TEXT(SZSERVICENAME));
302 
303 #ifndef __REACTOS__
304  _stprintf_s(szMsg,(sizeof(SZSERVICENAME) / sizeof(TCHAR)) + 100, TEXT("%s error: %d"), TEXT(SZSERVICENAME), dwErr);
305 #else
306  _sntprintf(szMsg,(sizeof(SZSERVICENAME) / sizeof(TCHAR)) + 100, TEXT("%s error: %d"), TEXT(SZSERVICENAME), dwErr);
307 #endif
308  lpszStrings[0] = szMsg;
309  lpszStrings[1] = lpszMsg;
310 
311  if (hEventSource != NULL)
312  {
313  ReportEvent(hEventSource, // handle of event source
314  EVENTLOG_ERROR_TYPE, // event type
315  0, // event category
316  0, // event ID
317  NULL, // current user's SID
318  2, // strings in lpszStrings
319  0, // no bytes of raw data
320  lpszStrings, // array of error strings
321  NULL); // no raw data
322 
323  (VOID) DeregisterEventSource(hEventSource);
324  }
325  }
326 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL bDebug
Definition: service.c:37
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define EVENTLOG_ERROR_TYPE
Definition: winnt_old.h:2630
smooth NULL
Definition: ftsmooth.c:416
DWORD dwErr
Definition: service.c:36
char TCHAR
Definition: xmlstorage.h:189
#define VOID
Definition: acefi.h:82
#define _sntprintf
Definition: xmlstorage.h:201
#define ReportEvent
Definition: winbase.h:3713
#define SZSERVICENAME
Definition: service.h:67
#define RegisterEventSource
Definition: winbase.h:3708
#define TEXT(s)
Definition: k32.h:26
BOOL WINAPI DeregisterEventSource(IN HANDLE hEventLog)
Definition: eventlog.c:473

◆ ReportStatusToSCMgr()

BOOL ReportStatusToSCMgr ( DWORD  dwCurrentState,
DWORD  dwWin32ExitCode,
DWORD  dwWaitHint 
)

Definition at line 240 of file service.c.

Referenced by open_log_files(), service_ctrl(), service_main(), and ServiceStart().

243 {
244  static DWORD dwCheckPoint = 1;
245  BOOL fResult = TRUE;
246 
247 
248  if ( !bDebug ) // when debugging we don't report to the SCM
249  {
250  if (dwCurrentState == SERVICE_START_PENDING)
252  else
254 
255  ssStatus.dwCurrentState = dwCurrentState;
256  ssStatus.dwWin32ExitCode = dwWin32ExitCode;
257  ssStatus.dwWaitHint = dwWaitHint;
258 
259  if ( ( dwCurrentState == SERVICE_RUNNING ) ||
260  ( dwCurrentState == SERVICE_STOPPED ) )
262  else
263  ssStatus.dwCheckPoint = dwCheckPoint++;
264 
265 
266  // Report the status of the service to the service control manager.
268  if (!fResult)
269  AddToMessageLog(TEXT("SetServiceStatus"));
270  }
271  return fResult;
272 }
#define TRUE
Definition: types.h:120
SERVICE_STATUS_HANDLE sshStatusHandle
Definition: service.c:35
DWORD dwCurrentState
Definition: winsvc.h:100
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
#define SERVICE_START_PENDING
Definition: winsvc.h:22
BOOL bDebug
Definition: service.c:37
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:957
VOID AddToMessageLog(LPTSTR lpszMsg)
Definition: service.c:289
DWORD dwCheckPoint
Definition: winsvc.h:104
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_RUNNING
Definition: winsvc.h:24
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD dwWaitHint
Definition: winsvc.h:105
DWORD dwWin32ExitCode
Definition: winsvc.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwControlsAccepted
Definition: winsvc.h:101
#define TEXT(s)
Definition: k32.h:26
SERVICE_STATUS ssStatus
Definition: service.c:34

◆ ServiceStart()

VOID ServiceStart ( DWORD  dwArgc,
LPTSTR lpszArgv 
)

Definition at line 380 of file nfs41_daemon.c.

Referenced by CmdDebugService(), IopLoadServiceModule(), and service_main().

382 {
383  DWORD status = 0, len;
384  // handle to our drivers
385  HANDLE pipe;
387  nfs41_idmapper *idmapper = NULL;
388  int i;
389  nfsd_args cmd_args;
390 
391  if (!check_for_files())
392  exit(0);
393  if (!parse_cmdlineargs(argc, argv, &cmd_args))
394  exit(0);
395  set_debug_level(cmd_args.debug_level);
396  open_log_files();
397 
398 #ifdef __REACTOS__
399  /* Start the kernel part */
400  {
402  if (hSvcMan)
403  {
404  HANDLE hSvc = OpenService(hSvcMan, "nfs41_driver", SERVICE_ALL_ACCESS);
405  if (hSvc)
406  {
407  SERVICE_STATUS SvcSt;
408  QueryServiceStatus(hSvc, &SvcSt);
409  if (SvcSt.dwCurrentState != SERVICE_RUNNING)
410  {
411  if (StartService(hSvc, 0, NULL))
412  {
413  dprintf(1, "NFS41 driver started\n");
414  }
415  else
416  {
417  eprintf("Driver failed to start: %d\n", GetLastError());
418  }
419  }
420  else
421  {
422  eprintf("Driver in state: %x\n", SvcSt.dwCurrentState);
423  }
424 
425  CloseServiceHandle(hSvc);
426  }
427  else
428  {
429  eprintf("Failed to open service: %d\n", GetLastError());
430  }
431 
432  CloseServiceHandle(hSvcMan);
433  }
434  else
435  {
436  eprintf("Failed to open service manager: %d\n", GetLastError());
437  }
438  }
439 #endif
440 
441 #ifdef _DEBUG
442  /* dump memory leaks to stderr on exit; this requires the debug heap,
443  /* available only when built in debug mode under visual studio -cbodley */
446 #pragma warning (push)
447 #pragma warning (disable : 4306) /* conversion from 'int' to '_HFILE' of greater size */
449 #pragma warning (pop)
450  dprintf(1, "debug mode. dumping memory leaks to stderr on exit.\n");
451 #endif
452  /* acquire and store in global memory current dns domain name.
453  * needed for acls */
454  if (getdomainname())
455  exit(0);
456 
458 
459  if (cmd_args.ldap_enable) {
460  status = nfs41_idmap_create(&idmapper);
461  if (status) {
462  eprintf("id mapping initialization failed with %d\n", status);
463  goto out_logs;
464  }
465  }
466 
468  dprintf(1, "NFS41 Daemon starting: version %d\n", NFS41D_VERSION);
469 
472  0, NULL);
473  if (pipe == INVALID_HANDLE_VALUE)
474  {
475  eprintf("Unable to open upcall pipe %d\n", GetLastError());
476  goto out_idmap;
477  }
478 
479  dprintf(1, "starting nfs41 mini redirector\n");
480  status = DeviceIoControl(pipe, IOCTL_NFS41_START,
481  &NFS41D_VERSION, sizeof(DWORD), NULL, 0, (LPDWORD)&len, NULL);
482  if (!status) {
483  eprintf("IOCTL_NFS41_START failed with %d\n",
484  GetLastError());
485  goto out_pipe;
486  }
487 
488 #ifndef STANDALONE_NFSD
490  if (stop_event == NULL)
491  goto out_pipe;
492 #endif
493 
494  for (i = 0; i < MAX_NUM_THREADS; i++) {
496  idmapper, 0, &tids[i].tid);
497  if (tids[i].handle == INVALID_HANDLE_VALUE) {
498  status = GetLastError();
499  eprintf("_beginthreadex failed %d\n", status);
500  goto out_pipe;
501  }
502  }
503 #ifndef STANDALONE_NFSD
504  // report the status to the service control manager.
506  goto out_pipe;
508 #else
509  //This can be changed to waiting on an array of handles and using waitformultipleobjects
510  dprintf(1, "Parent waiting for children threads\n");
511  for (i = 0; i < MAX_NUM_THREADS; i++)
513 #endif
514  dprintf(1, "Parent woke up!!!!\n");
515 
516 out_pipe:
517  CloseHandle(pipe);
518 out_idmap:
519  if (idmapper) nfs41_idmap_free(idmapper);
520 out_logs:
521 #ifndef STANDALONE_NFSD
522  close_log_files();
523 #endif
524  return;
525 }
#define CreateEvent
Definition: winbase.h:3562
#define StartService
Definition: winsvc.h:585
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
static bool_t check_for_files()
Definition: nfs41_daemon.c:168
DWORD dwCurrentState
Definition: winsvc.h:100
#define _CRTDBG_ALLOC_MEM_DF
Definition: crtdbg.h:55
#define _CRT_WARN
Definition: crtdbg.h:27
static int getdomainname()
Definition: nfs41_daemon.c:289
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:445
#define NFS41_USER_DEVICE_NAME_A
Definition: nfs41_driver.h:28
bool_t ldap_enable
Definition: nfs41_daemon.c:164
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
_CRTIMP uintptr_t __cdecl _beginthreadex(_In_opt_ void *_Security, _In_ unsigned _StackSize, _In_ unsigned(__stdcall *_StartAddress)(void *), _In_opt_ void *_ArgList, _In_ unsigned _InitFlag, _Out_opt_ unsigned *_ThrdAddr)
#define NO_ERROR
Definition: dderror.h:5
#define _CrtSetReportFile(t, f)
Definition: crtdbg.h:184
#define OpenService
Definition: winsvc.h:576
static char ** argv
Definition: ServiceArgs.c:11
#define FILE_SHARE_READ
Definition: compat.h:125
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE stop_event
Definition: nfs41_daemon.c:55
void set_debug_level(int level)
Definition: daemon_debug.c:35
GLenum GLclampf GLint i
Definition: glfuncs.h:14
void nfs41_server_list_init()
Definition: nfs41_server.c:48
#define dprintf
Definition: regdump.c:33
#define GENERIC_WRITE
Definition: nt_native.h:90
#define SERVICE_RUNNING
Definition: winsvc.h:24
static unsigned int WINAPI thread_main(void *args)
Definition: nfs41_daemon.c:84
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:576
DWORD NFS41D_VERSION
Definition: nfs41_daemon.c:42
smooth NULL
Definition: ftsmooth.c:416
void close_log_files()
Definition: daemon_debug.c:59
#define OPEN_EXISTING
Definition: compat.h:426
#define IOCTL_NFS41_START
Definition: nfs41_driver.h:43
#define _CRTDBG_LEAK_CHECK_DF
Definition: crtdbg.h:60
#define OpenSCManager
Definition: winsvc.h:575
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI QueryServiceStatus(SC_HANDLE hService, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:2787
#define _CRTDBG_MODE_FILE
Definition: crtdbg.h:32
GLenum GLsizei len
Definition: glext.h:6722
#define _CRTDBG_FILE_STDERR
Definition: crtdbg.h:40
#define GENERIC_READ
Definition: compat.h:124
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
static bool_t parse_cmdlineargs(int argc, TCHAR *argv[], nfsd_args *out)
Definition: nfs41_daemon.c:205
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
uint32_t * LPDWORD
Definition: typedefs.h:57
void open_log_files()
Definition: daemon_debug.c:40
int nfs41_idmap_create(struct idmap_context **context_out)
Definition: idmap.c:803
void exit(int exitcode)
Definition: _exit.c:33
#define INFINITE
Definition: serial.h:102
static TfClientId tid
#define _CrtSetDbgFlag(f)
Definition: crtdbg.h:192
void nfs41_idmap_free(struct idmap_context *context)
Definition: idmap.c:865
#define _CrtSetReportMode(t, f)
Definition: crtdbg.h:183
BOOL ReportStatusToSCMgr(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint)
Definition: service.c:240
#define MAX_NUM_THREADS
Definition: nfs41_daemon.c:41
Definition: ps.c:97

◆ ServiceStop()

VOID ServiceStop ( )

Definition at line 156 of file nfs41_daemon.c.

Referenced by ControlHandler(), and service_ctrl().

157 {
158  if (stop_event)
160 }
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
HANDLE stop_event
Definition: nfs41_daemon.c:55