Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
khell
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SECOND
os
khell
Commits
308baa8d
Commit
308baa8d
authored
2 years ago
by
jonas.stirnema
Browse files
Options
Downloads
Patches
Plain Diff
Refactored main seems to be working
parent
0efc3a9d
No related branches found
No related tags found
No related merge requests found
Pipeline
#20022
failed
2 years ago
Stage: build
Stage: test
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
include/spawner.h
+3
-2
3 additions, 2 deletions
include/spawner.h
ls.txt
+0
-16
0 additions, 16 deletions
ls.txt
src/builtin.c
+2
-3
2 additions, 3 deletions
src/builtin.c
src/main.c
+13
-27
13 additions, 27 deletions
src/main.c
src/spawner.c
+24
-0
24 additions, 0 deletions
src/spawner.c
with
42 additions
and
48 deletions
include/spawner.h
+
3
−
2
View file @
308baa8d
...
...
@@ -16,6 +16,7 @@
#include
<unistd.h>
pid_t
fork_n_exec
(
cmd_t
command
);
int
spawn_process
(
cmd_t
command
);
bool
is_available
(
cmd_t
const
command
);
...
...
This diff is collapsed.
Click to expand it.
ls.txt
deleted
100644 → 0
+
0
−
16
View file @
0efc3a9d
total 60K
drwxr-xr-x 9 tpo tpo 4.0K 20 oct 00:18 .
drwxr-xr-x 5 tpo tpo 4.0K 11 oct 23:05 ..
drwxr-xr-x 2 tpo tpo 4.0K 20 oct 00:18 bin
-rw-r--r-- 1 tpo tpo 1.6K 2 oct 17:08 .clang-format
drwxr-xr-x 2 tpo tpo 4.0K 11 oct 23:05 docs
drwxr-xr-x 8 tpo tpo 4.0K 19 oct 23:36 .git
-rw-r--r-- 1 tpo tpo 13 2 oct 18:34 .gitignore
-rw-r--r-- 1 tpo tpo 1.3K 18 oct 14:24 .gitlab-ci.yml
drwxr-xr-x 2 tpo tpo 4.0K 11 oct 23:05 include
-rw-r--r-- 1 tpo tpo 52 20 oct 00:18 ls.txt
-rw-r--r-- 1 tpo tpo 666 2 oct 21:11 Makefile
-rw-r--r-- 1 tpo tpo 2.1K 20 oct 00:17 readme.md
drwxr-xr-x 2 tpo tpo 4.0K 19 oct 23:17 src
drwxr-xr-x 2 tpo tpo 4.0K 19 oct 23:17 test
drwxr-xr-x 2 tpo tpo 4.0K 11 oct 23:05 .vscode
This diff is collapsed.
Click to expand it.
src/builtin.c
+
2
−
3
View file @
308baa8d
...
...
@@ -49,9 +49,8 @@ bool blt_help(__attribute__((unused)) cmd_t command)
* Returns -1 if not builtin
*
* @param command - Command to check
* @param blt_commands - Builtin commands
* @return true if its builtin
* @return false otherwise
* @return Index of bulting command
* @return -1 not a builtin
*/
int
is_builtin
(
cmd_t
command
)
{
...
...
This diff is collapsed.
Click to expand it.
src/main.c
+
13
−
27
View file @
308baa8d
...
...
@@ -25,46 +25,32 @@ int main()
// ! PARSING THE USER INPUT
char
usr_in
[
ARG_MAX
];
int
err_usr_in
=
ask_user_input
(
usr_in
);
if
((
err_usr_in
==
-
1
)
||
(
strlen
(
usr_in
)
<=
0
))
{
continue
;
}
if
(
parse_command
(
usr_in
,
&
command
)
==
-
1
)
{
fprintf
(
stderr
,
"Couldnt parse the command
\n
"
);
}
//
? CHECK IF ITS
BUILTIN
//
!
BUILTIN
OR JOB
int
index_blt
=
is_builtin
(
command
);
if
(
index_blt
>=
0
)
// ! BUILTIN
// ! BUILTIN
if
(
index_blt
>=
0
)
{
run
=
g_builtin
[
index_blt
].
p_func
(
command
);
}
else
// ! JOB
// ! JOB
else
{
if
(
is_available
(
command
))
{
pid_t
pid
=
fork
();
pid_t
pid
;
if
((
pid
=
fork_n_exec
(
command
))
==
-
1
)
continue
;
// No child created, no need to wait
switch
(
pid
)
{
case
-
1
:
// ERROR
die_errno
(
"Could not fork"
);
break
;
case
0
:
// CHILD
if
(
spawn_process
(
command
)
==
-
1
)
{
dispose_command
(
&
command
);
continue
;
}
break
;
default:
// PARENT
int
status
;
pid_t
pid_dead_child
=
waitpid
(
pid
,
&
status
,
0
);
printf
(
"Process %d exited with code %d
\n
"
,
pid_dead_child
,
status
>>
8
);
break
;
}
}
else
{
...
...
This diff is collapsed.
Click to expand it.
src/spawner.c
+
24
−
0
View file @
308baa8d
...
...
@@ -10,6 +10,30 @@
#include
<fcntl.h>
#include
<string.h>
int
fork_n_exec
(
cmd_t
command
)
{
pid_t
pid
=
fork
();
switch
(
pid
)
{
case
-
1
:
// ERROR - No child created, no need to wait
die_errno
(
"Could not fork"
);
return
-
1
;
case
0
:
// CHILD
if
(
spawn_process
(
command
)
==
-
1
)
{
dispose_command
(
&
command
);
fprintf
(
stderr
,
"Could not execute the command properly
\n
"
);
return
-
1
;
}
break
;
default:
// PARENT
return
pid
;
}
return
-
1
;
}
/**
* @brief Check if a command is available to the user
*
...
...
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