Enforce strict compiler warnings

This exposed a bunch of issues that needed dealing with to ensure the
code is clean and sane. Notably the dlopen/dlsym routine has been altered
to closer match the LSI approach of safe symbol binding, by not attempting
to directly cast the result of a dlsym operation. Instead, if we succeed
in getting the dlsym() pointer, we memcpy this to the target and ensure
we have the correct constraints.

Note that in sanitizing the log helpers, I opted to remove the varargs
ability from FATAL_ERRNO given this is used exactly like perror() and
there are no examples currently using varargs with this in the tree.
This allowed me to keep the log helpers as macros and not have to implement
wrapper functions.

Signed-off-by: Ikey Doherty <ikey@solus-project.com>
This commit is contained in:
Ikey Doherty
2018-01-16 10:59:17 +00:00
committed by Marc Di Luzio
parent 68e326de60
commit e90bd98d64
11 changed files with 120 additions and 59 deletions

View File

@@ -48,7 +48,7 @@ void daemonize(char *name)
}
if (pid != 0) {
LOG_MSG("Daemon launched...\n");
LOG_MSG("Daemon launched as %s...\n", name);
exit(EXIT_SUCCESS);
}

View File

@@ -46,7 +46,7 @@ static sd_bus_slot *slot = NULL;
/**
* Clean up our private dbus state
*/
static void clean_up()
static void clean_up(void)
{
if (slot) {
sd_bus_slot_unref(slot);
@@ -61,7 +61,8 @@ static void clean_up()
/**
* Handles the RegisterGame D-BUS Method
*/
static int method_register_game(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
static int method_register_game(sd_bus_message *m, void *userdata,
__attribute__((unused)) sd_bus_error *ret_error)
{
int pid = 0;
GameModeContext *context = userdata;
@@ -80,7 +81,8 @@ static int method_register_game(sd_bus_message *m, void *userdata, sd_bus_error
/**
* Handles the UnregisterGame D-BUS Method
*/
static int method_unregister_game(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
static int method_unregister_game(sd_bus_message *m, void *userdata,
__attribute__((unused)) sd_bus_error *ret_error)
{
int pid = 0;
GameModeContext *context = userdata;

View File

@@ -116,12 +116,12 @@ const char *get_gov_state()
/* Grab the file length */
fseek(f, 0, SEEK_END);
int length = ftell(f);
long length = ftell(f);
fseek(f, 0, SEEK_SET);
char contents[length];
if (fread(contents, 1, length, f) > 0) {
if (fread(contents, 1, (size_t)length, f) > 0) {
/* Files have a newline */
strtok(contents, "\n");
if (strlen(governor) > 0 && strncmp(governor, contents, 64) != 0) {

View File

@@ -44,4 +44,4 @@ int fetch_governors(char governors[MAX_GOVERNORS][MAX_GOVERNOR_LENGTH]);
/**
* Get the current governor state
*/
const char *get_gov_state();
const char *get_gov_state(void);

View File

@@ -36,12 +36,12 @@ POSSIBILITY OF SUCH DAMAGE.
/**
* Store initial governor so we can use it again
*/
void update_initial_gov_state();
void update_initial_gov_state(void);
/**
* Return the governer set in update_initial_gov_state
*/
const char *get_initial_governor();
const char *get_initial_governor(void);
/**
* Update all governors to the given value. If this is NULL, restore the

View File

@@ -40,37 +40,37 @@ POSSIBILITY OF SUCH DAMAGE.
#include <unistd.h>
/* Macros to help with basic logging */
#define PLOG_MSG(msg, ...) printf(msg, ##__VA_ARGS__)
#define SYSLOG_MSG(msg, ...) syslog(LOG_INFO, msg, ##__VA_ARGS__)
#define LOG_MSG(msg, ...) \
#define PLOG_MSG(...) printf(__VA_ARGS__)
#define SYSLOG_MSG(...) syslog(LOG_INFO, __VA_ARGS__)
#define LOG_MSG(...) \
do { \
if (get_use_syslog()) { \
SYSLOG_MSG(msg, ##__VA_ARGS__); \
SYSLOG_MSG(__VA_ARGS__); \
} else { \
PLOG_MSG(msg, ##__VA_ARGS__); \
PLOG_MSG(__VA_ARGS__); \
} \
} while (0)
#define PLOG_ERROR(msg, ...) fprintf(stderr, msg, ##__VA_ARGS__)
#define SYSLOG_ERROR(msg, ...) syslog(LOG_ERR, msg, ##__VA_ARGS__)
#define LOG_ERROR(msg, ...) \
#define PLOG_ERROR(...) fprintf(stderr, __VA_ARGS__)
#define SYSLOG_ERROR(...) syslog(LOG_ERR, __VA_ARGS__)
#define LOG_ERROR(...) \
do { \
if (get_use_syslog()) { \
SYSLOG_MSG(msg, ##__VA_ARGS__); \
SYSLOG_MSG(__VA_ARGS__); \
} else { \
PLOG_MSG(msg, ##__VA_ARGS__); \
PLOG_MSG(__VA_ARGS__); \
} \
} while (0)
/* Fatal warnings trigger an exit */
#define FATAL_ERRORNO(msg, ...) \
#define FATAL_ERRORNO(msg) \
do { \
LOG_ERROR(msg " (%s)\n", ##__VA_ARGS__, strerror(errno)); \
LOG_ERROR(msg " (%s)\n", strerror(errno)); \
exit(EXIT_FAILURE); \
} while (0)
#define FATAL_ERROR(msg, ...) \
#define FATAL_ERROR(...) \
do { \
LOG_ERROR(msg, ##__VA_ARGS__); \
LOG_ERROR(__VA_ARGS__); \
exit(EXIT_FAILURE); \
} while (0)
@@ -78,4 +78,4 @@ POSSIBILITY OF SUCH DAMAGE.
* Control if and how how we use syslog
*/
void set_use_syslog(const char *name);
bool get_use_syslog();
bool get_use_syslog(void);

View File

@@ -58,7 +58,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <string.h>
#include <unistd.h>
static void sigint_handler(int signo)
static void sigint_handler(__attribute__((unused)) int signo)
{
LOG_MSG("Quitting by request...\n");