-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiskfree.c
47 lines (40 loc) · 884 Bytes
/
diskfree.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "server.h"
static char* page_start =
"<html>\n"
" <body>\n"
" <pre>\n";
static char* page_end =
" </pre>\n"
" </body>\n"
"</html>\n";
void module_generate(int fd)
{
pid_t child_pid;
int rval;
write(fd,page_start,strlen(page_start));
child_pid = fork();
if(child_pid == 0){
char* argv[] = {"/bin/df","-h",NULL};
rval = dup2(fd,STDOUT_FILENO);
if(rval == -1)
system_error("dup2");
rval = dup2(fd,STDERR_FILENO);
if(rval == -1)
system_error("dup2");
execv(argv[0],argv);
system_error ("execv");
}
else if(child_pid > 0 ){
rval = waitpid(child_pid, NULL,0);
if(rval == -1)
system_error("Waitpid");
}
else
system_error("fork");
write(fd,page_end,sizeof(page_end));
}