-
Notifications
You must be signed in to change notification settings - Fork 0
/
execstest.c
66 lines (63 loc) · 1.69 KB
/
execstest.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* s2argv: convert strings to argv
* Copyright (C) 2014 Renzo Davoli. University of Bologna. <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <execs.h>
static void printargv(char **argv)
{
for(;*argv!=0;argv++) {
int argc=0;
for(;*argv!=0;argv++,argc++)
printf("argv[%d]=\"%s\"\n",argc,*argv);
argc++;
}
}
static int print1argv(char **argv, void *useless)
{
int argc=0;
for(;*argv!=0;argv++,argc++)
printf("argv[%d]=\"%s\"\n",argc,*argv);
return 0;
}
int main()
{
char buf[1024];
s2argv_getvar=getenv;
while (1) {
char **myargv;
if (fgets(buf,1024,stdin) == NULL)
return 0;
buf[strlen(buf)-1]=0;
myargv=s2argv(buf);
printargv(myargv);
printf("len %zd argc %zd\n", s2argvlen(myargv), s2argc(myargv));
s2argv_free(myargv);
s2multiargv(buf, print1argv, NULL, 0);
if (fork()==0) {
eexecsp(buf);
exit(-1);
} else {
int status;
wait(&status);
}
}
}