10 #include <sys/socket.h>
12 #include <netinet/in.h>
13 #include <arpa/inet.h>
15 #ifdef BUILTIN_RUNPARTS
26 * Helpers to replace system() calls
31 char *x
, path
[PATH_MAX
];
37 do { *x
++ = *p
++; } while (*p
&& *p
!= '/');
39 ret
= mkdir(path
, 0777);
40 } while (*p
&& (*p
!= '/' || *(p
+ 1))); /* ignore trailing slash */
47 void copyfile(char *src
, char *dst
, int size
)
49 char buffer
[BUF_SIZE
];
52 /* Size == 0 means copy entire file */
56 if ((s
= open(src
, O_RDONLY
)) >= 0) {
57 if ((d
= open(dst
, O_WRONLY
| O_CREAT
, 0644)) >= 0) {
59 int csize
= size
> BUF_SIZE
? BUF_SIZE
: size
;
61 if ((n
= read(s
, buffer
, csize
)) > 0)
64 } while (size
> 0 && n
== BUF_SIZE
);
71 #ifdef BUILTIN_RUNPARTS
73 #define NUM_SCRIPTS 128 /* ought to be enough for anyone */
76 static int cmp(const void *s1
, const void *s2
)
78 return strcmp(*(char **)s1
, *(char **)s2
);
81 int run_parts(char *dir
, ...)
86 char *ent
[NUM_SCRIPTS
];
87 int i
, num
= 0, argnum
= 1;
94 if ((d
= opendir(dir
)) == NULL
)
98 while (argnum
< NUM_ARGS
&& (args
[argnum
++] = va_arg(ap
, char *)));
101 while ((e
= readdir(d
))) {
102 if (e
->d_type
== DT_REG
&& stat(e
->d_name
, &st
) == 0) {
103 if (st
.st_mode
& S_IXUSR
) {
104 ent
[num
++] = strdup(e
->d_name
);
105 if (num
>= NUM_SCRIPTS
)
116 qsort(ent
, num
, sizeof(char *), cmp
);
118 for (i
= 0; i
< num
; i
++) {
131 int getgroup(char *s
)
135 if ((grp
= getgrnam(s
)) == NULL
)