cron allowed to interact with desktop ?
Igor Pechtchanski
pechtcha@cs.nyu.edu
Thu May 8 20:48:00 GMT 2003
On Thu, 8 May 2003, Corinna Vinschen wrote:
> On Thu, May 08, 2003 at 11:10:07AM +0200, a12 wrote:
> > Hi gurus,
> >
> > Default install instruction for cron is:
> > cygrunsrv -I cron -p /usr/sbin/cron -a -D
> >
> > As I want cron to execute Windows applications (i.e. AutoIT),
> > I have set in Windows Administrative Tools -> Services -> cron,
> > Allow service to interact with desktop
> >
> > Is there an appriopriate paramter for cygrunsrv that will do
> > it ?
>
> cygrunsrv --help and /usr/doc/Cygwin/cygrunsrv.README both show, the
> answer is "no".
>
> PTC (see http://cygwin.com/acronyms/),
> Corinna
Corinna,
FYI, you can use the acronym as the anchor, e.g.,
http://cygwin.com/acronyms/#PTC
Also, please thoughtfully consider the attached patch for cygrunsrv... ;-)
Igor
==============================================================================
2003-05-08 Igor Pechtchanski <pechtcha@cs.nyu.edu>
* crit.cc: (set_service_controls_accepted) Add an
interactive_process parameter.
* crit.h: (set_service_controls_accepted) Ditto.
* cygrunsrv.cc: (longopts, opts) Add an "--interactive"
option.
(interactive) New global variable.
(install_registry_keys) Add an interactive parameter.
(get_reg_entries) Add an interactive_p parameter.
(install_service) Add an interactive parameter.
(service_main) Pass the interactive flag to get_reg_entries
and set_service_controls_accepted.
(main) Process the "--interactive" flag.
* cygrunsrv.cc: (PARAM_INTERACT) New registry key.
* utils.h: (reason_t) Add InteractiveNotAllowed and
OnlyOneInteractive values.
* utils.cc: (reason_list) Add description strings for
the InteractiveNotAllowed and OnlyOneInteractive values.
(usage) Add description of the "--interactive" option.
* cygrunsrv.README: Add description of the "--interactive"
option.
--
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 --------------
--- ./crit.cc-orig 2003-02-18 16:13:53.000000000 -0500
+++ ./crit.cc 2003-05-08 16:15:21.000000000 -0400
@@ -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);
--- ./crit.h-orig 2001-06-22 20:10:54.000000000 -0400
+++ ./crit.h 2003-05-08 16:22:51.000000000 -0400
@@ -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 */
--- ./cygrunsrv.cc-orig 2003-02-18 16:13:53.000000000 -0500
+++ ./cygrunsrv.cc 2003-05-08 16:35:07.000000000 -0400
@@ -65,17 +65,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:E:p:a:c:e:d:f: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:ihv";
char *appname;
char *svcname;
DWORD termsig;
DWORD shutdown;
+DWORD interactive;
enum action_t {
Undefined,
@@ -127,7 +129,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;
@@ -202,6 +204,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:
@@ -272,7 +279,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;
@@ -312,6 +319,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;
@@ -474,7 +486,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;
@@ -582,7 +594,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,
@@ -926,14 +939,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:
@@ -1060,6 +1073,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];
@@ -1155,6 +1169,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);
@@ -1243,12 +1264,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;
--- ./cygrunsrv.h-orig 2002-02-26 06:22:29.000000000 -0500
+++ ./cygrunsrv.h 2003-05-08 16:07:13.000000000 -0400
@@ -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/"
--- ./cygrunsrv.README-orig 2002-02-26 06:22:29.000000000 -0500
+++ ./cygrunsrv.README 2003-05-08 16:20:15.000000000 -0400
@@ -235,6 +235,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:
--- ./utils.cc-orig 2002-02-26 06:22:29.000000000 -0500
+++ ./utils.cc 2003-05-08 15:59:57.000000000 -0400
@@ -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",
@@ -165,6 +167,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.");
--- ./utils.h-orig 2002-02-26 06:22:29.000000000 -0500
+++ ./utils.h 2003-05-08 15:38:36.000000000 -0400
@@ -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