961N/A/*
961N/A * CDDL HEADER START
961N/A *
961N/A * The contents of this file are subject to the terms of the
961N/A * Common Development and Distribution License, Version 1.0 only
961N/A * (the "License"). You may not use this file except in compliance
961N/A * with the License.
961N/A *
961N/A * You can obtain a copy of the license at
961N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
961N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
961N/A * See the License for the specific language governing permissions
961N/A * and limitations under the License.
961N/A *
961N/A * When distributing Covered Code, include this CDDL HEADER in each
961N/A * file and include the License file at
961N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
961N/A * add the following below this CDDL HEADER, with the fields enclosed
961N/A * by brackets "[]" replaced with your own identifying * information:
961N/A * Portions Copyright [yyyy] [name of copyright owner]
961N/A *
961N/A * CDDL HEADER END
961N/A *
961N/A *
3231N/A * Copyright 2008 Sun Microsystems, Inc.
6173N/A * Portions Copyright 2013 ForgeRock AS.
961N/A */
961N/A
1298N/A#include "common.h"
961N/A#include <errno.h>
961N/A#include <fcntl.h>
961N/A#include <io.h>
961N/A#include <stdio.h>
961N/A#include <sys/locking.h>
961N/A#include "EventLogMsg.h"
961N/A
961N/A#define MAX_SERVICE_NAME 256
961N/A
961N/A// ----------------------------------------------------
961N/A// Estimated time for a given operation (in ms).
961N/A// Note: if the estimated value is too short then the service controler
961N/A// may consider the service as not alive anymore! so the value
961N/A// must be as precise as possible (better have it too big rather
961N/A// than to small)
961N/A// ----------------------------------------------------
961N/A
961N/A#define TIMEOUT_NONE 0
961N/A#define TIMEOUT_CREATE_EVENT 5000
961N/A#define TIMEOUT_START_SERVICE 30000
961N/A#define TIMEOUT_STOP_SERVICE 30000
961N/A
961N/A// ----------------------------------------------------
961N/A// The first value to use for checkpoints
961N/A// ----------------------------------------------------
961N/A#define CHECKPOINT_FIRST_VALUE 1
961N/A
961N/A// ----------------------------------------------------
961N/A// Checkpoint value to use to let the SCM knows that there is
961N/A// no ongoing operation
961N/A// ----------------------------------------------------
961N/A#define CHECKPOINT_NO_ONGOING_OPERATION 0
961N/A
961N/A// ----------------------------------------------------
961N/A// Event Log Key.
961N/A// ----------------------------------------------------
961N/A#define EVENT_LOG_KEY "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s"
961N/A
961N/A// ----------------------------------------------------
961N/A// Max size of the registry key
961N/A// ----------------------------------------------------
961N/A#define MAX_REGISTRY_KEY 512
961N/A
961N/A// ----------------------------------------------------
961N/A// Max size of the binary to run the service
961N/A// ----------------------------------------------------
961N/A#define COMMAND_SIZE 2048
961N/A
961N/A#define SERVICE_ACCEPT_NONE 0
961N/A
961N/Atypedef struct {
961N/A char* serviceName; // the name of the service
961N/A char* displayName; // the display name of the service
961N/A char* cmdToRun; // the executable to run
961N/A } ServiceDescriptor;
961N/A
961N/Atypedef enum {
961N/A SERVICE_RETURN_OK, SERVICE_RETURN_ERROR, SERVICE_IN_USE,
961N/A SERVICE_NOT_IN_USE, DUPLICATED_SERVICE_NAME, SERVICE_ALREADY_EXISTS,
961N/A SERVICE_MARKED_FOR_DELETION
961N/A} ServiceReturnCode;
961N/A
961N/A
961N/AServiceReturnCode registerServiceHandler (char* serviceName,
961N/ALPHANDLER_FUNCTION serviceHandler, SERVICE_STATUS_HANDLE* serviceStatusHandle);
961N/AServiceReturnCode serviceNameInUse(char* serviceName);
969N/AServiceReturnCode createServiceName(char* serviceName, char* baseName);
961N/AServiceReturnCode getServiceList(ServiceDescriptor** serviceList,
961N/Aint *nbServices);
961N/AServiceReturnCode createServiceBinPath(char* serviceBinPath);
961N/AServiceReturnCode getServiceName(char* cmdToRun, char* serviceName);
961N/AServiceReturnCode updateServiceStatus (
961N/A DWORD statusToSet,
961N/A DWORD win32ExitCode,
961N/A DWORD serviceExitCode,
961N/A DWORD checkPoint,
961N/A DWORD waitHint,
961N/A SERVICE_STATUS_HANDLE *serviceStatusHandle
961N/A );
961N/Avoid serviceHandler(DWORD controlCode);
6173N/ABOOL getServiceStatus(char *serviceName, LPDWORD returnState);
961N/A