Add config.c and config.h

This commit is contained in:
2021-01-05 23:01:38 +01:00
parent 55028bd9cd
commit 4d4d94fc81
5 changed files with 58 additions and 6 deletions

View File

@ -30,7 +30,7 @@ int cache_process() {
signal(SIGINT, cache_process_term);
signal(SIGTERM, cache_process_term);
int shm_id = shmget(SHM_KEY, FILE_CACHE_SIZE * sizeof(cache_entry), 0);
int shm_id = shmget(SHM_KEY_CACHE, FILE_CACHE_SIZE * sizeof(cache_entry), 0);
if (shm_id < 0) {
fprintf(stderr, ERR_STR "Unable to create shared memory: %s" CLR_STR "\n", strerror(errno));
return -1;
@ -158,7 +158,7 @@ int cache_init() {
return -1;
}
int shm_id = shmget(SHM_KEY, FILE_CACHE_SIZE * sizeof(cache_entry), IPC_CREAT | IPC_EXCL | 0600);
int shm_id = shmget(SHM_KEY_CACHE, FILE_CACHE_SIZE * sizeof(cache_entry), IPC_CREAT | IPC_EXCL | 0600);
if (shm_id < 0) {
fprintf(stderr, ERR_STR "Unable to create shared memory: %s" CLR_STR "\n", strerror(errno));
return -2;
@ -202,7 +202,7 @@ int cache_init() {
}
int cache_unload() {
int shm_id = shmget(SHM_KEY, 0, 0);
int shm_id = shmget(SHM_KEY_CACHE, 0, 0);
if (shm_id < 0) {
fprintf(stderr, ERR_STR "Unable to create shared memory: %s" CLR_STR "\n", strerror(errno));
} else if (shmctl(shm_id, IPC_RMID, NULL) < 0) {
@ -214,7 +214,7 @@ int cache_unload() {
int cache_update_entry(int entry_num, const char *filename, const char *webroot) {
void *cache_ro = cache;
int shm_id = shmget(SHM_KEY, 0, 0);
int shm_id = shmget(SHM_KEY_CACHE, 0, 0);
void *shm_rw = shmat(shm_id, NULL, 0);
if (shm_rw == (void *) -1) {
print(ERR_STR "Unable to attach shared memory (rw): %s" CLR_STR, strerror(errno));
@ -256,7 +256,7 @@ int cache_update_entry(int entry_num, const char *filename, const char *webroot)
int cache_filename_comp_invalid(const char *filename) {
void *cache_ro = cache;
int shm_id = shmget(SHM_KEY, 0, 0);
int shm_id = shmget(SHM_KEY_CACHE, 0, 0);
void *shm_rw = shmat(shm_id, NULL, 0);
if (shm_rw == (void *) -1) {
print(ERR_STR "Unable to attach shared memory (rw): %s" CLR_STR, strerror(errno));

17
src/config.c Normal file
View File

@ -0,0 +1,17 @@
/**
* Necronda Web Server
* Configuration file loader
* src/config.c
* Lorenz Stechauner, 2021-01-05
*/
#include "config.h"
int config_init() {
return 0;
}
int config_load() {
return 0;
}

32
src/config.h Normal file
View File

@ -0,0 +1,32 @@
/**
* Necronda Web Server
* Configuration file loader (header file)
* src/config.h
* Lorenz Stechauner, 2021-01-05
*/
#ifndef NECRONDA_SERVER_CONFIG_H
#define NECRONDA_SERVER_CONFIG_H
typedef struct {
int type;
char name[256];
union {
struct {
char address[256];
unsigned short port;
};
struct {
char webroot[256];
unsigned char dir_mode;
};
};
} host_config;
int config_init();
int config_load();
#endif //NECRONDA_SERVER_CONFIG_H

View File

@ -9,6 +9,7 @@
#include "necronda-server.h"
#include "config.c"
#include "utils.c"
#include "uri.c"
#include "cache.c"

View File

@ -39,9 +39,11 @@
#define CHUNK_SIZE 4096
#define CLIENT_MAX_HEADER_SIZE 8192
#define FILE_CACHE_SIZE 1024
#define SHM_KEY 255641
#define GEOIP_MAX_SIZE 8192
#define SHM_KEY_CACHE 255641
#define SHM_KEY_CONFIG 255642
#define ERR_STR "\x1B[1;31m"
#define CLR_STR "\x1B[0m"
#define BLD_STR "\x1B[1m"