From owner-freebsd-questions Thu Dec 19 13:32:11 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A351037B401 for ; Thu, 19 Dec 2002 13:32:09 -0800 (PST) Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id 87E2043E4A for ; Thu, 19 Dec 2002 13:32:03 -0800 (PST) (envelope-from keramida@ceid.upatras.gr) Received: from gothmog.gr (patr530-a180.otenet.gr [212.205.215.180]) by mailsrv.otenet.gr (8.12.6/8.12.6) with ESMTP id gBJLVxSs004158; Thu, 19 Dec 2002 23:32:00 +0200 (EET) Received: from gothmog.gr (gothmog [127.0.0.1]) by gothmog.gr (8.12.6/8.12.6) with ESMTP id gBJLVtXW001090; Thu, 19 Dec 2002 23:31:58 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Received: (from giorgos@localhost) by gothmog.gr (8.12.6/8.12.6/Submit) id gBJHMOGs001648; Thu, 19 Dec 2002 19:22:24 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Date: Thu, 19 Dec 2002 19:22:24 +0200 From: Giorgos Keramidas To: Aaron Burke Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Problems with a C application that changes users and run 'screen -x' Message-ID: <20021219172224.GB985@gothmog.gr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 2002-12-19 02:50, Aaron Burke wrote: > I have an application that simply logs in as another user and runs > "screen -x". The problem I am having with the followin code is that > the results of execution is a message from (I am guessing the shell) > saying that I dont have access to the "/dev/ttyp?" where ? is the > current virtual terminal that I am running on. > > Here is my application: > > #include > int main(int argc, char* pszArgs[]) > { > int result; > result= system("/usr/bin/su ppp -m --login -c " & > "/usr/local/bin/screen -x"); > return result; > } You are using the & operator in a very strange manner here. It most certainly doesn't work the way you might think it does. You should also avoid using system, if possible. > And here is the output: > bash-2.05$ ./a.out You're not running the executable as `root'. Since you are not the superuser, you do not have permissions to operate on the pseudo-tty that login attempts to work with, and this is why you get the following error message: > Cannot open your terminal '/dev/ttyp0' - please check. Three possibilities that you might wish to investigate further are: 1. Write a shell script that does the equivalent of the system() call you are using now. This should be fairly easy and will work fine if you execute the script from a root shell. 2. Fix your program by removing the bad use of `&'. 3. Avoid using system() which I vaguely recall being described with a lot of bad words in various places and use fork(), exec(), _exit(), waitpid() and exit() instead. - Giorgos To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message