first commit

This commit is contained in:
Jose Caban
2025-06-07 01:59:34 -04:00
commit 388ac241f0
3558 changed files with 9116289 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include "include/sock_lib.h"
#include "include/settings.h"
#include "../../common/defs.h"
#include "../../common/thread_pool/thread_pool.h"
#include "../../common/shared_memory/shared_memory.h"
/* signal handler for SIGINT */
void catch_int(int sig_num)
{
// TODO: Insert memory freeing stuff here
printf("Signal %d received\n", sig_num);
printf("Destroying the Shared Memory Segments...\n");
destroy_shared_memory();
printf("Done!\n");
exit(1);
}
int main(int argc, char** argv) {
settings_t settings;
int c = '\0'; //character to get
#ifndef LINUX
sigset_t newmask;
sigset_t oldmask;
sigemptyset(&newmask);
sigaddset(&newmask, SIGPIPE);
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
{
fprintf(stderr, "can't set signal mask\n");
exit(1);
}
#endif
printf("* Beginning l33t_server Initialization *\n\n");
init_settings(&settings, argc, argv);
printf("** Using %d threads\n",settings.MAX_THREADS);
printf("** Using home_dir: %s\n",settings.LOAD_DIR);
printf( (settings.useSHMEM == 0 ? "** Not " : "** "));
printf( "Using Shared Memory.\n");
if (settings.useSHMEM) {
// Mask signals (fancy, isn't it?)
signal(SIGINT, catch_int);
signal(SIGABRT, catch_int);
signal(SIGSEGV, catch_int);
signal(SIGTERM, catch_int);
signal(SIGBUS, catch_int);
init_shared_memory();
}
if (chdir(settings.LOAD_DIR) < 0) {
printf("*** Error setting home directory..Exiting\n");
exit(1);
}
printf("* l33t_server started *\n\n");
init_thread_pool(&(settings.PORT_NUMBER), settings.MAX_THREADS,
producer, consumer, &settings);
while (getchar() != 'q');
if (settings.useSHMEM) {
catch_int(SIGINT);
}
return EXIT_SUCCESS;
}