Set UID, GID, and executable bits on uploaded application (#12)
Also remove old application rather than replacing directly, so it can be replaced while running.
This commit is contained in:
parent
de6f59548a
commit
0c1008defa
4
deps/tools/Makefile
vendored
4
deps/tools/Makefile
vendored
|
@ -6,6 +6,8 @@ OPENCV_INSTALL?=../03-build/opencv-build/install
|
|||
EXEC_HOME?=/home/pi
|
||||
FRC_JSON?=/boot/frc.json
|
||||
DHCPCD_CONF?=/boot/dhcpcd.conf
|
||||
APP_UID?=1000
|
||||
APP_GID?=1000
|
||||
|
||||
.PHONY: all
|
||||
.SUFFIXES:
|
||||
|
@ -65,6 +67,8 @@ rpiConfigServer: ${RPICONFIGSERVER_OBJS}
|
|||
'-DEXEC_HOME="${EXEC_HOME}"' \
|
||||
'-DFRC_JSON="${FRC_JSON}"' \
|
||||
'-DDHCPCD_CONF="${DHCPCD_CONF}"' \
|
||||
'-DAPP_UID=${APP_UID}' \
|
||||
'-DAPP_GID=${APP_GID}' \
|
||||
$<
|
||||
|
||||
%.html.cpp: %.html
|
||||
|
|
31
deps/tools/rpiConfigServer_src/Application.cpp
vendored
31
deps/tools/rpiConfigServer_src/Application.cpp
vendored
|
@ -7,6 +7,9 @@
|
|||
|
||||
#include "Application.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <wpi/FileSystem.h>
|
||||
#include <wpi/json.h>
|
||||
#include <wpi/raw_istream.h>
|
||||
|
@ -103,18 +106,38 @@ void Application::Upload(wpi::ArrayRef<uint8_t> contents,
|
|||
pathname = EXEC_HOME;
|
||||
pathname += filename;
|
||||
|
||||
// remove old file (need to do this as we can't overwrite a running exe)
|
||||
if (unlink(pathname.c_str()) == -1) {
|
||||
wpi::errs() << "could not remove app executable: " << std::strerror(errno)
|
||||
<< '\n';
|
||||
}
|
||||
|
||||
{
|
||||
// write file
|
||||
// open file for writing
|
||||
std::error_code ec;
|
||||
wpi::raw_fd_ostream os(pathname, ec, wpi::sys::fs::F_None);
|
||||
if (ec) {
|
||||
int fd;
|
||||
if (wpi::sys::fs::openFileForWrite(pathname, fd, wpi::sys::fs::F_None)) {
|
||||
wpi::SmallString<64> msg;
|
||||
msg = "could not write ";
|
||||
msg += pathname;
|
||||
onFail(msg);
|
||||
return;
|
||||
}
|
||||
os << contents;
|
||||
|
||||
// change ownership
|
||||
if (fchown(fd, APP_UID, APP_GID) == -1) {
|
||||
wpi::errs() << "could not change app ownership: " << std::strerror(errno)
|
||||
<< '\n';
|
||||
}
|
||||
|
||||
// set file to be executable
|
||||
if (fchmod(fd, 0775) == -1) {
|
||||
wpi::errs() << "could not change app permissions: "
|
||||
<< std::strerror(errno) << '\n';
|
||||
}
|
||||
|
||||
// write contents and close file
|
||||
wpi::raw_fd_ostream(fd, true) << contents;
|
||||
}
|
||||
|
||||
// terminate vision process so it reloads
|
||||
|
|
Loading…
Reference in New Issue
Block a user