--fork option does not execute post receive command -xcs

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
mikota
Posts: 6
Joined: Mon, 2006-02-27, 17:24
Location: Linz, Austria

--fork option does not execute post receive command -xcs

#1 Post by mikota »

Hi OFFIS Team!

After receiving a study, the command specified with the -xcs option will not be executed after the specified timeout -tos when the --fork option is given.

Example:
bin/storescp --fork -od /project/gateway/images/TELERAD_IN -dhl -ss study -xcs ./studycomplete.pl TELERAD_IN #p #a #c -rns -tos 30 50082

When I start the same program without the --fork option, the command will be executed.

It seems the the --fork option doesn't trigger the -xcs event.

Thank you very much in advance for your help!

Alfred

gerhardh
Posts: 8
Joined: Tue, 2006-02-28, 17:10

RE: --fork option does not execute post receive command -xcs

#2 Post by gerhardh »

Hi Alfred, Hallo Offis Team,

I made one small modification to storescp.cc to
fix this problem ...

Here is a diff of my modified storescp.cc and storescp.cc_ORIG:

Code: Select all

pl@lirdiag1:~/work/dicomtests/dcmtk-3.5.4/dcmnet/apps> diff storescp.cc storescp.cc_ORIG
1116,1127c1116
<     if (DUL_processIsForkedChild())
<     {
<       // HG 2006.02.28   aber: wenn end of study timeout aktiviert ist ...
<       if( opt_endOfStudyTimeout != -1 && ! lastStudyInstanceUID.empty() )
<         {
<           if (opt_verbose) printf("HG: wait for endOfStudyTimeout in child ...\n");
<         }
<         else
<         {
<           break;
<         }
<     }
---
>     if (DUL_processIsForkedChild()) break;
Gerhard

mikota
Posts: 6
Joined: Mon, 2006-02-27, 17:24
Location: Linz, Austria

#3 Post by mikota »

Hi!

Using this code the fork option works under most circumstances. But there is a problem when a clients connects to storescp when storescp is in the timeout loop waiting for the end-of-study timeout. While this time no further connections are possible.

Any suggestions?

Thanks a lot in advance!

Alfred

gerhardh
Posts: 8
Joined: Tue, 2006-02-28, 17:10

RE: --fork option does not execute post receive command -xcs

#4 Post by gerhardh »

Hi Alfred, Hallo Offis Team,

after some more modifications to storescp.cc (from dcmtk-3.5.4),

the --eostudy-timeout
and the different --exec-on-... Options
work with --fork, too.

Additionally I implemented two new features:
- a new parameter #r to pass the "remote_host" of an Association
to the different --exec-on Scripts,

- a new --exec-on-sostudy (-xss) Switch (=StartOfStudy),
to execute a Script after receiving the first Object of a NEW Study

WARNING!
- this modified version will compile ONLY on linux,
cause i have no time / environment to check this with Windows.

You can find my modified storescp.cc here:
http://earchive.at/dcmtk-3.5.4

