s/qmail  3.3.23
Next generation secure email transport
pathexec_run.c
Go to the documentation of this file.
1 #include "error.h"
2 #include "stralloc.h"
3 #include "str.h"
4 #include "env.h"
5 #include "pathexec.h"
6 
7 static stralloc tmp;
8 
9 void pathexec_run(char *file,char **argv,char **envp)
10 {
11  char *path;
12  unsigned int split;
13  int savederrno;
14 
15  if (file[str_chr(file,'/')]) {
16  execve(file,argv,envp);
17  return;
18  }
19 
20  path = env_get("PATH");
21  if (!path) path = "/bin:/usr/bin";
22 
23  savederrno = 0;
24  for (;;) {
25  split = str_chr(path,':');
26  if (!stralloc_copyb(&tmp,path,split)) return;
27  if (!split)
28  if (!stralloc_cats(&tmp,".")) return;
29  if (!stralloc_cats(&tmp,"/")) return;
30  if (!stralloc_cats(&tmp,file)) return;
31  if (!stralloc_0(&tmp)) return;
32 
33  execve(tmp.s,argv,envp);
34  if (errno != error_noent) {
35  savederrno = errno;
36  if ((errno != error_acces) && (errno != error_perm) && (errno != error_isdir)) return;
37  }
38 
39  if (!path[split]) {
40  if (savederrno) errno = savederrno;
41  return;
42  }
43  path += split;
44  path += 1;
45  }
46 }
unsigned int str_chr(char *, int)
int error_acces
Definition: error.c:90
int stralloc_copyb(stralloc *, char *, unsigned int)
Definition: stralloc_opyb.c:4
stralloc file
Definition: columnt.c:18
#define stralloc_0(sa)
Definition: stralloc.h:19
char * env_get(char *)
Definition: envread.c:4
void split(void(*dofield)(), void(*doline)())
Definition: columnt.c:65
int errno
int error_noent
Definition: error.c:20
stralloc tmp
Definition: newinclude.c:31
void pathexec_run(char *file, char **argv, char **envp)
Definition: pathexec_run.c:9
int stralloc_cats(stralloc *, char *)
Definition: stralloc_cats.c:5
int error_perm
Definition: error.c:83
int error_isdir
Definition: error.c:111