Skip to content

Commit

Permalink
Detect root user else exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
akatran committed Apr 19, 2018
1 parent 20b9d77 commit f2f0021
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "nRF24L01.h"
#include "RF24_config.h"
#include "RF24.h"
#include <stdlib.h>
#include <unistd.h>

/****************************************************************************/

Expand Down Expand Up @@ -67,8 +69,13 @@ void RF24::ce(bool level)

inline void RF24::beginTransaction() {
#if defined (RF24_SPI_TRANSACTIONS)
_SPI.beginTransaction(SPISettings(RF24_SPI_SPEED, MSBFIRST, SPI_MODE0));
#endif
if (geteuid() == 0){
_SPI.beginTransaction(SPISettings(RF24_SPI_SPEED, MSBFIRST, SPI_MODE0));
}else{
fprintf(stderr, "Root access required!\n") ;
exit(-1);
}
#endif
csn(LOW);
}

Expand Down

0 comments on commit f2f0021

Please sign in to comment.