From owner-freebsd-questions Fri Dec 20 1:16:30 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 8F5BE37B401 for ; Fri, 20 Dec 2002 01:16:28 -0800 (PST) Received: from rly-ip01.mx.aol.com (rly-ip01.mx.aol.com [205.188.156.49]) by mx1.FreeBSD.org (Postfix) with ESMTP id A036143EDC for ; Fri, 20 Dec 2002 01:16:27 -0800 (PST) (envelope-from aburke@nullplusone.com) Received: from logs-mtc-tf.proxy.aol.com (logs-mtc-tf.proxy.aol.com [64.12.103.5]) by rly-ip01.mx.aol.com (v83.35) with ESMTP id RELAYIN1-1220041602; Fri, 20 Dec 2002 04:16:02 -0500 Received: from thebe (ACA3273D.ipt.aol.com [172.163.39.61]) by logs-mtc-tf.proxy.aol.com (8.10.0/8.10.0) with ESMTP id gBK9E0m272750 for ; Fri, 20 Dec 2002 04:14:00 -0500 (EST) From: "Aaron Burke" To: Subject: RE: Problems with a C application that changes users and run 'screen -x' Date: Fri, 20 Dec 2002 01:13:58 -0800 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Importance: Normal X-Apparently-From: ImOptimum@aol.com 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 > 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: This is as I expected. And I dont know of a way to get around it. > > > 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. I dont think that this will work. The super-user has nothing to do with the process that needs to be run. The user that logs in is not privliged, and the account that he is becomming is not privlidged either. > > 2. Fix your program by removing the bad use of `&'. Done. Thanks for the comment on this. I noticed a warning from g++ about this today. > > 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. How would I do this with exec. According to the man page for exec I have only a few options. int execl(const char *path, const char *arg, ...); int execlp(const char *file, const char *arg, ...); int execle(const char *path, const char *arg, ...); int exect(const char *path, char *const argv[], char *const envp[]); int execv(const char *path, char *const argv[]); int execvp(const char *file, char *const argv[]); Can you point me to the right documentation to learn about the exec functions provided by ? Allthough I am not familiar with unistd.h at all, I did do a little bit of expermentation. Here is my new code: #include #include #include int main(int argc, char* pszArgs[]) { int result, result2; result= execlp("/usr/bin/su", "ppp", "-m"); result2=execlp("/usr/local/bin/screen", "-x"); return result + result2; } bash-2.05$ g++ run-ppp.c bash-2.05$ ./a.out bash-2.05$ I am a little supprised that nothing appeared to have happened. Perhaps I am running these improperly. Am I using the correct exec command? Can you demonstrate how this should work? What else could execlp(args) needs to say? > > - Giorgos > Thanks for your time. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message