1 #include "Headers/opsys.h"
3 OpSys OS
; // Global OpSys variable. Should be accessible to all modules.
5 void signal_handler(int s
)
9 cout
<< "\nSIGINT (Ctrl+C) received. Code " << s
<< ". Exiting.\n";
15 cout
<< "\nSIGHUP received. Code " << s
<< ". Exiting.\n";
20 SignalHandler::SignalHandler()
22 signal_action
.sa_handler
= signal_handler
;
23 sigemptyset(&signal_action
.sa_mask
);
24 signal_action
.sa_flags
= 0;
25 sigaction(SIGINT
, &signal_action
, NULL
);
28 string
OpSys::get_cwd()
30 char temp
[MAXPATHLEN
];
31 return getcwd(temp
, sizeof(temp
)) ? std::string( temp
) : std::string("");
34 void OpSys::change_dir(vector
<string
> command
)
37 for(unsigned short int i
= 1; i
< command
.size(); i
++)
41 if (chdir(cmd
.c_str()))
43 cerr
<< "miniShell: cd: " << cmd
<< ": Arquivo ou diretório não encontrado\n";
55 cerr
<< RED_ANSI
<< "Could not get the current working directory.\n" << RESET_ANSI
;
57 uid_t uid
= geteuid(); // Gets the effective ID of the user that started miniSHELL
59 struct passwd
*pwent_ptr
;
62 // Looks for the UDI on the password databank and saves the result on pwent
63 getpwuid_r(uid
, &pwent
, buffer
, sizeof buffer
, &pwent_ptr
);
64 username
= pwent
.pw_name
; // Saves username
67 gethostname(hostname
, 64);
68 this->hostname
= hostname
;