Skip to content

Commit

Permalink
Fix bad code when forking
Browse files Browse the repository at this point in the history
  • Loading branch information
dokutan committed Apr 5, 2020
1 parent 2006df8 commit 692e5ef
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions macrodevice-lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <string>
#include <map>
#include <exception>
#include <cstdio>

#include <getopt.h> // getopt_long
#include <sys/types.h> // for fork
Expand Down Expand Up @@ -338,7 +339,7 @@ int main( int argc, char *argv[] )
{
target_user = std::stoi( string_user, 0, 10 );
target_group = std::stoi( string_group, 0, 10 );
}
}
catch( std::exception &e )
{
std::cerr << "Invalid argument: -u and -g require a number\n";
Expand Down Expand Up @@ -384,9 +385,9 @@ int main( int argc, char *argv[] )
pid_t process_id = fork();

// close file descriptors
close(0); // cin
close(1); // cout
close(2); // cerr
close( fileno(stdin) ); // cin
close( fileno(stdout) ); // cout
close( fileno(stdout) ); // cerr

// quit if not child process
if( process_id != 0 )
Expand Down

0 comments on commit 692e5ef

Please sign in to comment.