Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
[CP] Enable auto start after deb installation and reboot, restrict on…
Browse files Browse the repository at this point in the history
…ly one hdcp daemon instance(CL#792390)

Enable auto start after deb installation and reboot, restrict only one hdcp daemon instance

Change-Id: I4bb0f0fdc8a431828d1533e62ffe56e12990344e
  • Loading branch information
shiqiangyu authored and Sherry-Lin committed Aug 20, 2018
1 parent afc48ae commit 0972f98
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
15 changes: 9 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,26 @@ if (DEFINED CMAKE_BUILD_TYPE AND "${CMAKE_BUILD_TYPE}" STREQUAL "Release")
message(STATUS "cmake build type is \"${CMAKE_BUILD_TYPE}\"")
endif ()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

add_subdirectory(common ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/common)
add_subdirectory(common ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/common)
add_subdirectory(sdk ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/sdk)
add_subdirectory(daemon ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/daemon)
add_subdirectory(daemon ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/daemon)

set(CMAKE_INSTALL_BINDIR /usr/bin)
set(CMAKE_INSTALL_LIBDIR /usr/lib/x86_64-linux-gnu)
set(CMAKE_SYSTEMD_INSTALL_DIR /etc/systemd/system)
install (PROGRAMS ${CMAKE_BINARY_DIR}/hdcpd DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT cp)
install (FILES ${CMAKE_BINARY_DIR}/libhdcpsdk.so DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT cp)
install (FILES ${CMAKE_BINARY_DIR}/hdcpd DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT cp)
install (FILES ${CMAKE_SOURCE_DIR}/config/hdcpd.service DESTINATION ${CMAKE_SYSTEMD_INSTALL_DIR} COMPONENT cp)

set(CPACK_GENERATOR "DEB")
set(CPACK_PACKAGE_NAME "intel-uapi-hdcp")
set(CPACK_PACKAGE_VENDOR "Intel")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "intel-uapi-hdcp deb package for internal usage only")
SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_SOURCE_DIR}/config/postinst)

set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel")
include(CPack)
10 changes: 10 additions & 0 deletions config/hdcpd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=hdcp daemon

[Service]
Type=simple
ExecStart=/usr/bin/hdcpd
User=root

[Install]
WantedBy=multi-user.target
4 changes: 4 additions & 0 deletions config/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

systemctl enable hdcpd.service
systemctl start hdcpd.service
46 changes: 46 additions & 0 deletions daemon/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <dirent.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <iostream>

#include "hdcpdef.h"
#include "srm.h"
Expand All @@ -44,6 +45,45 @@

FILE *dmLog = nullptr;

bool AlreadyRunning()
{
const std::string pidFile = "/var/run/hdcpd.pid";

int fd = open(pidFile.c_str(),
O_RDWR | O_CREAT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd < 0)
{
HDCP_ASSERTMESSAGE("Could not open pid file : %s\n", pidFile.c_str());
close(fd);
return true;
}

struct flock fl;
fl.l_type = F_WRLCK;
fl.l_start = 0;
fl.l_whence = SEEK_SET;
fl.l_len = 0;

if (fcntl(fd, F_SETLK, &fl) < 0)
{
HDCP_ASSERTMESSAGE("Could not lock pid file\n");
close(fd);
return true;
}

std::string pid = std::to_string(getpid());
if (write(fd, pid.c_str(), pid.length()) < 0)
{
HDCP_ASSERTMESSAGE("Could not write pid file\n");
close(fd);
return true;
}

close(fd);
return false;
}

int32_t daemon_init(void)
{
pid_t pid = fork();
Expand Down Expand Up @@ -171,6 +211,12 @@ int32_t main(void)
int32_t ret = -1;
struct passwd *mediaId = getpwnam("media");

if (AlreadyRunning())
{
HDCP_ASSERTMESSAGE("hdcp aleady already running\n");
return 1;
}

if (nullptr == mediaId)
{
HDCP_ASSERTMESSAGE(
Expand Down

0 comments on commit 0972f98

Please sign in to comment.