Hi All...

The attached patch adds the ability for cygrunsrv to set the service 
description field in the registry.

Thanks,

...Karl


_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
diff -up old/cygrunsrv.cc new/cygrunsrv.cc
--- old/cygrunsrv.cc    Fri Oct 19 02:12:14 2001
+++ new/cygrunsrv.cc    Sat Feb 23 14:57:41 2002
@@ -55,6 +55,7 @@ struct option longopts[] = {
   { "chdir", required_argument, NULL, 'c' },
   { "env", required_argument, NULL, 'e' },
   { "disp", required_argument, NULL, 'd' },
+  { "desc", required_argument, NULL, 'f' },
   { "user", required_argument, NULL, 'u' },
   { "passwd", required_argument, NULL, 'w' },
   { "type", required_argument, NULL, 't' },
@@ -69,7 +70,7 @@ struct option longopts[] = {
   { 0, no_argument, NULL, 0 }
};

-char *opts = "I:R:S:E:p:a:c:e:d:ou:w:t:s:y:0:1:2:hv";
+char *opts = "I:R:S:E:p:a:c:e:d:f:ou:w:t:s:y:0:1:2:hv";

char *appname;
char *svcname;
@@ -123,20 +124,33 @@ eval_wait_time (register DWORD wait)
/* Installs the subkeys of the service registry entry so that cygrunsrv
    can determine what application to start on service startup. */
int
-install_registry_keys (const char *name, const char *path,
+install_registry_keys (const char *name, const char *desc, const char 
*path,
                       char *args, char *dir, env_t *env, DWORD termsig,
                       const char *in_stdin, const char *in_stdout,
                       const char *in_stderr, DWORD shutdown)
{
   HKEY srv_key = NULL;
   HKEY env_key = NULL;
+  HKEY desc_key = NULL;
   DWORD disp;
-  char param_key[MAX_PATH];
+  char reg_key[MAX_PATH];
   char *err_func;
   DWORD err = 0;

-  strcat (strcat (strcpy (param_key, SRV_KEY), name), PARAM_KEY);
-  if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, param_key, 0, "",
+  strcat (strcpy (reg_key, SRV_KEY), name);
+  if (desc)
+    {
+      if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, reg_key, 0,
+                        KEY_ALL_ACCESS, &desc_key) != ERROR_SUCCESS)
+        err_out (RegOpenKeyEx);
+      if (RegSetValueEx (desc_key, DESC, 0, REG_SZ,
+                         (const BYTE *) desc, strlen (desc) + 1) != 
ERROR_SUCCESS)
+        err_out (RegSetValueEx);
+      RegFlushKey (desc_key);
+    }
+
+  strcat (reg_key, PARAM_KEY);
+  if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, reg_key, 0, "",
                      REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
                      NULL, &srv_key, &disp) != ERROR_SUCCESS)
     err_out (RegCreateKeyEx);
@@ -193,6 +207,8 @@ install_registry_keys (const char *name,
out:
   if (env_key)
     RegCloseKey (env_key);
+  if (desc_key)
+    RegCloseKey (desc_key);
   if (srv_key)
     RegCloseKey (srv_key);
   return err == 0 ? 0 : error (InstallErr, err_func, err);
@@ -1029,6 +1045,7 @@ main (int argc, char **argv)
   int c;
   action_t action = Undefined;
   char *in_name = NULL;
+  char *in_desc = NULL;
   char *in_path = NULL;
   char *in_args = NULL;
   char *in_dir = NULL;
@@ -1124,6 +1141,13 @@ main (int argc, char **argv)
          return error (OnlyOneDisp);
        in_disp = optarg;
        break;
+      case 'f':
+       if (action != Install)
+          return error (DescNotAllowed);
+       if (in_desc)
+         return error (OnlyOneDesc);
+       in_desc = optarg;
+       break;
       case 'o':
        if (action != Install)
          return error (ShutdownNotAllowed);
@@ -1221,8 +1245,8 @@ main (int argc, char **argv)
         return error (InvalidPath);
       if (ret = install_service (in_name, in_disp, in_type, in_user, 
in_pass, in_deps))
         return ret;
-      if (ret = install_registry_keys (in_name, in_path, in_args, in_dir,
-                                      in_env, in_termsig,
+      if (ret = install_registry_keys (in_name, in_desc, in_path, in_args,
+                                      in_dir, in_env, in_termsig,
                                       in_stdin, in_stdout, in_stderr,
                                       in_shutdown))
         remove_service (in_name);
diff -up old/cygrunsrv.h new/cygrunsrv.h
--- old/cygrunsrv.h     Fri Jun 22 18:10:56 2001
+++ new/cygrunsrv.h     Sat Feb 23 15:05:28 2002
@@ -21,7 +21,8 @@
#ifndef _CYGRUNSRV_H
#define _CYGRUNSRV_H

-#define SRV_KEY                "SYSTEM\\CurrentControlSet\\Services\\"
+#define SRV_KEY                "SYSTEM\\CurrentControlSet\\Services\\"
+#define DESC            "Description"
#define PARAM_KEY       "\\Parameters"
#define PARAM_PATH      "AppPath"
#define PARAM_ARGS      "AppArgs"
diff -up old/utils.h new/utils.h
--- old/utils.h Fri Jun 22 18:10:56 2001
+++ new/utils.h Sat Feb 23 15:34:28 2002
@@ -56,6 +56,8 @@ enum reason_t {
   RemoveErr,
   StartErr,
   StopErr,
+  DescNotAllowed,
+  OnlyOneDesc,
   MaxReason            /* Always the last element */
};



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Reply via email to