Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
44a4e2fd
Commit
44a4e2fd
authored
Nov 05, 1993
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added execve; change getstrarg into getargs with "s" format
parent
3c64f4d4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
99 additions
and
10 deletions
+99
-10
Modules/posixmodule.c
Modules/posixmodule.c
+99
-10
No files found.
Modules/posixmodule.c
View file @
44a4e2fd
...
@@ -156,7 +156,7 @@ posix_1str(args, func)
...
@@ -156,7 +156,7 @@ posix_1str(args, func)
{
{
char
*
path1
;
char
*
path1
;
int
res
;
int
res
;
if
(
!
get
strarg
(
args
,
&
path1
))
if
(
!
get
args
(
args
,
"s"
,
&
path1
))
return
NULL
;
return
NULL
;
BGN_SAVE
BGN_SAVE
res
=
(
*
func
)(
path1
);
res
=
(
*
func
)(
path1
);
...
@@ -213,7 +213,7 @@ posix_do_stat(self, args, statfunc)
...
@@ -213,7 +213,7 @@ posix_do_stat(self, args, statfunc)
struct
stat
st
;
struct
stat
st
;
char
*
path
;
char
*
path
;
int
res
;
int
res
;
if
(
!
get
strarg
(
args
,
&
path
))
if
(
!
get
args
(
args
,
"s"
,
&
path
))
return
NULL
;
return
NULL
;
BGN_SAVE
BGN_SAVE
res
=
(
*
statfunc
)(
path
,
&
st
);
res
=
(
*
statfunc
)(
path
,
&
st
);
...
@@ -290,7 +290,7 @@ posix_listdir(self, args)
...
@@ -290,7 +290,7 @@ posix_listdir(self, args)
#ifdef TURBO_C
#ifdef TURBO_C
struct
ffblk
ep
;
struct
ffblk
ep
;
int
rv
;
int
rv
;
if
(
!
get
strarg
(
args
,
&
name
))
if
(
!
get
args
(
args
,
"s"
,
&
name
))
return
NULL
;
return
NULL
;
if
(
findfirst
(
name
,
&
ep
,
0
)
==
-
1
)
if
(
findfirst
(
name
,
&
ep
,
0
)
==
-
1
)
...
@@ -320,7 +320,7 @@ posix_listdir(self, args)
...
@@ -320,7 +320,7 @@ posix_listdir(self, args)
int
attrib
;
int
attrib
;
int
num
=
0
;
int
num
=
0
;
if
(
!
get
strarg
(
args
,
&
name
))
if
(
!
get
args
(
args
,
"s"
,
&
name
))
return
NULL
;
return
NULL
;
strcpy
(
_name
,
name
);
strcpy
(
_name
,
name
);
...
@@ -365,7 +365,7 @@ again:
...
@@ -365,7 +365,7 @@ again:
#ifdef unix
#ifdef unix
DIR
*
dirp
;
DIR
*
dirp
;
struct
direct
*
ep
;
struct
direct
*
ep
;
if
(
!
get
strarg
(
args
,
&
name
))
if
(
!
get
args
(
args
,
"s"
,
&
name
))
return
NULL
;
return
NULL
;
BGN_SAVE
BGN_SAVE
if
((
dirp
=
opendir
(
name
))
==
NULL
)
{
if
((
dirp
=
opendir
(
name
))
==
NULL
)
{
...
@@ -470,7 +470,7 @@ posix_system(self, args)
...
@@ -470,7 +470,7 @@ posix_system(self, args)
{
{
char
*
command
;
char
*
command
;
long
sts
;
long
sts
;
if
(
!
get
strarg
(
args
,
&
command
))
if
(
!
get
args
(
args
,
"s"
,
&
command
))
return
NULL
;
return
NULL
;
BGN_SAVE
BGN_SAVE
sts
=
system
(
command
);
sts
=
system
(
command
);
...
@@ -587,8 +587,6 @@ posix__exit(self, args)
...
@@ -587,8 +587,6 @@ posix__exit(self, args)
/* NOTREACHED */
/* NOTREACHED */
}
}
/* XXX To do: exece, execp */
static
object
*
static
object
*
posix_execv
(
self
,
args
)
posix_execv
(
self
,
args
)
object
*
self
;
object
*
self
;
...
@@ -623,7 +621,7 @@ posix_execv(self, args)
...
@@ -623,7 +621,7 @@ posix_execv(self, args)
if
(
argvlist
==
NULL
)
if
(
argvlist
==
NULL
)
return
NULL
;
return
NULL
;
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
if
(
!
get
strarg
((
*
getitem
)(
argv
,
i
)
,
&
argvlist
[
i
]))
{
if
(
!
get
args
((
*
getitem
)(
argv
,
i
),
"s"
,
&
argvlist
[
i
]))
{
DEL
(
argvlist
);
DEL
(
argvlist
);
goto
badarg
;
goto
badarg
;
}
}
...
@@ -638,6 +636,96 @@ posix_execv(self, args)
...
@@ -638,6 +636,96 @@ posix_execv(self, args)
return
posix_error
();
return
posix_error
();
}
}
static
object
*
posix_execve
(
self
,
args
)
object
*
self
;
object
*
args
;
{
char
*
path
;
object
*
argv
,
*
env
;
char
**
argvlist
;
char
**
envlist
;
object
*
key
,
*
val
;
int
i
,
pos
,
argc
,
envc
;
object
*
(
*
getitem
)
PROTO
((
object
*
,
int
));
/* execve has three arguments: (path, argv, env), where
argv is a list or tuple of strings and env is a dictionary
like posix.environ. */
if
(
!
getargs
(
args
,
"(sOO)"
,
&
path
,
&
argv
,
&
env
))
return
NULL
;
if
(
is_listobject
(
argv
))
{
argc
=
getlistsize
(
argv
);
getitem
=
getlistitem
;
}
else
if
(
is_tupleobject
(
argv
))
{
argc
=
gettuplesize
(
argv
);
getitem
=
gettupleitem
;
}
else
{
err_setstr
(
TypeError
,
"argv must be tuple or list"
);
return
NULL
;
}
if
(
!
is_dictobject
(
env
))
{
err_setstr
(
TypeError
,
"env must be dictionary"
);
return
NULL
;
}
argvlist
=
NEW
(
char
*
,
argc
+
1
);
if
(
argvlist
==
NULL
)
{
err_nomem
();
return
NULL
;
}
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
if
(
!
getargs
((
*
getitem
)(
argv
,
i
),
"s;argv must be list of strings"
,
&
argvlist
[
i
]))
{
goto
fail_1
;
}
}
argvlist
[
argc
]
=
NULL
;
i
=
getmappingsize
(
env
);
envlist
=
NEW
(
char
*
,
i
+
1
);
if
(
envlist
==
NULL
)
{
err_nomem
();
goto
fail_1
;
}
pos
=
0
;
envc
=
0
;
while
(
mappinggetnext
(
env
,
&
pos
,
&
key
,
&
val
))
{
char
*
p
,
*
k
,
*
v
;
if
(
!
getargs
(
key
,
"s;non-string key in env"
,
&
k
)
||
!
getargs
(
val
,
"s;non-string value in env"
,
&
v
))
{
goto
fail_2
;
}
p
=
NEW
(
char
,
getstringsize
(
key
)
+
getstringsize
(
val
)
+
2
);
if
(
p
==
NULL
)
{
err_nomem
();
goto
fail_2
;
}
sprintf
(
p
,
"%s=%s"
,
k
,
v
);
envlist
[
envc
++
]
=
p
;
}
envlist
[
envc
]
=
0
;
execve
(
path
,
argvlist
,
envlist
);
/* If we get here it's definitely an error */
(
void
)
posix_error
();
fail_2:
while
(
--
envc
>=
0
)
DEL
(
envlist
[
envc
]);
DEL
(
envlist
);
fail_1:
DEL
(
argvlist
);
return
NULL
;
}
static
object
*
static
object
*
posix_fork
(
self
,
args
)
posix_fork
(
self
,
args
)
object
*
self
;
object
*
self
;
...
@@ -839,7 +927,7 @@ posix_readlink(self, args)
...
@@ -839,7 +927,7 @@ posix_readlink(self, args)
char
buf
[
1024
];
/* XXX Should use MAXPATHLEN */
char
buf
[
1024
];
/* XXX Should use MAXPATHLEN */
char
*
path
;
char
*
path
;
int
n
;
int
n
;
if
(
!
get
strarg
(
args
,
&
path
))
if
(
!
get
args
(
args
,
"s"
,
&
path
))
return
NULL
;
return
NULL
;
BGN_SAVE
BGN_SAVE
n
=
readlink
(
path
,
buf
,
(
int
)
sizeof
buf
);
n
=
readlink
(
path
,
buf
,
(
int
)
sizeof
buf
);
...
@@ -1189,6 +1277,7 @@ static struct methodlist posix_methods[] = {
...
@@ -1189,6 +1277,7 @@ static struct methodlist posix_methods[] = {
#ifndef MSDOS
#ifndef MSDOS
{
"_exit"
,
posix__exit
},
{
"_exit"
,
posix__exit
},
{
"execv"
,
posix_execv
},
{
"execv"
,
posix_execv
},
{
"execve"
,
posix_execve
},
{
"fork"
,
posix_fork
},
{
"fork"
,
posix_fork
},
{
"getegid"
,
posix_getegid
},
{
"getegid"
,
posix_getegid
},
{
"geteuid"
,
posix_geteuid
},
{
"geteuid"
,
posix_geteuid
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment