ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a C++ application that I wrote. Due to the special nature of this program, it is not intended to be invoked directly by the user, but instead there is a Perl script which does some important pre-processing for calling the C++ application.
Is there a way that I can have the C++ application check that it was called by this Perl script? (I googled and didn't find an answer). Currently I do a cheap trick where the Perl script sends an undocumented command line argument to the application, and the application will refuse to run unless it has been given that argument (so a user can technically still invoke the application directly). Thanks in advance.
Hmmm, that's a tough problem...if Perl spawns new programs as child processes, maybe you could have the program find its parent process with the entries in /proc, then make sure that the command line of the parent process (in /proc/[process_num]/stat) has 'perl' (or whatever the name of the executable is) in it? Sort of a nasty hack, but I guess it's more secure than relying on the command line option remaining undocumented. It won't work, however, if processes spawned by Perl have only init as a parent.
Why not use a semaphore? Have your Perl app "touch" some file and your app check for that file's existence. You could even check the the "creation time" for the file was reasonably close to that of the start of the C app.
Last edited by PTrenholme; 03-29-2006 at 02:16 PM.
Hmmm, that's a tough problem...if Perl spawns new programs as child processes, maybe you could have the program find its parent process with the entries in /proc, then make sure that the command line of the parent process (in /proc/[process_num]/stat) has 'perl' (or whatever the name of the executable is) in it? Sort of a nasty hack, but I guess it's more secure than relying on the command line option remaining undocumented. It won't work, however, if processes spawned by Perl have only init as a parent.
It doesn't spawn it as a new child process (the invocations of the application also need to run on a distributed computing cluster). I wanted to avoid a Linux-specific solution to the problem, because the app is designed to be portable.
Quote:
Originally Posted by PTrenholme
Why not use a semaphore? Have your Perl app "touch" some file and your app check for that file's existence. You could even check the the "creation time" for the file was reasonably close to that of the start of the C app.
This Perl script may execute the application multiple times in one run through the script, and it also does some amount of computation before the program is run (parses configuration files).
Thanks for the suggestions. I just wanted to make sure there wasn't some easy method for doing this that I wasn't aware of. Since it doesn't sound like there is an easy solution, I think my curent method will do the job.
[snip]This Perl script may execute the application multiple times in one run through the script, and it also does some amount of computation before the program is run (parses configuration files).
[snip]
Well, you could still use a file to pass a "token" to the C program (generated by some cryptic process) which the C program needs to "match" before it would run. Something as simple as an XOR with a key might work to discourage casual use of the code. Yes, "touch" is *NIX specific, but files are not.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.