Date: Thu, 19 Dec 2002 19:22:24 +0200 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Aaron Burke <aburke@nullplusone.com> 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> In-Reply-To: <NGBBLCIHCLNJAIGIFFHJEEOMCOAA.aburke@nullplusone.com> References: <NGBBLCIHCLNJAIGIFFHJEEOMCOAA.aburke@nullplusone.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2002-12-19 02:50, Aaron Burke <aburke@nullplusone.com> 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 <stdlib.h> > 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021219172224.GB985>