Skip to content

Commit

Permalink
integrate db_check() into the main function and remove src/db_rawcheck.c
Browse files Browse the repository at this point in the history
  • Loading branch information
cdpxe committed Oct 5, 2024
1 parent a3c349d commit 1902c89
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 77 deletions.
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ BUILDFLAGS=-O2 $(STACK_PROT) $(ADD_LNKFLAGS)
DOCFILES_TO_INST=AUTHORS CHANGELOG HISTORY README.md INSTALL LICENSE database/usenet.db_struct database/mysql_db_struct.sql
MANPAGES=docs/wendzelnntpd.8 docs/wendzelnntpadm.8

all : wendzelnntpadm main.o db_rawcheck.o log.o database.o cdpstrings.o server.o lexyacc charstack.o libfunc.o acl.o db_abstraction.o hash.o $(SQLITEOBJ) $(MYSQLOBJ) $(POSTGRESOBJ) $(OPENSSLOBJ) globals.o
all : wendzelnntpadm main.o log.o database.o cdpstrings.o server.o lexyacc charstack.o libfunc.o acl.o db_abstraction.o hash.o $(SQLITEOBJ) $(MYSQLOBJ) $(POSTGRESOBJ) $(OPENSSLOBJ) globals.o
expr `cat build` \+ 1 >build
$(CC) $(DEBUG) $(BUILDFLAGS) -o bin/wendzelnntpd main.o log.o server.o lex.yy.o config.tab.o database.o globals.o cdpstrings.o db_rawcheck.o acl.o db_abstraction.o hash.o $(SQLITEOBJ) $(MYSQLOBJ) $(POSTGRESOBJ) charstack.o libfunc.o $(OPENSSLOBJ) $(SOLNETLIBS) $(SQLITELIB) $(MYSQLLIB) $(POSTGRESLIB) $(LIBDIRS) $(SOLNETLIBS) $(GCCLOCALPTHREAD) $(LIBPTHREAD) $(LIBMHASH) $(OPENSSLLIB)
$(CC) $(DEBUG) $(BUILDFLAGS) -o bin/wendzelnntpd main.o log.o server.o lex.yy.o config.tab.o database.o globals.o cdpstrings.o acl.o db_abstraction.o hash.o $(SQLITEOBJ) $(MYSQLOBJ) $(POSTGRESOBJ) charstack.o libfunc.o $(OPENSSLOBJ) $(SOLNETLIBS) $(SQLITELIB) $(MYSQLLIB) $(POSTGRESLIB) $(LIBDIRS) $(SOLNETLIBS) $(GCCLOCALPTHREAD) $(LIBPTHREAD) $(LIBMHASH) $(OPENSSLLIB)
#strip bin/wendzelnntpd

lexyacc : lex.yy.o config.tab.o
Expand All @@ -54,9 +54,6 @@ log.o : $(SRC)/log.c $(HEADERS)
libfunc.o : $(SRC)/libfunc.c $(HEADERS)
$(CC) $(DEBUG) $(BUILD) $(CFLAGS) $(INCDIRS) $<

db_rawcheck.o : $(SRC)/db_rawcheck.c $(HEADERS)
$(CC) $(DEBUG) $(BUILD) $(CFLAGS) $(INCDIRS) $<

acl.o : $(SRC)/acl.c $(HEADERS)
$(CC) $(DEBUG) $(BUILD) $(CFLAGS) $(INCDIRS) $<

Expand Down
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3243
3245
68 changes: 0 additions & 68 deletions src/db_rawcheck.c

This file was deleted.

3 changes: 0 additions & 3 deletions src/include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,6 @@ void onxxdebug(char *str);
void onxxdebugm(char *str, ...);
void logstr(char *, int, char *, char *);

/* db_rawcheck.c */
void check_db(void);

/* libfunc.c */
#if defined(__WIN32__) || defined(NOSUPPORT_STRNDUP)
char *strndup(char *, int);
Expand Down
41 changes: 41 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ extern short global_mode;
extern sig_atomic_t rec_sighup; //SIGHUP has been sent to process - global.c
extern sig_atomic_t rec_sigterm; //SIGTERM (KILL) has been sent to process - global.c

extern unsigned short dbase; /* from config.y */
extern short be_verbose;

/* need this global for server.c */
struct sockaddr_in sa;
struct sockaddr_in6 sa6;
Expand All @@ -49,6 +52,44 @@ usage_(void)
"-v print the version and exit\n");
}

static void
check_db(void)
{
server_cb_inf inf;

if (!(inf.servinf = (serverinfo_t *) calloc(1, sizeof(serverinfo_t)))) {
fprintf(stderr, "Unable to allocate memory");
exit(ERR_EXIT);
}

/* Make sure we have a database engine */
switch (dbase) {
case DBASE_NONE:
fprintf(stderr, "There is no database specified in the configuration!\n");
fprintf(stderr, "Please write at least 'database-engine sqlite3' in \n");
fprintf(stderr, "your config file.\n");
DO_SYSL("Exiting. No database engine specified.");
exit(ERR_EXIT);
/*NOTREACHED*/
break;
case DBASE_SQLITE3:
case DBASE_MYSQL:
case DBASE_POSTGRES:
db_open_connection(&inf);
db_close_connection(&inf);
break;
default:
fprintf(stderr, "DB engine not supported. exiting.");
DO_SYSL("DB engine not supported. exiting.");
exit(ERR_EXIT);
break;
}
if (be_verbose) {
printf("Database check %s: Success.\n",
(dbase == DBASE_SQLITE3 ? "Sqlite3" : (dbase == DBASE_MYSQL ? "MySQL" : "PostgreSQL")));
}
}

static void
welcome_(int ready)
{
Expand Down

0 comments on commit 1902c89

Please sign in to comment.