(all modifications are marked with: // HG: ... )

Gerhard
Last edited by gerhardh on Thu, 2006-06-01, 12:10, edited 2 times in total.

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1444
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#5 Post by Marco Eichelberg »

Thanks for this contribution. I have added it to the list of things to be merged into the next release.

Luuk
Posts: 8
Joined: Thu, 2005-08-18, 13:00

#6 Post by Luuk »

It was not to hard to adjust Gerhard's code to make it work under Windows (just use findfirst/findnext/findclose instead of opendir / closedir)

But then another issue arises. Using the next commandline is OK:
storescp --fork -xcr dosomething.bat 1000
To give the batch-file some parameters you can add for example #f and/or #p as follows
storescp --fork -xcr "dosomething.bat #p #f" 1000
The quotation marks are needed, else you'll get the error message "Too many parameters". The problem is that for the child process the quotation marks are lost. This results in the same error message if you start to send a DICOM-file.
So I changed dul.cxx a little. I "replaced" lines 1651 and 1652 with the following:

Code: Select all

    cmdLine += " \"";
    cmdLine += command_argv[i];
    cmdLine += "\"";
Now all parameters have quotation marks (but this is no problem, at least under Windows).

Luuk

rhinojunk
Posts: 10
Joined: Tue, 2006-03-14, 22:25

#7 Post by rhinojunk »

Luuk, thanks for the idea on the fix. I'm uneasy with quoting every argument, plus it makes enclosed escaped quotes behave different with/without the --fork option. The below code does the following.

1. Fixes the CreateProcess() security hole when the first argument is NULL as described at MSDN. http://msdn.microsoft.com/library/defau ... rocess.asp

2. If the argument contains a space, enclose it in quotes, and escape all sub-quotes. This should restrict adding quotes and escaping to only arguments which need it. Detecting/Re-escaping other characters might be advantageous as well.

3. If the argument does not contain a space, process like 3.5.4 (no escaping or quoting).


dul.cxx Line ~1649

Code: Select all

        // prepare the command line
        OFString cmdLine;
		OFString cmdLineTemp; // (rhinojunk) used to rebuild escaped quotes.
		size_t position; // (rhinojunk) used to rebuild escaped quotes.
        
		// (rhinojunk) Add quotes around storescp path per CreateProcess()
		// (rhinojunk) security notes on MSDN.
		cmdLine = "\"";
		cmdLine += command_argv[0];
		cmdLine += "\"";

		cmdLine += " --forked-child";
        for (int i=1; i < command_argc; ++i)
        {
			// (rhinojunk) If command_argv[i] contains a space, escape
			// (rhinojunk) enclosed double quotes and enclose in new quotes
			// (rhinojunk) for proper processing by child.
			OFString cmdLineTemp = command_argv[i];
			if (cmdLineTemp.find(" ", 0) != OFString_npos)
			{
				position = 0;
				while ((position = cmdLineTemp.find("\"",position)) != OFString_npos)
				{
					cmdLineTemp.insert(position, "\\");
					position = position + 2; // (rhinojunk) need to account for insert. 
				}
				cmdLine += " \"";
				cmdLine += cmdLineTemp;
				cmdLine += "\"";
			}
			else // (rhinojunk) no spaces found, do normal append.
			{
				cmdLine += " ";
				cmdLine += command_argv[i];
			}
        }

bmoloney
Posts: 10
Joined: Wed, 2011-09-07, 00:38

Re: --fork option does not execute post receive command -xcs

#8 Post by bmoloney »

It seems these fixes never made it into the 3.6.0 release. Is there any plan to merge these changes?

Thanks!

J. Riesmeier
DCMTK Developer
Posts: 2504
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: --fork option does not execute post receive command -xcs

#9 Post by J. Riesmeier »

As far as I remember, the "space quoting" thing has been fixed already. See this patch. Or, do you mean something else?

Btw, I personally do not like the whole Windows multi-process stuff (aka "fork") in the DCMTK. To me it looks like a bad hack ...

gotmikhail
Posts: 3
Joined: Thu, 2019-01-10, 15:10

Re: --fork option does not execute post receive command -xcs

#10 Post by gotmikhail »

What ever came from this?

The latest version, 3.6.4, still does not support `--exec-on-eostudy` and `--fork` simultaneously.

Basically, what are people using as the solution to receive from multiple sources at once, and know when receiving is completed?

I may be misunderstanding the benefit / need of `--fork` altogether.

(I've been "away" from the dcmtk community for about 5 years now, so there are a lot of things I'm catching up on)

J. Riesmeier
DCMTK Developer
Posts: 2504
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: --fork option does not execute post receive command -xcs

#11 Post by J. Riesmeier »

Nowadays, one would probably use the DcmStorageSCP class and extend it for handling multiple associations at a time (e.g. based on the thread-pool SCP class). The corresponding command line tool would then be "dcmrecv"...

PS: Welcome back!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest