cron allowed to interact with desktop ?

Igor Pechtchanski pechtcha@cs.nyu.edu
Fri May 9 13:58:00 GMT 2003


On Fri, 9 May 2003, Corinna Vinschen wrote:
> On Thu, May 08, 2003 at 04:48:29PM -0400, Igor Pechtchanski wrote:
> > Also, please thoughtfully consider the attached patch for cygrunsrv... ;-)
> > Igor
>> I do. Thanks for the patch, it looks good. However, I can't apply it
> cleanly to the current version from CVS, even with patch'es -l option.
>> Would you mind to create a new patch relative to current CVS?
>> Thanks,
> Corinna

Corinna,
Yeah, I was still working off the 0.95-1 sources... Thanks for prompting
me to get off my lazy ass and get the CVS version checked out.
FWIW, the previous patch failed because of a new flag (-Q) in CVS.
New patch attached. Same ChangeLog.
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
 |\ _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`' -. ;-;;,_		igor@watson.ibm.com
 |,4- ) )-,_. ,\ ( `'-'		Igor Pechtchanski
 '---''(_/--' `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-. Meow!
Knowledge is an unending adventure at the edge of uncertainty.
 -- Leto II
-------------- next part --------------
Index: crit.cc
===================================================================
RCS file: /cvs/cygwin-apps/cygrunsrv/crit.cc,v
retrieving revision 1.2
diff -u -p -r1.2 crit.cc
--- crit.cc	23 Jun 2001 00:10:54 -0000	1.2
+++ crit.cc	9 May 2003 13:51:42 -0000
@@ -70,7 +70,7 @@ set_service_status (DWORD state, DWORD c
 }
 
 void
-set_service_controls_accepted (bool accept_shutdown)
+set_service_controls_accepted (bool accept_shutdown, bool interactive_process)
 {
 EnterCriticalSection (&ssc);
 if (ssh)
@@ -78,6 +78,8 @@ set_service_controls_accepted (bool acce
 ss.dwControlsAccepted = SERVICE_ACCEPT_STOP;
 if (accept_shutdown)
 	ss.dwControlsAccepted |= SERVICE_ACCEPT_SHUTDOWN;
+ if (interactive_process)
+	ss.dwServiceType |= SERVICE_INTERACTIVE_PROCESS;
 SetServiceStatus(ssh, &ss);
 }
 LeaveCriticalSection (&ssc);
Index: crit.h
===================================================================
RCS file: /cvs/cygwin-apps/cygrunsrv/crit.h,v
retrieving revision 1.2
diff -u -p -r1.2 crit.h
--- crit.h	23 Jun 2001 00:10:54 -0000	1.2
+++ crit.h	9 May 2003 13:51:42 -0000
@@ -29,6 +29,6 @@ extern void set_service_status (DWORD st
 				DWORD check_point = 0,
 		 DWORD wait_hint = 0,
 				DWORD exit_code = NO_ERROR);
-extern void set_service_controls_accepted(bool shutdown);
+extern void set_service_controls_accepted(bool shutdown, bool interactive);
 
 #endif /* _CRIT_H */
Index: cygrunsrv.README
===================================================================
RCS file: /cvs/cygwin-apps/cygrunsrv/cygrunsrv.README,v
retrieving revision 1.6
diff -u -p -r1.6 cygrunsrv.README
--- cygrunsrv.README	11 Mar 2002 11:56:42 -0000	1.6
+++ cygrunsrv.README	9 May 2003 13:51:42 -0000
@@ -243,6 +243,13 @@ application a short time to clean up and
 each Cygwin process also sends SIGHUP to itself (implicitly) during
 system shutdown.
 
+-------------------------------
+-i, --interactive
+
+ Optional flag that allows cygrunsrv to interact with the desktop.
+When in effect, cygrunsrv can open windows and pop up message boxes.
+Equivalent to the "Allow service to interact with desktop" box.
+
 **********************************************
 General Notes:
 
Index: cygrunsrv.cc
===================================================================
RCS file: /cvs/cygwin-apps/cygrunsrv/cygrunsrv.cc,v
retrieving revision 1.13
diff -u -p -r1.13 cygrunsrv.cc
--- cygrunsrv.cc	24 Apr 2003 08:36:05 -0000	1.13
+++ cygrunsrv.cc	9 May 2003 13:51:43 -0000
@@ -66,17 +66,19 @@ struct option longopts[] = {
 { "stdout", required_argument, NULL, '1' },
 { "stderr", required_argument, NULL, '2' },
 { "shutdown", no_argument, NULL, 'o' },
+ { "interactive", no_argument, NULL, 'i' },
 { "help", no_argument, NULL, 'h' },
 { "version", no_argument, NULL, 'v' },
 { 0, no_argument, NULL, 0 }
 };
 
-char *opts = "I:R:S:Q:E:p:a:c:e:d:f:ou:w:t:s:y:0:1:2:hv";
+char *opts = "I:R:S:Q:E:p:a:c:e:d:f:ou:w:t:s:y:0:1:2:ihv";
 
 char *appname;
 char *svcname;
 DWORD termsig;
 DWORD shutdown;
+DWORD interactive;
 
 enum action_t {
 Undefined,
@@ -129,7 +131,7 @@ int
 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)
+		 const char *in_stderr, DWORD shutdown, DWORD interactive)
 {
 HKEY srv_key = NULL;
 HKEY env_key = NULL;
@@ -204,6 +206,11 @@ install_registry_keys (const char *name,
 		 (const BYTE *) &shutdown,
 		 sizeof(DWORD)) != ERROR_SUCCESS)
 err_out (RegSetValueEx);
+ if (interactive)
+ if (RegSetValueEx (srv_key, PARAM_INTERACT, 0, REG_DWORD,
+		 (const BYTE *) &interactive,
+		 sizeof(DWORD)) != ERROR_SUCCESS)
+ err_out (RegSetValueEx);
 RegFlushKey (srv_key);
 
 out:
@@ -274,7 +281,7 @@ int
 get_reg_entries (const char *name, char *&path, char *&args, char *&dir,
 		 env_t *&env, DWORD *termsig_p,
 		 char *&stdin_path, char *&stdout_path, char *&stderr_path,
-		 DWORD *shutdown_p)
+		 DWORD *shutdown_p, DWORD *interactive_p)
 {
 HKEY srv_key = NULL;
 HKEY env_key = NULL;
@@ -314,6 +321,11 @@ get_reg_entries (const char *name, char 
 		 (BYTE *) shutdown_p,
 		 (size = sizeof(*shutdown_p), &size)) != ERROR_SUCCESS)
 *shutdown_p = 0; // the default
+ /* Get (optional) interactive flag. */
+ if (RegQueryValueEx (srv_key, PARAM_INTERACT, 0, &type,
+		 (BYTE *) interactive_p,
+		 (size = sizeof(*interactive_p), &size)) != ERROR_SUCCESS)
+ *interactive_p = 0; // the default
 /* Get (optional) stdin/stdout/stderr redirection files. */
 if ((ret = get_opt_string_entry (srv_key, PARAM_STDIN, stdin_path)))
 goto out;
@@ -476,7 +488,7 @@ eval_arglist (const char *path, char *ar
 /* Installs cygrunsrv as service `name' with display name `disp'. */
 int
 install_service (const char *name, const char *disp, type_t type,
-		 char *user, char *pass, char **deps)
+		 char *user, char *pass, char **deps, int interactive)
 {
 char mypath[MAX_PATH];
 SC_HANDLE sm = (SC_HANDLE) 0;
@@ -584,7 +596,8 @@ install_service (const char *name, const
 }
 /* Try to create service. */
 if (!(sh = CreateService (sm, name, disp, SERVICE_ALL_ACCESS,
-			 SERVICE_WIN32_OWN_PROCESS,
+			 SERVICE_WIN32_OWN_PROCESS |
+			 (interactive ? SERVICE_INTERACTIVE_PROCESS : 0),
 			 type == Auto ? SERVICE_AUTO_START
 			 		 : SERVICE_DEMAND_START,
 			 SERVICE_ERROR_NORMAL, mypath, NULL, NULL,
@@ -1043,14 +1056,14 @@ service_main (DWORD argc, LPSTR *argv)
 char *stderr_path = NULL;
 if (err = get_reg_entries (svcname, path, args, dir, env, &termsig,
 			 stdin_path, stdout_path, stderr_path,
-			 &shutdown))
+			 &shutdown, &interactive))
 {
 syslog_starterr ("get_reg_entries", err);
 set_service_status (SERVICE_STOPPED, 0, 0, err);
 return;
 }
 
- set_service_controls_accepted ( shutdown );
+ set_service_controls_accepted ( shutdown, interactive );
 report_service_status ();
 
 /* Step 2: Further preparations:
@@ -1177,6 +1190,7 @@ main (int argc, char **argv)
 char *in_stdout = NULL;
 char *in_stderr = NULL;
 int in_shutdown = 0;
+ int in_interactive = 0;
 
 appname = argv[0];
 
@@ -1278,6 +1292,13 @@ main (int argc, char **argv)
 	 return error (OnlyOneShutdown);
 	in_shutdown = 1;
 	break;
+ case 'i':
+	if (action != Install)
+	 return error (InteractiveNotAllowed);
+	if (in_interactive)
+	 return error (OnlyOneInteractive);
+	in_interactive = 1;
+	break;
 case 's':
 	if (action != Install)
 	 return error (SigNotAllowed);
@@ -1366,12 +1387,12 @@ main (int argc, char **argv)
 in_type = Auto;
 if (!is_executable (in_path))
 return error (InvalidPath);
- if (ret = install_service (in_name, in_disp, in_type, in_user, in_pass, in_deps))
+ if (ret = install_service (in_name, in_disp, in_type, in_user, in_pass, in_deps, in_interactive))
 return ret;
 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))
+				 in_shutdown, in_interactive))
 remove_service (in_name);
 return ret;
 break;
Index: cygrunsrv.h
===================================================================
RCS file: /cvs/cygwin-apps/cygrunsrv/cygrunsrv.h,v
retrieving revision 1.8
diff -u -p -r1.8 cygrunsrv.h
--- cygrunsrv.h	26 Feb 2002 11:22:29 -0000	1.8
+++ cygrunsrv.h	9 May 2003 13:51:43 -0000
@@ -33,6 +33,7 @@
 #define PARAM_ENVIRON	"Environment"
 #define PARAM_TERMSIG	"TermSig"
 #define PARAM_SHUTDOWN	"Shutdown"
+#define PARAM_INTERACT	"Interactive"
 
 #define DEF_STDIN_PATH	"/dev/null"
 #define DEF_LOG_PATH	"/var/log/"
Index: utils.cc
===================================================================
RCS file: /cvs/cygwin-apps/cygrunsrv/utils.cc,v
retrieving revision 1.10
diff -u -p -r1.10 utils.cc
--- utils.cc	24 Apr 2003 08:36:05 -0000	1.10
+++ utils.cc	9 May 2003 13:51:43 -0000
@@ -61,6 +61,8 @@ char *reason_list[] = {
 "Each of --std{in,out,err} is allowed only once",
 "--shutdown is only allowed with --install",
 "Only one --shutdown is allowed",
+ "--interactive is only allowed with --install",
+ "Only one --interactive is allowed",
 "Trailing commandline arguments not allowed",
 "You must specify one of the `-IRSE' options",
 "Error installing a service",
@@ -167,6 +169,7 @@ usage ()
 uprint (" -2, --stderr <file> Optional output file used for stderr redirection.");
 uprint (" Default is /var/log/<svc_name>.log.");
 uprint (" -o, --shutdown Stop service application during system shutdown.");
+ uprint (" -i, --interactive Allow service to interact with the desktop.");
 uprint ("\nInformative output:");
 uprint (" -h, --help print this help, then exit.");
 uprint (" -v, --version print cygrunsrv program version number, then exit.");
Index: utils.h
===================================================================
RCS file: /cvs/cygwin-apps/cygrunsrv/utils.h,v
retrieving revision 1.8
diff -u -p -r1.8 utils.h
--- utils.h	11 Mar 2002 11:56:42 -0000	1.8
+++ utils.h	9 May 2003 13:51:43 -0000
@@ -52,6 +52,8 @@ enum reason_t {
 OnlyOneIO,
 ShutdownNotAllowed,
 OnlyOneShutdown,
+ InteractiveNotAllowed,
+ OnlyOneInteractive,
 TrailingArgs,
 StartAsSvcErr,
 InstallErr,
-------------- next part --------------
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/


More information about the Cygwin mailing list

AltStyle によって変換されたページ (->オリジナル) /