How to make an application to prevent itself from launching from the command line?
I have a binary which should be launched by a daemon; but when somebody tries to launch the binary from command line, I should error out stating "cannot be launched from command line".
Tried googling but in vain.
boomerang2711 0 Newbie Poster
Recommended Answers
Jump to PostAnother approach would be to see if stdin is attached to a real terminal. A process that is spawned by a daemon would have no stdin device, or it would be /dev/null.
Jump to PostIn C, you can
#include <unistd.h>
and then use thettyname(0)
function. It resturns a pointer to the terminal that fd 0 (stdin) is connected with, or NULL if it isn't attached to a terminal (or there is an error) - checking errno for ENOTTY will tell you …
All 5 Replies
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster
boomerang2711 commented: never mind.. i got it! +0
boomerang2711 0 Newbie Poster
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster
boomerang2711 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.