mraa.c: added user check into mraa_init() & increase verbosity
mraa_init() will now: - print user name and EUID of the process instead of UID, - print full platform text name in addition to numeric type, - return, log and print an error if started by non-root user Fixes #64 Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
committed by
Brendan Le Foll
parent
4d8b82eedb
commit
083db5bd27
24
src/mraa.c
24
src/mraa.c
@@ -27,6 +27,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
#define DEBUG
|
#define DEBUG
|
||||||
|
|
||||||
@@ -61,6 +62,9 @@ mraa_init()
|
|||||||
return MRAA_ERROR_PLATFORM_ALREADY_INITIALISED;
|
return MRAA_ERROR_PLATFORM_ALREADY_INITIALISED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uid_t proc_euid = geteuid();
|
||||||
|
struct passwd *proc_user = getpwuid(proc_euid);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
setlogmask(LOG_UPTO(LOG_DEBUG));
|
setlogmask(LOG_UPTO(LOG_DEBUG));
|
||||||
#else
|
#else
|
||||||
@@ -68,7 +72,19 @@ mraa_init()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
openlog("libmraa", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
|
openlog("libmraa", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
|
||||||
syslog(LOG_DEBUG, "libmraa initialised by user %d", getuid());
|
syslog(LOG_DEBUG,
|
||||||
|
"libmraa initialised by user '%s' with EUID %d",
|
||||||
|
(proc_user != NULL) ? proc_user->pw_name : "<unknown>",
|
||||||
|
proc_euid);
|
||||||
|
|
||||||
|
if (proc_euid != 0) {
|
||||||
|
char *err_msg = "mraa: FATAL error, "
|
||||||
|
"libmraa program must be run as root (EUID 0), "
|
||||||
|
"cannot proceed\n";
|
||||||
|
syslog(LOG_ERR, err_msg);
|
||||||
|
fprintf(stderr, err_msg);
|
||||||
|
return MRAA_ERROR_PLATFORM_NOT_INITIALISED;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SWIGPYTHON
|
#ifdef SWIGPYTHON
|
||||||
// Initialise python threads, this allows use to grab the GIL when we are
|
// Initialise python threads, this allows use to grab the GIL when we are
|
||||||
@@ -93,7 +109,11 @@ mraa_init()
|
|||||||
printf("mraa: FATAL error, failed to initialise platform\n");
|
printf("mraa: FATAL error, failed to initialise platform\n");
|
||||||
return MRAA_ERROR_PLATFORM_NOT_INITIALISED;
|
return MRAA_ERROR_PLATFORM_NOT_INITIALISED;
|
||||||
}
|
}
|
||||||
syslog(LOG_INFO, "libmraa initialised for platform %d", platform_type);
|
|
||||||
|
syslog(LOG_INFO,
|
||||||
|
"libmraa initialised for platform '%s' of type %d",
|
||||||
|
mraa_get_platform_name(),
|
||||||
|
platform_type);
|
||||||
return MRAA_SUCCESS;
|
return MRAA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user