Prev: Create staple diagrams from a text file (containing numbers)from command line?
Next: using --prefix= in my code
From: Rainer Weikusat on 5 Feb 2010 05:45 Rich <rtillmore(a)gmail.com> writes: > On Feb 4, 7:16�am, Rainer Weikusat wrote: >> The exec replaces the program a process is currently running with a >> new program. What you want requires the new program in a new process, >> so you need to fork one first and then wait for its >> termination. [...] > So I am getting I should use fork and avoid system and popen as they > have potential security issues. They both start an additional shell process and this is something which should (in my opinion) be avoided except if features of the shell beyond 'it can start programs' are actually going to be used. Depending on the context, using the shell in this way may have security issues because its operation is partially controlled by various environment variables which may have been provided by an untrusted party, meaning, using the shell in this way is (also IMO) a bad habit to get into, especially since sanitizing the environment selectively isn't portably possible, because unsetenv is broken on FreeBSD (more precisely, unsetenv can be caused to abort processing before reaching variables which will later be found by getenv, to be fixed 'after a more thorough security audit has been conducted' -- since 2009/12/07). I usually use fork, because this is (again, IMO) the easiest and most flexible option (I also usually don't want to halt execution of the parent process until "somewhen").
From: Ben Bacarisse on 5 Feb 2010 09:12 Rich <rtillmore(a)gmail.com> writes: > On Feb 3, 9:11 pm, Ben Bacarisse wrote: >> Rich writes: >> > On Feb 3, 7:48 pm, Ben Bacarisse wrote: >> <snip> >> >> I missed the loop the first time round. The exec functions replace >> your process with a new one. Once you exec your program is gone. You >> probably want system(3) or popen(3). >> >> BTW, what source are you using for learning this stuff? Asking in >> Usenet at each stage is likely to be slower than a good text about >> Unix programming. > > I will look into popen and system. I am using my 15 year old C book. > It doesn't mention exec, popen, or system. I found the thread that > listed some free C books and The C Book doesn't mention exec either. > It is probably time to buy a new book :) You need a Unix book, not a C one (though both can't hurt). Stevens[1] is often sited but I don't know how much C you need to get through it. [1] http://www.kohala.com/start/apue.html -- Ben.
From: John Gordon on 5 Feb 2010 10:30 In <a5fbfcd2-b6c5-411e-96bd-8d22b1e9ccf7(a)r19g2000yqb.googlegroups.com> Rich <rtillmore(a)gmail.com> writes: > I will look into popen and system. I am using my 15 year old C book. > It doesn't mention exec, popen, or system. I found the thread that Those things aren't strictly part of the C language, so a C language book won't cover them. You probably want a Unix or Posix programming book, which will cover things like this. -- John Gordon A is for Amy, who fell down the stairs gordon(a)panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies"
From: Rich on 6 Feb 2010 16:44
On Feb 5, 4:45 am, Rainer wrote: > Rich writes: > > On Feb 4, 7:16 am, Rainer wrote: > >> The exec replaces the program a process is currently running with a > >> new program. What you want requires the new program in a new process, > >> so you need to fork one first and then wait for its > >> termination. > > [...] > > > So I am getting I should use fork and avoid system and popen as they > > have potential security issues. > > I usually use fork, because this is (again, IMO) the easiest and most > flexible option (I also usually don't want to halt execution of the > parent process until "somewhen"). I added a fork and had defunct processes. I added a wait and no more zombies. Thank you everyone. |