Skip to content

Commit

Permalink
Send READY=1 notification to systemd after tee-supplicant is setup
Browse files Browse the repository at this point in the history
This option is very useful when tee-supplicant is started from systemd and can used with Type=notify to signal readiness
  • Loading branch information
embetrix committed May 31, 2024
1 parent 3eac340 commit d130624
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
8 changes: 3 additions & 5 deletions tee-supplicant/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ target_link_libraries(${PROJECT_NAME}
PRIVATE teec
)

if(CFG_TEE_SUPP_PLUGINS)
target_link_libraries(${PROJECT_NAME}
PRIVATE dl
)
endif()
target_link_libraries(${PROJECT_NAME}
PRIVATE dl
)

################################################################################
# Install targets
Expand Down
5 changes: 3 additions & 2 deletions tee-supplicant/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ TEES_LFLAGS += -lpthread
# Needed to get clock_gettime() for for glibc versions before 2.17
TEES_LFLAGS += -lrt

# Needed for dlopen()
TEES_LFLAGS += -ldl

ifeq ($(CFG_TEE_SUPP_PLUGINS),y)
# Needed to dynamically load user plugins
TEES_LFLAGS += -ldl
# Needed for dlopen()
TEES_LFLAGS += -Wl,-rpath=$(CFG_TEE_PLUGIN_LOAD_PATH)
endif

Expand Down
17 changes: 17 additions & 0 deletions tee-supplicant/src/tee_supplicant.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <tee_supp_fs.h>
#include <tee_supplicant.h>
#include <unistd.h>
#include <dlfcn.h>

#include "optee_msg_supplicant.h"

Expand Down Expand Up @@ -823,6 +824,8 @@ int main(int argc, char *argv[])
int e = 0;
int long_index = 0;
int opt = 0;
void *sd_handle = NULL;
int (*tee_sd_notify)(int unset_environment, const char *state) = NULL;

e = pthread_mutex_init(&arg.mutex, NULL);
if (e) {
Expand Down Expand Up @@ -923,6 +926,20 @@ int main(int argc, char *argv[])
}
}

/* we are set here notify systemd */
sd_handle = dlopen("libsystemd.so.0", RTLD_LAZY);
if (sd_handle) {
tee_sd_notify = dlsym(sd_handle, "sd_notify");
if (tee_sd_notify) {
e = tee_sd_notify(0, "READY=1");
if (e <= 0)
fprintf(stderr, "sd_notify failed: %d\n", e);
} else
fprintf(stderr, "Couldn't find sd_notify symbol: %s\n", dlerror());
dlclose(sd_handle);
} else
fprintf(stderr, "Couldn't open libsystemd.so.0: %s\n", dlerror());

if (daemonize) {
/* Release parent */
if (write(pipefd[1], "", 1) != 1) {
Expand Down

0 comments on commit d130624

Please sign in to comment.