Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
ion
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
redox-os
ion
Commits
adde38d8
Commit
adde38d8
authored
7 years ago
by
Michael Aaron Murphy
Browse files
Options
Downloads
Patches
Plain Diff
Add UID and EUID String Variables
parent
8cdf371e
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/shell/binary/mod.rs
+3
-3
3 additions, 3 deletions
src/shell/binary/mod.rs
src/shell/variables/mod.rs
+16
-7
16 additions, 7 deletions
src/shell/variables/mod.rs
src/sys/redox.rs
+4
-0
4 additions, 0 deletions
src/sys/redox.rs
src/sys/unix/mod.rs
+4
-0
4 additions, 0 deletions
src/sys/unix/mod.rs
with
27 additions
and
10 deletions
src/shell/binary/mod.rs
+
3
−
3
View file @
adde38d8
...
...
@@ -14,13 +14,13 @@ use super::status::*;
use
liner
::{
Buffer
,
Context
};
use
smallvec
::
SmallVec
;
use
std
::
env
;
use
std
::
error
::
Error
;
use
std
::
fs
::
File
;
use
std
::
io
::{
stdout
,
Write
};
use
std
::
io
::
ErrorKind
;
use
std
::
iter
::{
self
,
FromIterator
};
use
std
::
path
::
Path
;
use
std
::
process
;
use
std
::
io
::{
stdout
,
Write
};
use
std
::
error
::
Error
;
const
MAN_ION
:
&
'static
str
=
r#"NAME
ion - ion shell
...
...
@@ -208,7 +208,7 @@ impl Binary for Shell {
match
stdout
.write_all
(
MAN_ION
.as_bytes
())
.and_then
(|
_
|
stdout
.flush
())
{
{
Ok
(
_
)
=>
return
,
Err
(
err
)
=>
panic!
(
"{}"
,
err
.description
()
.to_owned
()),
}
...
...
This diff is collapsed.
Click to expand it.
src/shell/variables/mod.rs
+
16
−
7
View file @
adde38d8
...
...
@@ -6,7 +6,7 @@ use fnv::FnvHashMap;
use
liner
::
Context
;
use
std
::
env
;
use
std
::
io
::{
self
,
BufRead
};
use
sys
::{
self
,
get
p
id
,
is_root
};
use
sys
::{
self
,
get
euid
,
getpid
,
getu
id
,
is_root
};
use
sys
::
variables
as
self_sys
;
use
types
::{
Array
,
ArrayVariableContext
,
HashMap
,
HashMapVariableContext
,
Identifier
,
Key
,
Value
,
...
...
@@ -41,11 +41,20 @@ impl Default for Variables {
${c::reset}"
.into
(),
);
// Set the PID variable to the PID of the shell
let
pid
=
getpid
()
.map
(|
p
|
p
.to_string
())
.unwrap_or_else
(|
e
|
e
.to_string
());
map
.insert
(
"PID"
.into
(),
pid
.into
());
// Set the PID, UID, and EUID variables.
map
.insert
(
"PID"
.into
(),
getpid
()
.ok
()
.map_or
(
"?"
.into
(),
|
id
|
id
.to_string
()),
);
map
.insert
(
"UID"
.into
(),
getuid
()
.ok
()
.map_or
(
"?"
.into
(),
|
id
|
id
.to_string
()),
);
map
.insert
(
"EUID"
.into
(),
geteuid
()
.ok
()
.map_or
(
"?"
.into
(),
|
id
|
id
.to_string
()),
);
// Initialize the HISTFILE variable
if
let
Ok
(
base_dirs
)
=
BaseDirectories
::
with_prefix
(
"ion"
)
{
...
...
@@ -206,8 +215,8 @@ impl Variables {
pub
fn
get_var
(
&
self
,
name
:
&
str
)
->
Option
<
Value
>
{
match
name
{
"SWD"
=>
return
Some
(
self
.get_simplified_directory
()),
"MWD"
=>
return
Some
(
self
.get_minimal_directory
()),
"SWD"
=>
return
Some
(
self
.get_simplified_directory
()),
_
=>
(),
}
if
let
Some
((
name
,
variable
))
=
name
.find
(
"::"
)
.map
(|
pos
|
(
&
name
[
..
pos
],
&
name
[
pos
+
2
..
]))
...
...
This diff is collapsed.
Click to expand it.
src/sys/redox.rs
+
4
−
0
View file @
adde38d8
...
...
@@ -22,6 +22,10 @@ pub(crate) const STDIN_FILENO: RawFd = 0;
pub
(
crate
)
const
STDOUT_FILENO
:
RawFd
=
1
;
pub
(
crate
)
const
STDERR_FILENO
:
RawFd
=
2
;
pub
(
crate
)
fn
geteuid
()
->
io
::
Result
<
u32
>
{
cvt
(
syscall
::
geteuid
()
.map
(|
pid
|
pid
as
u32
))
}
pub
(
crate
)
fn
getuid
()
->
io
::
Result
<
u32
>
{
cvt
(
syscall
::
getuid
()
.map
(|
pid
|
pid
as
u32
))
}
pub
(
crate
)
fn
is_root
()
->
bool
{
syscall
::
geteuid
()
.map
(|
id
|
id
==
0
)
.unwrap_or
(
false
)
}
pub
unsafe
fn
fork
()
->
io
::
Result
<
u32
>
{
cvt
(
syscall
::
clone
(
0
))
.map
(|
pid
|
pid
as
u32
)
}
...
...
This diff is collapsed.
Click to expand it.
src/sys/unix/mod.rs
+
4
−
0
View file @
adde38d8
...
...
@@ -23,6 +23,10 @@ pub(crate) const STDOUT_FILENO: i32 = libc::STDOUT_FILENO;
pub
(
crate
)
const
STDERR_FILENO
:
i32
=
libc
::
STDERR_FILENO
;
pub
(
crate
)
const
STDIN_FILENO
:
i32
=
libc
::
STDIN_FILENO
;
pub
(
crate
)
fn
geteuid
()
->
io
::
Result
<
u32
>
{
Ok
(
unsafe
{
libc
::
geteuid
()
}
as
u32
)
}
pub
(
crate
)
fn
getuid
()
->
io
::
Result
<
u32
>
{
Ok
(
unsafe
{
libc
::
getuid
()
}
as
u32
)
}
pub
(
crate
)
fn
is_root
()
->
bool
{
unsafe
{
libc
::
geteuid
()
==
0
}
}
pub
unsafe
fn
fork
()
->
io
::
Result
<
u32
>
{
cvt
(
libc
::
fork
())
.map
(|
pid
|
pid
as
u32
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment