Linux-Bulgaria.ORG
навигация

 

начало

пощенски списък

архив на групата

семинари ...

документи

как да ...

 

 

Предишно писмо Следващо писмо Предишно по тема Следващо по тема По Дата По тема (thread)

Re: lug-bg: "C" wapros


  • Subject: Re: lug-bg: "C" wapros
  • From: gf@xxxxxxxxxx (gf@xxxxxxxxxx)
  • Date: Wed, 17 May 2000 21:11:02 GMT



10x za help-a, az izplzvah tova i rabotata trygna, wzeh ot man page-a na
system   waw secure programming FAQ-a pishe *Never* use system ama
to ako samo tova mi e kusura na programa zdrave da e ;)

int run_system (const char *command) {
int pid, status;

   if (command == 0)
       return 1;
   pid = fork();
   if (pid == -1)
       return -1;
   if (pid == 0) {
       char *argv[4];
       argv[0] = "sh";
       argv[1] = "-c";
       argv[2] = command;
       argv[3] = 0;
       execve("/bin/sh", argv, environ);
       exit(127);
   }
   do {
       if (waitpid(pid, &status, 0) == -1) {
           if (errno != EINTR)
               return -1;
           } else
               return status;
       } while(1);
}

Luben Karavelov writes:

> On Wed, May 17, 2000 at 10:04:59AM +0300, Valery Dachev wrote:
> > On Tue, 16 May 2000, luben karavelov wrote:
> > 
> > > Georgi Chorbadzhiyski wrote:
> > > > 
> > > > Ako mozhe niakoi po svetnat da pomogne. Imam slednata programa
> > > > ...
> > > script. Na purvia red directivata !/bin/sh e directiva kym shell-a,
> > > akavto niamash, kogato izpulniavash exec().
> > 
> > Na dali towa e prichinata da dade EFAULT ("Bad address").
> >
> 99% siguren sam che tova e prichinata.
> kakvo prqaviat seriata funkcii exec(), t.e. execv(), execl(), execvp()
> i t.n. - ami zarezhdat ukazania v argumemta fail v segmenta na
> izpulnimia kod i mu predadat upravlenieto.
> V opisania sluchai tova, koeto se naricha "process image" e textov
> fail, koito niama nikakav shans da "trugne" da se izpulniava. za da se
> ispulni, triabva da se zaredi kato "process image" interpretator,
> koito da go izpulni. komadata sledovatelno triabva da e:
> 
> execv("/bin/sh","sh","/usr/local/my_script",NULL);
> 
> ili ako iskash da napravish taka che scripta da se izpulni kato nov
> process:
> 
> system("/usr/bin/local/my_script");
==================================================================
A mail-list of Linux Users Group - Bulgaria (bulgarian linuxers)
Otpiswaneto RABOTI !!! : Majordomo@xxxxxxxxxxxxxxxxxx UNSUBSCRIBE LUG-BG
http://www.linux-bulgaria.org/ Hosted by Internet Group Ltd. - Stara Zagora



 

наши приятели

 

линукс за българи
http://linux-bg.org

FSA-BG
http://fsa-bg.org

OpenFest
http://openfest.org

FreeBSD BG
http://bg-freebsd.org

KDE-BG
http://kde.fsa-bg.org/

Gnome-BG
http://gnome.cult.bg/

проект OpenFMI
http://openfmi.net

NetField Forum
http://netField.ludost.net/forum/

 

 

Linux-Bulgaria.ORG

Mailing list messages are © Copyright their authors.