Re: lug-bg: "C" wapros
- Subject: Re: lug-bg: "C" wapros
- From: zimage@xxxxxxxxx (Theodor Milkov)
- Date: Fri, 01 Jan 1999 01:19:37 +0200
Georgi Chorbadzhiyski wrote:
> Ako mozhe niakoi po svetnat da pomogne. Imam slednata programa
>
> #
> # funkciikata e orezana versia ot pppd
> #
> int run_program(prog, args, must_exist, done, arg)
> char *prog;
> char **args;
> int must_exist;
> void (*done) __P((void *));
> void *arg;
> {
> int pid;
>
> pid = fork();
> if (pid == -1) {
> log(L_ERR, "Failed to create child process for %s", prog);
> return -1;
> }
> if (pid == 0) {
> /* run the program */
> execvp(prog, args);
> if (must_exist || errno != ENOENT) {
> /* have to reopen the log, there's nowhere else
> for the message to go. */
> log(L_ERR, "Can't execute: %s error: %u", prog, errno);
> }
> _exit(-1);
> }
> return pid;
> }
>
> wikam si funkciikata taka:
>
> run_program("/usr/local/my_script", exec_buf, 0, NULL, NULL);
>
> /usr/local/my_script sadyrzha:
>
> #!/bin/sh
> echo raboti! >> /tmp/proba
>
> Wsichko ok obache, kato go wikna tova run_program i waw log-a
> mi pishe:
>
> can't execute: /usr/local/my_script error: 14
>
> kogato skript-a ne e izpalnim msg-to e:
>
> can't execute: /usr/local/my_script error: 13
>
> Kakvo oznachavat tezi i greshki i kakvo sam obyrkal ??
>
Po printcip mojesh da polzvash systemnata biblioteka errno.h v koiato sa
definirani raznite greshki. Naprimer zameni:
log(L_ERR, "Can't execute: %s error: %u", prog, errno);
as slednoto:
log(L_ERR, "Can't execute: %s error: %s", prog,
sys_errlist[errno]);
Kato ne zabravish da #include <errno.h>. Togava vmesto 13 i 14 shte poluchish
saotvetno "Permission denied" i "Bad address"... dokolkoto "Bad
address" niakoi znae kakvo tochno znachi :-)
egards
==================================================================
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
|