execv()

execv()

Post by Sam » Sun, 06 Jul 2003 03:54:13



I'm wodering how to send email without system(). Can't figure out the way
passing
 char *msgbody to /bin/mail in execv() in a linux box. any way to do it or
have to use other command. My boss thinks system() is no good, btw.

TIA

sam

 
 
 

execv()

Post by Jens.Toerr.. » Sun, 06 Jul 2003 04:17:29



> I'm wodering how to send email without system(). Can't figure out the way
> passing
>  char *msgbody to /bin/mail in execv() in a linux box. any way to do it or
> have to use other command. My boss thinks system() is no good, btw.

It's beyond me way your boss would assume that sytem() is "no good",
but if he pays you to reinvent the wheel... But what do you want to
pass a char pointer to an exec'ed program for? It's going to point
to nothing reasonable in the newly created process anyway. You would
probably better off doing something like this:

1. Create a pipe using pipe(2)
2. Install a handler to catch SIGCHLD signals to avoid a zombie
3. fork(2)

In the child now do:

4C: close(2) write of pipe
5C: call dup2(2) with the read end of the pipe and STDIN as the
    arguments,
6C: call execcv() to replace the childs code by the one of /bin/mail
    with the appropriate command line arguments, i.e.

    const char *my_args[ 5 ];

        my_args[ 0 ] = "/bin/mail";
        my_args[ 1 ] = "-s"
    my_args[ 2 ] = "The subject line"

    my_args[ 4 ] = NULL;

    execv( my_args[ 0 ], my_args );

In the parent you do

4P: close(2) the read end of pipe
5P: copy the message using write(2) to the write end of the pipe
6P: close(2) the write end of the pipe

That's basically everything you need. Things would be even simpler
if you are allowed to use popen(3) and pclose(3), then all you
need to call popen() with the mail-command, then write to the
newly created stream and finally close it.

                                Regards, Jens
--
      _  _____  _____

  _  | |  | |    | |
 | |_| |  | |    | |          http://www.physik.fu-berlin.de/~toerring
  \___/ens|_|homs|_|oerring

 
 
 

execv()

Post by David Schwart » Sun, 06 Jul 2003 10:04:26



Quote:> I'm wodering how to send email without system(). Can't figure out the way
> passing
>  char *msgbody to /bin/mail in execv() in a linux box. any way to do it or
> have to use other command. My boss thinks system() is no good, btw.

    Get a copy of any good book on UNIX programming. Read the section on
using pipes in conjunction with fork/exec. You can probably get away with
using 'popen'.

    Comments like "system() is no good" are meaningless. Without citing a
specific problem or type of problem, he could mean that 'system()' is no
good for frying eggs.

    DS

 
 
 

execv()

Post by Fritz » Thu, 10 Jul 2003 00:33:48



>     Comments like "system() is no good" are meaningless.

He might be concerned about potential security problems.  system()
invokes the shell.

RFM
--
To reply, translate domain from l33+ 2p33|< to alpha.
                4=a  0=o  3=e  +=t

 
 
 

execv()

Post by Villy Kru » Thu, 10 Jul 2003 17:08:08


On Tue, 8 Jul 2003 15:33:48 +0000 (UTC),


>>     Comments like "system() is no good" are meaningless.

>He might be concerned about potential security problems.  system()
>invokes the shell.

So he should have explained that.  Most of us have lost the ability to
mind read long time ago.

Villy

 
 
 

1. lpd: cannot execv .. printer filters

Slackware 4.0 setup right off the CD, 2.0.6 kernel.

Firstly, I've been running a Linux box for very long time and am
neither blushing virgin nor newbiw. Nevertheless I can't get lpd
filters to work.

The lpd system works fine when sending "raw" files to the printer..
provided I don't have an if: filter in printcap. When I do, I'm
seeing the following in the syslog:

Jun 23 18:23:08 musica lpd[354]: cannot execv /var/spool/lp1/test/input_filter

What am I looking for???

Here's the relevant printcap entry:

test|testnec:\
        :lp=/dev/null:\
        :sd=/var/spool/lp1/test:\
        :lf=/var/spool/lp1/test/errs:\
        :if=/var/spool/lp1/test/input_filter:\
        :mx#0:\
        :sh:

Here are the relevant spooler permissions:

drwx------   2 root     lp           1024 Jun 23 18:23 test/

/var/spool/lp1/test:
total 3
-rw-r--r--   1 root     lp             18 Jun 23 18:23 lock
-rw-rw-r--   1 root     lp             27 Jun 23 18:23 status
-rwxr-xr-x   1 root     lp            222 Jun 22 19:19
input_filter*
-rw-r--r--   1 root     lp              0 Jun 19 12:40 errs

Here is input_filter:

#/bin/sh
echo ------------------------------- >>/tmp/test.nec
date                                 >>/tmp/test.nec
echo ------------------------------- >>/tmp/test.nec
cat                                  >>/tmp/test.nec

Obviously this is a trivial filter.. makes no difference, I get
that same "cannot execv" error in syslog.

What am I looking for?
--


  Richard J. Wyble

2. Can you create your own custom boot floppy?

3. setting environment before calling execv()

4. snmp manager?

5. Print filter error: lpd[10296]: cannot execv

6. RedHat finds SB16 but not AWE

7. Beyond execv()

8. how do I open tektronix window on AIX3.1 ?

9. Memory allocation and execv

10. C++ - Alternatives for execv() & friends

11. cannot execv /var/spool/lpd filter

12. please, urgent, EXECV, how it's running ?!?

13. execv failed on woody